diff options
author | Noel Grandin <noelgrandin@gmail.com> | 2016-03-31 20:29:21 +0200 |
---|---|---|
committer | Noel Grandin <noelgrandin@gmail.com> | 2016-04-04 09:15:28 +0000 |
commit | 3efd7a07cbccd03ecb289e95fb9343460ace4a7f (patch) | |
tree | 15088849d2cae70471d1abfe7d3ba6d6bff9de38 /sfx2 | |
parent | 9e087de13351624a9fff2edf33d98221a967e040 (diff) |
sequence->vector in sfx2
Change-Id: I31c3075db663253b37f0a8dc64338ec6f6172801
Reviewed-on: https://gerrit.libreoffice.org/23755
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/source/doc/doctemplates.cxx | 34 | ||||
-rw-r--r-- | sfx2/source/doc/doctemplateslocal.cxx | 43 | ||||
-rw-r--r-- | sfx2/source/doc/doctemplateslocal.hxx | 13 | ||||
-rw-r--r-- | sfx2/source/doc/sfxbasemodel.cxx | 35 |
4 files changed, 51 insertions, 74 deletions
diff --git a/sfx2/source/doc/doctemplates.cxx b/sfx2/source/doc/doctemplates.cxx index cfe527eab048..175354c12fd6 100644 --- a/sfx2/source/doc/doctemplates.cxx +++ b/sfx2/source/doc/doctemplates.cxx @@ -218,7 +218,7 @@ class SfxDocTplService_Impl const OUString& aPrefix, const OUString& aExt ); - uno::Sequence< beans::StringPair > ReadUINamesForTemplateDir_Impl( const OUString& aUserPath ); + std::vector< beans::StringPair > ReadUINamesForTemplateDir_Impl( const OUString& aUserPath ); bool UpdateUINamesForTemplateDir_Impl( const OUString& aUserPath, const OUString& aGroupName, const OUString& aNewFolderName ); @@ -229,7 +229,7 @@ class SfxDocTplService_Impl void RemoveUINamesForTemplateDir_Impl( const OUString& aUserPath, const OUString& aGroupName ); bool WriteUINamesForTemplateDir_Impl( const OUString& aUserPath, - const uno::Sequence< beans::StringPair >& aUINames ); + const std::vector< beans::StringPair >& aUINames ); OUString CreateNewGroupFsys( const OUString& rGroupName, Content& aGroup ); @@ -1215,7 +1215,7 @@ void SfxDocTplService_Impl::doUpdate() } -uno::Sequence< beans::StringPair > SfxDocTplService_Impl::ReadUINamesForTemplateDir_Impl( const OUString& aUserPath ) +std::vector< beans::StringPair > SfxDocTplService_Impl::ReadUINamesForTemplateDir_Impl( const OUString& aUserPath ) { INetURLObject aLocObj( aUserPath ); aLocObj.insertName( "groupuinames.xml", false, @@ -1224,7 +1224,7 @@ uno::Sequence< beans::StringPair > SfxDocTplService_Impl::ReadUINamesForTemplate Content aLocContent; // TODO/LATER: Use hashmap in future - uno::Sequence< beans::StringPair > aUINames; + std::vector< beans::StringPair > aUINames; if ( Content::create( aLocObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference < ucb::XCommandEnvironment >(), comphelper::getProcessComponentContext(), aLocContent ) ) { try @@ -1245,15 +1245,15 @@ bool SfxDocTplService_Impl::UpdateUINamesForTemplateDir_Impl( const OUString& aU const OUString& aGroupName, const OUString& aNewFolderName ) { - uno::Sequence< beans::StringPair > aUINames = ReadUINamesForTemplateDir_Impl( aUserPath ); - sal_Int32 nLen = aUINames.getLength(); + std::vector< beans::StringPair > aUINames = ReadUINamesForTemplateDir_Impl( aUserPath ); + sal_Int32 nLen = aUINames.size(); // it is possible that the name is used already, but it should be checked before for ( sal_Int32 nInd = 0; nInd < nLen; nInd++ ) if ( aUINames[nInd].First.equals( aNewFolderName ) ) return false; - aUINames.realloc( ++nLen ); + aUINames.resize( ++nLen ); aUINames[nLen-1].First = aNewFolderName; aUINames[nLen-1].Second = aGroupName; @@ -1266,8 +1266,8 @@ bool SfxDocTplService_Impl::ReplaceUINamesForTemplateDir_Impl( const OUString& a const OUString& aOldGroupName, const OUString& aNewGroupName ) { - uno::Sequence< beans::StringPair > aUINames = ReadUINamesForTemplateDir_Impl( aUserPath ); - sal_Int32 nLen = aUINames.getLength(); + std::vector< beans::StringPair > aUINames = ReadUINamesForTemplateDir_Impl( aUserPath ); + sal_Int32 nLen = aUINames.size(); bool bChanged = false; for ( sal_Int32 nInd = 0; nInd < nLen; nInd++ ) @@ -1279,7 +1279,7 @@ bool SfxDocTplService_Impl::ReplaceUINamesForTemplateDir_Impl( const OUString& a if ( !bChanged ) { - aUINames.realloc( ++nLen ); + aUINames.resize( ++nLen ); aUINames[nLen-1].First = aDefaultFsysGroupName; aUINames[nLen-1].Second = aNewGroupName; } @@ -1290,9 +1290,9 @@ bool SfxDocTplService_Impl::ReplaceUINamesForTemplateDir_Impl( const OUString& a void SfxDocTplService_Impl::RemoveUINamesForTemplateDir_Impl( const OUString& aUserPath, const OUString& aGroupName ) { - uno::Sequence< beans::StringPair > aUINames = ReadUINamesForTemplateDir_Impl( aUserPath ); - sal_Int32 nLen = aUINames.getLength(); - uno::Sequence< beans::StringPair > aNewUINames( nLen ); + std::vector< beans::StringPair > aUINames = ReadUINamesForTemplateDir_Impl( aUserPath ); + sal_Int32 nLen = aUINames.size(); + std::vector< beans::StringPair > aNewUINames( nLen ); sal_Int32 nNewLen = 0; bool bChanged = false; @@ -1306,14 +1306,14 @@ void SfxDocTplService_Impl::RemoveUINamesForTemplateDir_Impl( const OUString& aU aNewUINames[nNewLen-1].Second = aUINames[nInd].Second; } - aNewUINames.realloc( nNewLen ); + aNewUINames.resize( nNewLen ); !bChanged || WriteUINamesForTemplateDir_Impl( aUserPath, aNewUINames ); } bool SfxDocTplService_Impl::WriteUINamesForTemplateDir_Impl( const OUString& aUserPath, - const uno::Sequence< beans::StringPair >& aUINames ) + const std::vector< beans::StringPair >& aUINames ) { bool bResult = false; try { @@ -2564,7 +2564,7 @@ void SfxDocTplService_Impl::createFromContent( GroupList_Impl& rList, INetURLObject aLayerObj( aTargetURL ); // TODO/LATER: Use hashmap in future - uno::Sequence< beans::StringPair > aUINames; + std::vector< beans::StringPair > aUINames; if ( !bHierarchy ) aUINames = ReadUINamesForTemplateDir_Impl( aLayerObj.GetMainURL( INetURLObject::NO_DECODE ) ); @@ -2596,7 +2596,7 @@ void SfxDocTplService_Impl::createFromContent( GroupList_Impl& rList, else { OUString aUITitle; - for ( sal_Int32 nInd = 0; nInd < aUINames.getLength(); nInd++ ) + for ( size_t nInd = 0; nInd < aUINames.size(); nInd++ ) if ( aUINames[nInd].First.equals( aTitle ) ) { aUITitle = aUINames[nInd].Second; diff --git a/sfx2/source/doc/doctemplateslocal.cxx b/sfx2/source/doc/doctemplateslocal.cxx index d65d970369b9..63017bb00fdb 100644 --- a/sfx2/source/doc/doctemplateslocal.cxx +++ b/sfx2/source/doc/doctemplateslocal.cxx @@ -33,7 +33,7 @@ using namespace ::com::sun::star; -uno::Sequence< beans::StringPair > DocTemplLocaleHelper::ReadGroupLocalizationSequence( const uno::Reference< io::XInputStream >& xInStream, const uno::Reference< uno::XComponentContext > xContext ) +std::vector< beans::StringPair > DocTemplLocaleHelper::ReadGroupLocalizationSequence( const uno::Reference< io::XInputStream >& xInStream, const uno::Reference< uno::XComponentContext > xContext ) throw( uno::Exception ) { OUString aStringID = "groupuinames.xml"; @@ -41,7 +41,7 @@ uno::Sequence< beans::StringPair > DocTemplLocaleHelper::ReadGroupLocalizationSe } -void SAL_CALL DocTemplLocaleHelper::WriteGroupLocalizationSequence( const uno::Reference< io::XOutputStream >& xOutStream, const uno::Sequence< beans::StringPair >& aSequence, const uno::Reference< uno::XComponentContext > xContext ) +void SAL_CALL DocTemplLocaleHelper::WriteGroupLocalizationSequence( const uno::Reference< io::XOutputStream >& xOutStream, const std::vector< beans::StringPair >& aSequence, const uno::Reference< uno::XComponentContext > xContext ) throw( uno::Exception ) { if ( !xOutStream.is() ) @@ -70,7 +70,7 @@ void SAL_CALL DocTemplLocaleHelper::WriteGroupLocalizationSequence( const uno::R xWriterHandler->startDocument(); xWriterHandler->startElement( aGroupListElement, xRootAttrList ); - for ( sal_Int32 nInd = 0; nInd < aSequence.getLength(); nInd++ ) + for ( size_t nInd = 0; nInd < aSequence.size(); nInd++ ) { ::comphelper::AttributeList *pAttrList = new ::comphelper::AttributeList; uno::Reference< xml::sax::XAttributeList > xAttrList( pAttrList ); @@ -88,7 +88,7 @@ void SAL_CALL DocTemplLocaleHelper::WriteGroupLocalizationSequence( const uno::R } -uno::Sequence< beans::StringPair > SAL_CALL DocTemplLocaleHelper::ReadLocalizationSequence_Impl( const uno::Reference< io::XInputStream >& xInStream, const OUString& aStringID, const uno::Reference< uno::XComponentContext > xContext ) +std::vector< beans::StringPair > SAL_CALL DocTemplLocaleHelper::ReadLocalizationSequence_Impl( const uno::Reference< io::XInputStream >& xInStream, const OUString& aStringID, const uno::Reference< uno::XComponentContext > xContext ) throw( uno::Exception ) { if ( !xContext.is() || !xInStream.is() ) @@ -123,9 +123,9 @@ DocTemplLocaleHelper::~DocTemplLocaleHelper() } -uno::Sequence< beans::StringPair > DocTemplLocaleHelper::GetParsingResult() +std::vector< beans::StringPair > DocTemplLocaleHelper::GetParsingResult() { - if ( m_aElementsSeq.getLength() ) + if ( !m_aElementsSeq.empty() ) throw uno::RuntimeException(); // the parsing has still not finished! return m_aResultSeq; @@ -149,27 +149,22 @@ void SAL_CALL DocTemplLocaleHelper::startElement( const OUString& aName, const u { if ( aName == m_aGroupListElement ) { - sal_Int32 nNewLength = m_aElementsSeq.getLength() + 1; - - if ( nNewLength != 1 ) + if ( m_aElementsSeq.size() != 0 ) throw xml::sax::SAXException(); // TODO: this element must be the first level element - m_aElementsSeq.realloc( nNewLength ); - m_aElementsSeq[nNewLength-1] = aName; + m_aElementsSeq.push_back( aName ); return; // nothing to do } else if ( aName == m_aGroupElement ) { - sal_Int32 nNewLength = m_aElementsSeq.getLength() + 1; - if ( nNewLength != 2 ) + if ( m_aElementsSeq.size() != 1 ) throw xml::sax::SAXException(); // TODO: this element must be the second level element - m_aElementsSeq.realloc( nNewLength ); - m_aElementsSeq[nNewLength-1] = aName; + m_aElementsSeq.push_back( aName ); - sal_Int32 nNewEntryNum = m_aResultSeq.getLength() + 1; - m_aResultSeq.realloc( nNewEntryNum ); + sal_Int32 nNewEntryNum = m_aResultSeq.size() + 1; + m_aResultSeq.resize( nNewEntryNum ); OUString aNameValue = xAttribs->getValueByName( m_aNameAttr ); if ( aNameValue.isEmpty() ) @@ -185,13 +180,10 @@ void SAL_CALL DocTemplLocaleHelper::startElement( const OUString& aName, const u else { // accept future extensions - sal_Int32 nNewLength = m_aElementsSeq.getLength() + 1; - - if ( !nNewLength ) + if ( m_aElementsSeq.empty() ) throw xml::sax::SAXException(); // TODO: the extension element must not be the first level element - m_aElementsSeq.realloc( nNewLength ); - m_aElementsSeq[nNewLength-1] = aName; + m_aElementsSeq.push_back( aName ); } } @@ -199,14 +191,13 @@ void SAL_CALL DocTemplLocaleHelper::startElement( const OUString& aName, const u void SAL_CALL DocTemplLocaleHelper::endElement( const OUString& aName ) throw( xml::sax::SAXException, uno::RuntimeException, std::exception ) { - sal_Int32 nLength = m_aElementsSeq.getLength(); - if ( nLength <= 0 ) + if ( m_aElementsSeq.empty() ) throw xml::sax::SAXException(); // TODO: no other end elements expected! - if ( !m_aElementsSeq[nLength-1].equals( aName ) ) + if ( m_aElementsSeq.back() != aName ) throw xml::sax::SAXException(); // TODO: unexpected element ended - m_aElementsSeq.realloc( nLength - 1 ); + m_aElementsSeq.pop_back(); } diff --git a/sfx2/source/doc/doctemplateslocal.hxx b/sfx2/source/doc/doctemplateslocal.hxx index a0a0748caafd..53a98140d714 100644 --- a/sfx2/source/doc/doctemplateslocal.hxx +++ b/sfx2/source/doc/doctemplateslocal.hxx @@ -25,6 +25,7 @@ #include <com/sun/star/io/XInputStream.hpp> #include <com/sun/star/io/XOutputStream.hpp> #include <cppuhelper/implbase.hxx> +#include <vector> class DocTemplLocaleHelper : public cppu::WeakImplHelper < css::xml::sax::XDocumentHandler > @@ -35,13 +36,13 @@ class DocTemplLocaleHelper : public cppu::WeakImplHelper < css::xml::sax::XDocum OUString m_aNameAttr; OUString m_aUINameAttr; - css::uno::Sequence< css::beans::StringPair > m_aResultSeq; - css::uno::Sequence< OUString > m_aElementsSeq; // stack of elements being parsed + std::vector< css::beans::StringPair > m_aResultSeq; + std::vector< OUString > m_aElementsSeq; // stack of elements being parsed DocTemplLocaleHelper(); - css::uno::Sequence< css::beans::StringPair > GetParsingResult(); + std::vector< css::beans::StringPair > GetParsingResult(); - static css::uno::Sequence< css::beans::StringPair > SAL_CALL ReadLocalizationSequence_Impl( const css::uno::Reference< css::io::XInputStream >& xInStream, const OUString& aStringID, const css::uno::Reference< css::uno::XComponentContext > xContext ) + static std::vector< css::beans::StringPair > SAL_CALL ReadLocalizationSequence_Impl( const css::uno::Reference< css::io::XInputStream >& xInStream, const OUString& aStringID, const css::uno::Reference< css::uno::XComponentContext > xContext ) throw( css::uno::Exception ); public: @@ -49,7 +50,7 @@ public: // returns sequence of pairs ( GroupName, GroupUIName ) static - css::uno::Sequence< css::beans::StringPair > + std::vector< css::beans::StringPair > ReadGroupLocalizationSequence( const css::uno::Reference< css::io::XInputStream >& xInStream, const css::uno::Reference< css::uno::XComponentContext > xContext ) @@ -59,7 +60,7 @@ public: static void SAL_CALL WriteGroupLocalizationSequence( const css::uno::Reference< css::io::XOutputStream >& xOutStream, - const css::uno::Sequence< css::beans::StringPair >& aSequence, + const std::vector< css::beans::StringPair >& aSequence, const css::uno::Reference< css::uno::XComponentContext > xContext ) throw( css::uno::Exception ); diff --git a/sfx2/source/doc/sfxbasemodel.cxx b/sfx2/source/doc/sfxbasemodel.cxx index 8bb5c08de0a9..1d5b4e8b994d 100644 --- a/sfx2/source/doc/sfxbasemodel.cxx +++ b/sfx2/source/doc/sfxbasemodel.cxx @@ -196,7 +196,7 @@ struct IMPL_SfxBaseModel_DataContainer : public ::sfx2::IModifiableDocument Reference< script::XStarBasicAccess > m_xStarBasicAccess ; Reference< container::XNameReplace > m_xEvents ; Sequence< beans::PropertyValue> m_seqArguments ; - Sequence< Reference< frame::XController > > m_seqControllers ; + std::vector< Reference< frame::XController > > m_seqControllers ; Reference< container::XIndexAccess > m_contViewData ; sal_uInt16 m_nControllerLockCount ; bool m_bClosed ; @@ -771,7 +771,7 @@ void SAL_CALL SfxBaseModel::dispose() throw(RuntimeException, std::exception) } m_pData->m_xCurrent.clear(); - m_pData->m_seqControllers.realloc(0); + m_pData->m_seqControllers.clear(); // m_pData member must be set to zero before 0delete is called to // force disposed exception whenever someone tries to access our @@ -1063,14 +1063,9 @@ void SAL_CALL SfxBaseModel::connectController( const Reference< frame::XControll if ( !xController.is() ) return; - sal_uInt32 nOldCount = m_pData->m_seqControllers.getLength(); - Sequence< Reference< frame::XController > > aNewSeq( nOldCount + 1 ); - for ( sal_uInt32 n = 0; n < nOldCount; n++ ) - aNewSeq.getArray()[n] = m_pData->m_seqControllers.getConstArray()[n]; - aNewSeq.getArray()[nOldCount] = xController; - m_pData->m_seqControllers = aNewSeq; + m_pData->m_seqControllers.push_back(xController); - if ( m_pData->m_seqControllers.getLength() == 1 ) + if ( m_pData->m_seqControllers.size() == 1 ) { SfxViewFrame* pViewFrame = SfxViewFrame::Get( xController, GetObjectShell() ); ENSURE_OR_THROW( pViewFrame, "SFX document without SFX view!?" ); @@ -1089,21 +1084,11 @@ void SAL_CALL SfxBaseModel::disconnectController( const Reference< frame::XContr { SfxModelGuard aGuard( *this ); - sal_uInt32 nOldCount = m_pData->m_seqControllers.getLength(); - if ( !nOldCount ) + if ( m_pData->m_seqControllers.empty() ) return; - Sequence< Reference< frame::XController > > aNewSeq( nOldCount - 1 ); - for ( sal_uInt32 nOld = 0, nNew = 0; nOld < nOldCount; ++nOld ) - { - if ( xController != m_pData->m_seqControllers.getConstArray()[nOld] ) - { - aNewSeq.getArray()[nNew] = m_pData->m_seqControllers.getConstArray()[nOld]; - ++nNew; - } - } - - m_pData->m_seqControllers = aNewSeq; + auto& vec = m_pData->m_seqControllers; + vec.erase(std::remove(vec.begin(), vec.end(), xController), vec.end()); if ( xController == m_pData->m_xCurrent ) m_pData->m_xCurrent.clear(); @@ -1215,7 +1200,7 @@ Reference< frame::XController > SAL_CALL SfxBaseModel::getCurrentController() th return m_pData->m_xCurrent; // get the first controller of this model - return m_pData->m_seqControllers.getLength() ? m_pData->m_seqControllers.getConstArray()[0] : m_pData->m_xCurrent; + return !m_pData->m_seqControllers.empty() ? m_pData->m_seqControllers.front() : m_pData->m_xCurrent; } @@ -3391,7 +3376,7 @@ Sequence< OUString > SAL_CALL SfxBaseModel::getDocumentSubStoragesNames() if ( !bSuccess ) throw io::IOException(); - return aResult; + return aResult; } @@ -4085,7 +4070,7 @@ Reference< container::XEnumeration > SAL_CALL SfxBaseModel::getControllers() { SfxModelGuard aGuard( *this ); - sal_Int32 c = m_pData->m_seqControllers.getLength(); + sal_Int32 c = m_pData->m_seqControllers.size(); sal_Int32 i = 0; Sequence< Any > lEnum(c); for (i=0; i<c; ++i) |