diff options
Diffstat (limited to 'linguistic/source/convdiclist.cxx')
-rw-r--r-- | linguistic/source/convdiclist.cxx | 57 |
1 files changed, 20 insertions, 37 deletions
diff --git a/linguistic/source/convdiclist.cxx b/linguistic/source/convdiclist.cxx index a977062bce83..de7160f10a41 100644 --- a/linguistic/source/convdiclist.cxx +++ b/linguistic/source/convdiclist.cxx @@ -31,6 +31,7 @@ #include <cppuhelper/factory.hxx> #include <cppuhelper/implbase.hxx> #include <comphelper/processfactory.hxx> +#include <comphelper/sequence.hxx> #include <cppuhelper/supportsservice.hxx> #include <rtl/instance.hxx> #include <tools/stream.hxx> @@ -79,7 +80,7 @@ class ConvDicNameContainer : public cppu::WeakImplHelper< css::container::XNameContainer >, private boost::noncopyable { - uno::Sequence< uno::Reference< XConversionDictionary > > aConvDics; + std::vector< uno::Reference< XConversionDictionary > > aConvDics; sal_Int32 GetIndexByName_Impl( const OUString& rName ); @@ -110,12 +111,12 @@ public: // calls Flush for the dictionaries that support XFlushable void FlushDics() const; - sal_Int32 GetCount() const { return aConvDics.getLength(); } + sal_Int32 GetCount() const { return aConvDics.size(); } uno::Reference< XConversionDictionary > GetByName( const OUString& rName ); - const uno::Reference< XConversionDictionary > GetByIndex( sal_Int32 nIdx ) + const uno::Reference< XConversionDictionary >& GetByIndex( sal_Int32 nIdx ) { - return aConvDics.getConstArray()[nIdx]; + return aConvDics[nIdx]; } }; @@ -129,11 +130,10 @@ ConvDicNameContainer::~ConvDicNameContainer() void ConvDicNameContainer::FlushDics() const { - sal_Int32 nLen = aConvDics.getLength(); - const uno::Reference< XConversionDictionary > *pDic = aConvDics.getConstArray(); + sal_Int32 nLen = aConvDics.size(); for (sal_Int32 i = 0; i < nLen; ++i) { - uno::Reference< util::XFlushable > xFlush( pDic[i] , UNO_QUERY ); + uno::Reference< util::XFlushable > xFlush( aConvDics[i] , UNO_QUERY ); if (xFlush.is()) { try @@ -152,11 +152,10 @@ sal_Int32 ConvDicNameContainer::GetIndexByName_Impl( const OUString& rName ) { sal_Int32 nRes = -1; - sal_Int32 nLen = aConvDics.getLength(); - const uno::Reference< XConversionDictionary > *pDic = aConvDics.getConstArray(); + sal_Int32 nLen = aConvDics.size(); for (sal_Int32 i = 0; i < nLen && nRes == -1; ++i) { - if (rName == pDic[i]->getName()) + if (rName == aConvDics[i]->getName()) nRes = i; } return nRes; @@ -168,7 +167,7 @@ uno::Reference< XConversionDictionary > ConvDicNameContainer::GetByName( uno::Reference< XConversionDictionary > xRes; sal_Int32 nIdx = GetIndexByName_Impl( rName ); if ( nIdx != -1) - xRes = aConvDics.getArray()[nIdx]; + xRes = aConvDics[nIdx]; return xRes; } @@ -183,7 +182,7 @@ sal_Bool SAL_CALL ConvDicNameContainer::hasElements( ) throw (RuntimeException, std::exception) { MutexGuard aGuard( GetLinguMutex() ); - return aConvDics.getLength() > 0; + return !aConvDics.empty(); } uno::Any SAL_CALL ConvDicNameContainer::getByName( const OUString& rName ) @@ -201,12 +200,11 @@ uno::Sequence< OUString > SAL_CALL ConvDicNameContainer::getElementNames( ) { MutexGuard aGuard( GetLinguMutex() ); - sal_Int32 nLen = aConvDics.getLength(); + sal_Int32 nLen = aConvDics.size(); uno::Sequence< OUString > aRes( nLen ); OUString *pName = aRes.getArray(); - const uno::Reference< XConversionDictionary > *pDic = aConvDics.getConstArray(); for (sal_Int32 i = 0; i < nLen; ++i) - pName[i] = pDic[i]->getName(); + pName[i] = aConvDics[i]->getName(); return aRes; } @@ -231,7 +229,7 @@ void SAL_CALL ConvDicNameContainer::replaceByName( rElement >>= xNew; if (!xNew.is() || xNew->getName() != rName) throw IllegalArgumentException(); - aConvDics.getArray()[ nRplcIdx ] = xNew; + aConvDics[ nRplcIdx ] = xNew; } void SAL_CALL ConvDicNameContainer::insertByName( @@ -248,9 +246,7 @@ void SAL_CALL ConvDicNameContainer::insertByName( if (!xNew.is() || xNew->getName() != rName) throw IllegalArgumentException(); - sal_Int32 nLen = aConvDics.getLength(); - aConvDics.realloc( nLen + 1 ); - aConvDics.getArray()[ nLen ] = xNew; + aConvDics.push_back(xNew); } void SAL_CALL ConvDicNameContainer::removeByName( const OUString& rName ) @@ -263,7 +259,7 @@ void SAL_CALL ConvDicNameContainer::removeByName( const OUString& rName ) throw NoSuchElementException(); // physically remove dictionary - uno::Reference< XConversionDictionary > xDel = aConvDics.getArray()[nRplcIdx]; + uno::Reference< XConversionDictionary > xDel = aConvDics[nRplcIdx]; OUString aName( xDel->getName() ); OUString aDicMainURL( GetConvDicMainURL( aName, GetDictionaryWriteablePath() ) ); INetURLObject aObj( aDicMainURL ); @@ -287,11 +283,7 @@ void SAL_CALL ConvDicNameContainer::removeByName( const OUString& rName ) } } - sal_Int32 nLen = aConvDics.getLength(); - uno::Reference< XConversionDictionary > *pDic = aConvDics.getArray(); - for (sal_Int32 i = nRplcIdx; i < nLen - 1; ++i) - pDic[i] = pDic[i + 1]; - aConvDics.realloc( nLen - 1 ); + aConvDics.erase(aConvDics.begin() + nRplcIdx); } void ConvDicNameContainer::AddConvDics( @@ -482,9 +474,7 @@ uno::Sequence< OUString > SAL_CALL ConvDicList::queryConversions( { MutexGuard aGuard( GetLinguMutex() ); - sal_Int32 nCount = 0; - uno::Sequence< OUString > aRes( 20 ); - OUString *pRes = aRes.getArray(); + std::vector< OUString > aRes; bool bSupported = false; sal_Int32 nLen = GetNameContainer().GetCount(); @@ -503,14 +493,8 @@ uno::Sequence< OUString > SAL_CALL ConvDicList::queryConversions( sal_Int32 nNewLen = aNewConv.getLength(); if (nNewLen > 0) { - if (nCount + nNewLen > aRes.getLength()) - { - aRes.realloc( nCount + nNewLen + 20 ); - pRes = aRes.getArray(); - } - const OUString *pNewConv = aNewConv.getConstArray(); for (sal_Int32 k = 0; k < nNewLen; ++k) - pRes[nCount++] = pNewConv[k]; + aRes.push_back(aNewConv[k]); } } } @@ -518,8 +502,7 @@ uno::Sequence< OUString > SAL_CALL ConvDicList::queryConversions( if (!bSupported) throw NoSupportException(); - aRes.realloc( nCount ); - return aRes; + return comphelper::containerToSequence(aRes); } sal_Int16 SAL_CALL ConvDicList::queryMaxCharCount( |