[Libreoffice-commits] core.git: include/sfx2 sfx2/source
Noel Grandin
noelgrandin at gmail.com
Sun Apr 30 06:56:13 UTC 2017
include/sfx2/msgpool.hxx | 21 +++-----
sfx2/source/control/msgpool.cxx | 104 +++++++++++++++-------------------------
2 files changed, 48 insertions(+), 77 deletions(-)
New commits:
commit 00052c1c4f7285a58a8854d34a9b6b3fd2d5991a
Author: Noel Grandin <noelgrandin at gmail.com>
Date: Sat Apr 29 22:47:58 2017 +0200
stop torturing std::string in SfxSlotPool
when what you really want is std::vector.
Also drop unnecassary use of std::unique_ptr
and constify a couple of methods.
Change-Id: I676ee3460a015b0c7656167c06a569c30c861f98
Reviewed-on: https://gerrit.libreoffice.org/37106
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/include/sfx2/msgpool.hxx b/include/sfx2/msgpool.hxx
index 817b914152e2..4d57ba74d46a 100644
--- a/include/sfx2/msgpool.hxx
+++ b/include/sfx2/msgpool.hxx
@@ -24,26 +24,23 @@
#include <sal/types.h>
#include <sfx2/dllapi.h>
#include <sfx2/msg.hxx>
-#include <string>
#include <memory>
#include <vector>
class SfxInterface;
class SfxSlot;
-typedef std::basic_string< sal_uInt16 > SfxSlotGroupArr_Impl;
-
class SFX2_DLLPUBLIC SfxSlotPool
{
- std::unique_ptr<SfxSlotGroupArr_Impl> _pGroups;
+ std::vector<sal_uInt16> _vGroups;
SfxSlotPool* _pParentPool;
- std::unique_ptr< std::vector<SfxInterface*> > _pInterfaces;
- sal_uInt16 _nCurGroup;
- sal_uInt16 _nCurInterface;
- sal_uInt16 _nCurMsg;
+ std::vector<SfxInterface*> _vInterfaces;
+ sal_uInt16 _nCurGroup;
+ sal_uInt16 _nCurInterface;
+ sal_uInt16 _nCurMsg;
private:
- const SfxSlot* SeekSlot( sal_uInt16 nObject );
+ const SfxSlot* SeekSlot( sal_uInt16 nObject );
public:
SfxSlotPool(SfxSlotPool* pParent=nullptr);
@@ -55,12 +52,12 @@ public:
static SfxSlotPool& GetSlotPool( SfxViewFrame *pFrame=nullptr );
- sal_uInt16 GetGroupCount();
+ sal_uInt16 GetGroupCount() const;
OUString SeekGroup( sal_uInt16 nNo );
const SfxSlot* FirstSlot();
const SfxSlot* NextSlot();
- const SfxSlot* GetSlot( sal_uInt16 nId );
- const SfxSlot* GetUnoSlot( const OUString& rUnoName );
+ const SfxSlot* GetSlot( sal_uInt16 nId ) const;
+ const SfxSlot* GetUnoSlot( const OUString& rUnoName ) const;
const std::type_info* GetSlotType( sal_uInt16 nSlotId ) const;
};
diff --git a/sfx2/source/control/msgpool.cxx b/sfx2/source/control/msgpool.cxx
index adbb0e6968fc..ed74d2020c3b 100644
--- a/sfx2/source/control/msgpool.cxx
+++ b/sfx2/source/control/msgpool.cxx
@@ -54,9 +54,7 @@ SfxSlotPool::~SfxSlotPool()
void SfxSlotPool::RegisterInterface( SfxInterface& rInterface )
{
// add to the list of SfxObjectInterface instances
- if(!_pInterfaces)
- _pInterfaces.reset(new std::vector<SfxInterface*> );
- _pInterfaces->push_back(&rInterface);
+ _vInterfaces.push_back(&rInterface);
// Stop at a (single) Null-slot (for syntactic reasons the interfaces
// always contain at least one slot)
@@ -64,27 +62,22 @@ void SfxSlotPool::RegisterInterface( SfxInterface& rInterface )
return;
// possibly add Interface-id and group-ids of funcs to the list of groups
- if ( !_pGroups )
+ if ( _pParentPool )
{
- _pGroups.reset(new SfxSlotGroupArr_Impl);
-
- if ( _pParentPool )
- {
- // The Groups in parent Slotpool are also known here
- _pGroups->append( *_pParentPool->_pGroups );
- }
+ // The Groups in parent Slotpool are also known here
+ _vGroups.insert( _vGroups.end(), _pParentPool->_vGroups.begin(), _pParentPool->_vGroups.end() );
}
for ( size_t nFunc = 0; nFunc < rInterface.Count(); ++nFunc )
{
SfxSlot &rDef = rInterface.pSlots[nFunc];
if ( rDef.GetGroupId() && /* rDef.GetGroupId() != GID_INTERN && */
- _pGroups->find(rDef.GetGroupId()) == SfxSlotGroupArr_Impl::npos )
+ std::find(_vGroups.begin(), _vGroups.end(), rDef.GetGroupId()) == _vGroups.end() )
{
if (rDef.GetGroupId() == GID_INTERN)
- _pGroups->insert(_pGroups->begin(), rDef.GetGroupId());
+ _vGroups.insert(_vGroups.begin(), rDef.GetGroupId());
else
- _pGroups->push_back(rDef.GetGroupId());
+ _vGroups.push_back(rDef.GetGroupId());
}
}
}
@@ -92,7 +85,7 @@ void SfxSlotPool::RegisterInterface( SfxInterface& rInterface )
const std::type_info* SfxSlotPool::GetSlotType( sal_uInt16 nId ) const
{
- const SfxSlot* pSlot = (const_cast <SfxSlotPool*> (this))->GetSlot( nId );
+ const SfxSlot* pSlot = GetSlot( nId );
return pSlot ? pSlot->GetType()->Type() : nullptr;
}
@@ -101,26 +94,18 @@ const std::type_info* SfxSlotPool::GetSlotType( sal_uInt16 nId ) const
void SfxSlotPool::ReleaseInterface( SfxInterface& rInterface )
{
- SAL_WARN_IF(!_pInterfaces, "sfx.control", "releasing SfxInterface, but there are none");
- if (!_pInterfaces)
- return ;
-
// remove from the list of SfxInterface instances
- auto i = std::find(_pInterfaces->begin(), _pInterfaces->end(), &rInterface);
- if(i != _pInterfaces->end())
- _pInterfaces->erase(i);
+ auto i = std::find(_vInterfaces.begin(), _vInterfaces.end(), &rInterface);
+ if(i != _vInterfaces.end())
+ _vInterfaces.erase(i);
}
// get the first SfxMessage for a special Id (e.g. for getting check-mode)
-const SfxSlot* SfxSlotPool::GetSlot( sal_uInt16 nId )
+const SfxSlot* SfxSlotPool::GetSlot( sal_uInt16 nId ) const
{
- SAL_WARN_IF(!_pInterfaces, "sfx.control", "no Interfaces registered");
- if (!_pInterfaces)
- return nullptr;
-
// First, search their own interfaces
- for (SfxInterface* _pInterface : *_pInterfaces)
+ for (SfxInterface* _pInterface : _vInterfaces)
{
const SfxSlot *pDef = _pInterface->GetSlot(nId);
if ( pDef )
@@ -136,17 +121,15 @@ const SfxSlot* SfxSlotPool::GetSlot( sal_uInt16 nId )
OUString SfxSlotPool::SeekGroup( sal_uInt16 nNo )
{
- SAL_WARN_IF(!_pInterfaces, "sfx.control", "no Interfaces registered");
-
// if the group exists, use it
- if ( _pGroups && nNo < _pGroups->size() )
+ if ( nNo < _vGroups.size() )
{
_nCurGroup = nNo;
if ( _pParentPool )
{
// In most cases, the order of the IDs agree
- sal_uInt16 nParentCount = _pParentPool->_pGroups->size();
- if ( nNo < nParentCount && (*_pGroups)[nNo] == (*_pParentPool->_pGroups)[nNo] )
+ sal_uInt16 nParentCount = _pParentPool->_vGroups.size();
+ if ( nNo < nParentCount && _vGroups[nNo] == _pParentPool->_vGroups[nNo] )
_pParentPool->_nCurGroup = nNo;
else
{
@@ -154,13 +137,13 @@ OUString SfxSlotPool::SeekGroup( sal_uInt16 nNo )
// pool, _nCurGroup is set outside the valid range
sal_uInt16 i;
for ( i=1; i<nParentCount; i++ )
- if ( (*_pGroups)[nNo] == (*_pParentPool->_pGroups)[i] )
+ if ( _vGroups[nNo] == _pParentPool->_vGroups[i] )
break;
_pParentPool->_nCurGroup = i;
}
}
- SfxResId aResId( (*_pGroups)[_nCurGroup] );
+ SfxResId aResId( _vGroups[_nCurGroup] );
aResId.SetRT(RSC_STRING);
if ( !SfxResId::GetResMgr()->IsAvailable(aResId) )
{
@@ -175,9 +158,9 @@ OUString SfxSlotPool::SeekGroup( sal_uInt16 nNo )
}
-sal_uInt16 SfxSlotPool::GetGroupCount()
+sal_uInt16 SfxSlotPool::GetGroupCount() const
{
- return _pGroups->size();
+ return _vGroups.size();
}
@@ -185,16 +168,12 @@ sal_uInt16 SfxSlotPool::GetGroupCount()
const SfxSlot* SfxSlotPool::SeekSlot( sal_uInt16 nStartInterface )
{
- SAL_WARN_IF(!_pInterfaces, "sfx.control", "no Interfaces registered");
- if (!_pInterfaces)
- return nullptr;
-
// The numbering starts at the interfaces of the parent pool
- sal_uInt16 nFirstInterface = _pParentPool ? _pParentPool->_pInterfaces->size() : 0;
+ sal_uInt16 nFirstInterface = _pParentPool ? _pParentPool->_vInterfaces.size() : 0;
// have reached the end of the Parent-Pools?
if ( nStartInterface < nFirstInterface &&
- _pParentPool->_nCurGroup >= _pParentPool->_pGroups->size() )
+ _pParentPool->_nCurGroup >= _pParentPool->_vGroups.size() )
nStartInterface = nFirstInterface;
// Is the Interface still in the Parent-Pool?
@@ -206,18 +185,18 @@ const SfxSlot* SfxSlotPool::SeekSlot( sal_uInt16 nStartInterface )
}
// find the first func-def with the current group id
- sal_uInt16 nCount = _pInterfaces->size() + nFirstInterface;
+ sal_uInt16 nCount = _vInterfaces.size() + nFirstInterface;
for ( _nCurInterface = nStartInterface;
_nCurInterface < nCount;
++_nCurInterface )
{
- SfxInterface* pInterface = (*_pInterfaces)[_nCurInterface-nFirstInterface];
+ SfxInterface* pInterface = _vInterfaces[_nCurInterface-nFirstInterface];
for ( _nCurMsg = 0;
_nCurMsg < pInterface->Count();
++_nCurMsg )
{
const SfxSlot& rMsg = pInterface->pSlots[_nCurMsg];
- if (rMsg.GetGroupId() == _pGroups->at(_nCurGroup))
+ if (rMsg.GetGroupId() == _vGroups.at(_nCurGroup))
return &rMsg;
}
}
@@ -230,14 +209,10 @@ const SfxSlot* SfxSlotPool::SeekSlot( sal_uInt16 nStartInterface )
const SfxSlot* SfxSlotPool::NextSlot()
{
- SAL_WARN_IF(!_pInterfaces, "sfx.control", "no Interfaces registered");
- if (!_pInterfaces)
- return nullptr;
-
// The numbering starts at the interfaces of the parent pool
- sal_uInt16 nFirstInterface = _pParentPool ? _pParentPool->_pInterfaces->size() : 0;
+ sal_uInt16 nFirstInterface = _pParentPool ? _pParentPool->_vInterfaces.size() : 0;
- if ( _nCurInterface < nFirstInterface && _nCurGroup >= _pParentPool->_pGroups->size() )
+ if ( _nCurInterface < nFirstInterface && _nCurGroup >= _pParentPool->_vGroups.size() )
_nCurInterface = nFirstInterface;
if ( _nCurInterface < nFirstInterface )
@@ -254,15 +229,15 @@ const SfxSlot* SfxSlotPool::NextSlot()
sal_uInt16 nInterface = _nCurInterface - nFirstInterface;
// possibly we are already at the end
- if ( nInterface >= _pInterfaces->size() )
+ if ( nInterface >= _vInterfaces.size() )
return nullptr;
// look for further matching func-defs within the same Interface
- SfxInterface* pInterface = (*_pInterfaces)[nInterface];
+ SfxInterface* pInterface = _vInterfaces[nInterface];
while ( ++_nCurMsg < pInterface->Count() )
{
SfxSlot& rMsg = pInterface->pSlots[_nCurMsg];
- if (rMsg.GetGroupId() == _pGroups->at(_nCurGroup))
+ if (rMsg.GetGroupId() == _vGroups.at(_nCurGroup))
return &rMsg;
}
@@ -276,22 +251,21 @@ const SfxSlot* SfxSlotPool::NextSlot()
SfxInterface* SfxSlotPool::FirstInterface()
{
_nCurInterface = 0;
- if ( !_pInterfaces || !_pInterfaces->size() )
+ if ( _vInterfaces.empty() )
return nullptr;
- return _pParentPool ? _pParentPool->FirstInterface() : (*_pInterfaces)[0];
+ return _pParentPool ? _pParentPool->FirstInterface() : _vInterfaces[0];
}
-const SfxSlot* SfxSlotPool::GetUnoSlot( const OUString& rName )
+const SfxSlot* SfxSlotPool::GetUnoSlot( const OUString& rName ) const
{
const SfxSlot *pSlot = nullptr;
- if (_pInterfaces)
- for (auto const & nInterface: *_pInterfaces)
- {
- pSlot = nInterface->GetSlot( rName );
- if ( pSlot )
- break;
- }
+ for (auto const & nInterface: _vInterfaces)
+ {
+ pSlot = nInterface->GetSlot( rName );
+ if ( pSlot )
+ break;
+ }
if ( !pSlot && _pParentPool )
pSlot = _pParentPool->GetUnoSlot( rName );
More information about the Libreoffice-commits
mailing list