Kaydet (Commit) 2c71f383 authored tarafından Matthew Pottage's avatar Matthew Pottage Kaydeden (comit) Caolán McNamara

fdo#75757: Remove inheritance from std::vector.

In framework/inc/stdtypes.h. class OUStringList.

Removed inheritance and separated additional functionality into more general
functions. Changed to using std::vector<OUString> rather than SequenceAsVector.

The functions now work for any vector. Although they could be made more general
and support any container by altering the arguments.

Change-Id: I472267029dc69da1ad0a98d55e26e3784f6b07cd
Reviewed-on: https://gerrit.libreoffice.org/13612Reviewed-by: 's avatarCaolán McNamara <caolanm@redhat.com>
Tested-by: 's avatarCaolán McNamara <caolanm@redhat.com>
üst 651441ef
...@@ -90,8 +90,8 @@ struct FileType ...@@ -90,8 +90,8 @@ struct FileType
sClipboardFormat.clear(); sClipboardFormat.clear();
nDocumentIconID = 0; nDocumentIconID = 0;
lUINames.free (); lUINames.free ();
lURLPattern.free(); framework::free(lURLPattern);
lExtensions.free(); framework::free(lExtensions);
} }
inline FileType& impl_copy( const FileType& rCopy ) inline FileType& impl_copy( const FileType& rCopy )
...@@ -153,8 +153,8 @@ struct Filter ...@@ -153,8 +153,8 @@ struct Filter
nFlags = 0; nFlags = 0;
nFileFormatVersion = 0; nFileFormatVersion = 0;
sTemplateName.clear(); sTemplateName.clear();
lUINames.free (); lUINames.free();
lUserData.free (); framework::free(lUserData);
} }
inline Filter& impl_copy( const Filter& rCopy ) inline Filter& impl_copy( const Filter& rCopy )
...@@ -213,7 +213,7 @@ struct Detector ...@@ -213,7 +213,7 @@ struct Detector
inline void impl_clear() inline void impl_clear()
{ {
sName.clear(); sName.clear();
lTypes.free(); framework::free(lTypes);
} }
inline Detector& impl_copy( const Detector& rCopy ) inline Detector& impl_copy( const Detector& rCopy )
...@@ -254,8 +254,8 @@ struct Loader ...@@ -254,8 +254,8 @@ struct Loader
inline void impl_clear() inline void impl_clear()
{ {
sName.clear(); sName.clear();
lUINames.free (); lUINames.free();
lTypes.free (); framework::free(lTypes);
} }
inline Loader& impl_copy( const Loader& rCopy ) inline Loader& impl_copy( const Loader& rCopy )
...@@ -297,7 +297,7 @@ struct ContentHandler ...@@ -297,7 +297,7 @@ struct ContentHandler
inline void impl_clear() inline void impl_clear()
{ {
sName.clear(); sName.clear();
lTypes.free(); framework::free(lTypes);
} }
inline ContentHandler& impl_copy( const ContentHandler& rCopy ) inline ContentHandler& impl_copy( const ContentHandler& rCopy )
...@@ -335,9 +335,9 @@ class SetNodeHash : public std::unordered_map< OUString , ...@@ -335,9 +335,9 @@ class SetNodeHash : public std::unordered_map< OUString ,
inline void free() inline void free()
{ {
SetNodeHash().swap( *this ); // get rid of reserved capacity SetNodeHash().swap( *this ); // get rid of reserved capacity
lAddedItems.free (); framework::free(lAddedItems);
lChangedItems.free(); framework::free(lChangedItems);
lRemovedItems.free(); framework::free(lRemovedItems);
} }
// Append changed, added or removed items to special lists // Append changed, added or removed items to special lists
......
...@@ -209,7 +209,7 @@ class JobData ...@@ -209,7 +209,7 @@ class JobData
static void appendEnabledJobsForEvent( const css::uno::Reference< css::uno::XComponentContext >& rxContext, static void appendEnabledJobsForEvent( const css::uno::Reference< css::uno::XComponentContext >& rxContext,
const OUString& sEvent , const OUString& sEvent ,
::comphelper::SequenceAsVector< JobData::TJob2DocEventBinding >& lJobs ); ::std::vector< JobData::TJob2DocEventBinding >& lJobs );
// private helper // private helper
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#ifndef INCLUDED_FRAMEWORK_INC_STDTYPES_H #ifndef INCLUDED_FRAMEWORK_INC_STDTYPES_H
#define INCLUDED_FRAMEWORK_INC_STDTYPES_H #define INCLUDED_FRAMEWORK_INC_STDTYPES_H
#include <algorithm>
#include <queue> #include <queue>
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
...@@ -28,7 +29,6 @@ ...@@ -28,7 +29,6 @@
#include <com/sun/star/awt/KeyEvent.hpp> #include <com/sun/star/awt/KeyEvent.hpp>
#include <comphelper/sequenceasvector.hxx>
#include <cppuhelper/interfacecontainer.hxx> #include <cppuhelper/interfacecontainer.hxx>
#include <rtl/ustring.hxx> #include <rtl/ustring.hxx>
...@@ -79,38 +79,26 @@ struct KeyEventEqualsFunc ...@@ -79,38 +79,26 @@ struct KeyEventEqualsFunc
} }
}; };
/** typedef ::std::vector< OUString > OUStringList;
Basic string list based on a std::vector()
It implements some additional funtionality which can be useful but
is missing at the normal vector implementation.
*/
class OUStringList : public ::comphelper::SequenceAsVector< OUString >
{
public:
// insert given element as the first one into the vector // search for given element
void push_front( const OUString& sElement ) template <class T>
{ typename std::vector<T>::iterator find( std::vector<T>& vec, const T& sElement )
insert( begin(), sElement ); {
} return ::std::find(vec.begin(), vec.end(), sElement);
}
// search for given element
iterator find( const OUString& sElement )
{
return ::std::find(begin(), end(), sElement);
}
const_iterator findConst( const OUString& sElement ) const template <class T>
{ typename std::vector<T>::const_iterator find( const std::vector<T>& vec, const T& sElement )
return ::std::find(begin(), end(), sElement); {
} return ::std::find(vec.begin(), vec.end(), sElement);
}
// the only way to free used memory really! template <class T>
void free() void free(std::vector<T>& vec)
{ {
OUStringList().swap( *this );// get rid of reserved capacity OUStringList().swap(vec);
} }
};
/** /**
Basic string queue based on a std::queue() Basic string queue based on a std::queue()
......
...@@ -37,6 +37,8 @@ ...@@ -37,6 +37,8 @@
#include <com/sun/star/io/XSeekable.hpp> #include <com/sun/star/io/XSeekable.hpp>
#include <algorithm>
#define PATH_SEPARATOR_ASCII "/" #define PATH_SEPARATOR_ASCII "/"
#define PATH_SEPARATOR_UNICODE ((sal_Unicode)'/') #define PATH_SEPARATOR_UNICODE ((sal_Unicode)'/')
#define PATH_SEPARATOR OUString(PATH_SEPARATOR_ASCII) #define PATH_SEPARATOR OUString(PATH_SEPARATOR_ASCII)
......
...@@ -469,7 +469,7 @@ bool isEnabled( const OUString& sAdminTime , ...@@ -469,7 +469,7 @@ bool isEnabled( const OUString& sAdminTime ,
*/ */
void JobData::appendEnabledJobsForEvent( const css::uno::Reference< css::uno::XComponentContext >& rxContext, void JobData::appendEnabledJobsForEvent( const css::uno::Reference< css::uno::XComponentContext >& rxContext,
const OUString& sEvent , const OUString& sEvent ,
::comphelper::SequenceAsVector< JobData::TJob2DocEventBinding >& lJobs ) ::std::vector< JobData::TJob2DocEventBinding >& lJobs )
{ {
css::uno::Sequence< OUString > lAdditionalJobs = JobData::getEnabledJobsForEvent(rxContext, sEvent); css::uno::Sequence< OUString > lAdditionalJobs = JobData::getEnabledJobsForEvent(rxContext, sEvent);
sal_Int32 c = lAdditionalJobs.getLength(); sal_Int32 c = lAdditionalJobs.getLength();
......
...@@ -210,7 +210,7 @@ void SAL_CALL JobExecutor::trigger( const OUString& sEvent ) throw(css::uno::Run ...@@ -210,7 +210,7 @@ void SAL_CALL JobExecutor::trigger( const OUString& sEvent ) throw(css::uno::Run
// Optimization! // Optimization!
// Check if the given event name exist inside configuration and reject wrong requests. // Check if the given event name exist inside configuration and reject wrong requests.
// This optimization suppress using of the cfg api for getting event and job descriptions ... // This optimization suppress using of the cfg api for getting event and job descriptions ...
if (m_lEvents.find(sEvent) == m_lEvents.end()) if (framework::find(m_lEvents, sEvent) == m_lEvents.end())
return; return;
// get list of all enabled jobs // get list of all enabled jobs
...@@ -255,7 +255,7 @@ void SAL_CALL JobExecutor::notifyEvent( const css::document::EventObject& aEvent ...@@ -255,7 +255,7 @@ void SAL_CALL JobExecutor::notifyEvent( const css::document::EventObject& aEvent
OUString EVENT_ON_DOCUMENT_ADDED("onDocumentAdded"); // Job API event : OnCreate or OnLoadFinished OUString EVENT_ON_DOCUMENT_ADDED("onDocumentAdded"); // Job API event : OnCreate or OnLoadFinished
OUString aModuleIdentifier; OUString aModuleIdentifier;
::comphelper::SequenceAsVector< JobData::TJob2DocEventBinding > lJobs; ::std::vector< JobData::TJob2DocEventBinding > lJobs;
/* SAFE */ { /* SAFE */ {
osl::MutexGuard g(rBHelper.rMutex); osl::MutexGuard g(rBHelper.rMutex);
...@@ -279,7 +279,7 @@ void SAL_CALL JobExecutor::notifyEvent( const css::document::EventObject& aEvent ...@@ -279,7 +279,7 @@ void SAL_CALL JobExecutor::notifyEvent( const css::document::EventObject& aEvent
(aEvent.EventName == EVENT_ON_LOAD) (aEvent.EventName == EVENT_ON_LOAD)
) )
{ {
if (m_lEvents.find(EVENT_ON_DOCUMENT_OPENED) != m_lEvents.end()) if (find(m_lEvents, EVENT_ON_DOCUMENT_OPENED) != m_lEvents.end())
JobData::appendEnabledJobsForEvent(m_xContext, EVENT_ON_DOCUMENT_OPENED, lJobs); JobData::appendEnabledJobsForEvent(m_xContext, EVENT_ON_DOCUMENT_OPENED, lJobs);
} }
...@@ -289,17 +289,17 @@ void SAL_CALL JobExecutor::notifyEvent( const css::document::EventObject& aEvent ...@@ -289,17 +289,17 @@ void SAL_CALL JobExecutor::notifyEvent( const css::document::EventObject& aEvent
(aEvent.EventName == EVENT_ON_LOAD_FINISHED) (aEvent.EventName == EVENT_ON_LOAD_FINISHED)
) )
{ {
if (m_lEvents.find(EVENT_ON_DOCUMENT_ADDED) != m_lEvents.end()) if (find(m_lEvents, EVENT_ON_DOCUMENT_ADDED) != m_lEvents.end())
JobData::appendEnabledJobsForEvent(m_xContext, EVENT_ON_DOCUMENT_ADDED, lJobs); JobData::appendEnabledJobsForEvent(m_xContext, EVENT_ON_DOCUMENT_ADDED, lJobs);
} }
// Add all jobs for "real" notified event too .-) // Add all jobs for "real" notified event too .-)
if (m_lEvents.find(aEvent.EventName) != m_lEvents.end()) if (find(m_lEvents, aEvent.EventName) != m_lEvents.end())
JobData::appendEnabledJobsForEvent(m_xContext, aEvent.EventName, lJobs); JobData::appendEnabledJobsForEvent(m_xContext, aEvent.EventName, lJobs);
} /* SAFE */ } /* SAFE */
// step over all enabled jobs and execute it // step over all enabled jobs and execute it
::comphelper::SequenceAsVector< JobData::TJob2DocEventBinding >::const_iterator pIt; ::std::vector< JobData::TJob2DocEventBinding >::const_iterator pIt;
for ( pIt = lJobs.begin(); for ( pIt = lJobs.begin();
pIt != lJobs.end(); pIt != lJobs.end();
++pIt ) ++pIt )
...@@ -340,7 +340,7 @@ void SAL_CALL JobExecutor::elementInserted( const css::container::ContainerEvent ...@@ -340,7 +340,7 @@ void SAL_CALL JobExecutor::elementInserted( const css::container::ContainerEvent
OUString sEvent = ::utl::extractFirstFromConfigurationPath(sValue); OUString sEvent = ::utl::extractFirstFromConfigurationPath(sValue);
if (!sEvent.isEmpty()) if (!sEvent.isEmpty())
{ {
OUStringList::iterator pEvent = m_lEvents.find(sEvent); OUStringList::iterator pEvent = find(m_lEvents, sEvent);
if (pEvent == m_lEvents.end()) if (pEvent == m_lEvents.end())
m_lEvents.push_back(sEvent); m_lEvents.push_back(sEvent);
} }
...@@ -355,7 +355,7 @@ void SAL_CALL JobExecutor::elementRemoved ( const css::container::ContainerEvent ...@@ -355,7 +355,7 @@ void SAL_CALL JobExecutor::elementRemoved ( const css::container::ContainerEvent
OUString sEvent = ::utl::extractFirstFromConfigurationPath(sValue); OUString sEvent = ::utl::extractFirstFromConfigurationPath(sValue);
if (!sEvent.isEmpty()) if (!sEvent.isEmpty())
{ {
OUStringList::iterator pEvent = m_lEvents.find(sEvent); OUStringList::iterator pEvent = find(m_lEvents, sEvent);
if (pEvent != m_lEvents.end()) if (pEvent != m_lEvents.end())
m_lEvents.erase(pEvent); m_lEvents.erase(pEvent);
} }
......
...@@ -600,7 +600,7 @@ OUStringList PathSettings::impl_readOldFormat(const OUString& sPath) ...@@ -600,7 +600,7 @@ OUStringList PathSettings::impl_readOldFormat(const OUString& sPath)
} }
else if (aVal >>= lStringListVal) else if (aVal >>= lStringListVal)
{ {
aPathVal << lStringListVal; aPathVal = comphelper::sequenceToContainer<OUStringList>(lStringListVal);
} }
} }
...@@ -624,17 +624,19 @@ PathSettings::PathInfo PathSettings::impl_readNewFormat(const OUString& sPath) ...@@ -624,17 +624,19 @@ PathSettings::PathInfo PathSettings::impl_readNewFormat(const OUString& sPath)
// read internal path list // read internal path list
css::uno::Reference< css::container::XNameAccess > xIPath; css::uno::Reference< css::container::XNameAccess > xIPath;
xPath->getByName(CFGPROP_INTERNALPATHS) >>= xIPath; xPath->getByName(CFGPROP_INTERNALPATHS) >>= xIPath;
aPathVal.lInternalPaths << xIPath->getElementNames(); aPathVal.lInternalPaths = comphelper::sequenceToContainer<OUStringList>(xIPath->getElementNames());
// read user defined path list // read user defined path list
aPathVal.lUserPaths << xPath->getByName(CFGPROP_USERPATHS); css::uno::Sequence<OUString> vTmpUserPathsSeq;
xPath->getByName(CFGPROP_USERPATHS) >>= vTmpUserPathsSeq;
aPathVal.lUserPaths = comphelper::sequenceToContainer<OUStringList>(vTmpUserPathsSeq);
// read the writeable path // read the writeable path
xPath->getByName(CFGPROP_WRITEPATH) >>= aPathVal.sWritePath; xPath->getByName(CFGPROP_WRITEPATH) >>= aPathVal.sWritePath;
// avoid duplicates, by removing the writeable path from // avoid duplicates, by removing the writeable path from
// the user defined path list if it happens to be there too // the user defined path list if it happens to be there too
OUStringList::iterator aI = aPathVal.lUserPaths.find(aPathVal.sWritePath); OUStringList::iterator aI = find(aPathVal.lUserPaths, aPathVal.sWritePath);
if (aI != aPathVal.lUserPaths.end()) if (aI != aPathVal.lUserPaths.end())
aPathVal.lUserPaths.erase(aI); aPathVal.lUserPaths.erase(aI);
...@@ -677,7 +679,7 @@ void PathSettings::impl_storePath(const PathSettings::PathInfo& aPath) ...@@ -677,7 +679,7 @@ void PathSettings::impl_storePath(const PathSettings::PathInfo& aPath)
::comphelper::ConfigurationHelper::writeRelativeKey(xCfgNew, ::comphelper::ConfigurationHelper::writeRelativeKey(xCfgNew,
aResubstPath.sPathName, aResubstPath.sPathName,
CFGPROP_USERPATHS, CFGPROP_USERPATHS,
css::uno::makeAny(aResubstPath.lUserPaths.getAsConstList())); css::uno::makeAny(comphelper::containerToSequence(aResubstPath.lUserPaths)));
} }
::comphelper::ConfigurationHelper::writeRelativeKey(xCfgNew, ::comphelper::ConfigurationHelper::writeRelativeKey(xCfgNew,
...@@ -722,8 +724,8 @@ void PathSettings::impl_mergeOldUserPaths( PathSettings::PathInfo& rPath, ...@@ -722,8 +724,8 @@ void PathSettings::impl_mergeOldUserPaths( PathSettings::PathInfo& rPath,
else else
{ {
if ( if (
( rPath.lInternalPaths.findConst(sOld) == rPath.lInternalPaths.end()) && ( find(rPath.lInternalPaths, sOld) == rPath.lInternalPaths.end()) &&
( rPath.lUserPaths.findConst(sOld) == rPath.lUserPaths.end() ) && ( find(rPath.lUserPaths, sOld) == rPath.lUserPaths.end() ) &&
(! rPath.sWritePath.equals(sOld) ) (! rPath.sWritePath.equals(sOld) )
) )
rPath.lUserPaths.push_back(sOld); rPath.lUserPaths.push_back(sOld);
...@@ -924,18 +926,18 @@ void PathSettings::impl_notifyPropListener( PathSettings::EChangeOp /*eOp*/ ...@@ -924,18 +926,18 @@ void PathSettings::impl_notifyPropListener( PathSettings::EChangeOp /*eOp*/
case IDGROUP_INTERNAL_PATHS : case IDGROUP_INTERNAL_PATHS :
{ {
if (pPathOld) if (pPathOld)
lOldVals[0] <<= pPathOld->lInternalPaths.getAsConstList(); lOldVals[0] <<= comphelper::containerToSequence(pPathOld->lInternalPaths);
if (pPathNew) if (pPathNew)
lNewVals[0] <<= pPathNew->lInternalPaths.getAsConstList(); lNewVals[0] <<= comphelper::containerToSequence(pPathNew->lInternalPaths);
} }
break; break;
case IDGROUP_USER_PATHS : case IDGROUP_USER_PATHS :
{ {
if (pPathOld) if (pPathOld)
lOldVals[0] <<= pPathOld->lUserPaths.getAsConstList(); lOldVals[0] <<= comphelper::containerToSequence(pPathOld->lUserPaths);
if (pPathNew) if (pPathNew)
lNewVals[0] <<= pPathNew->lUserPaths.getAsConstList(); lNewVals[0] <<= comphelper::containerToSequence(pPathNew->lUserPaths);
} }
break; break;
...@@ -1054,10 +1056,10 @@ void PathSettings::impl_purgeKnownPaths(PathSettings::PathInfo& rPath, ...@@ -1054,10 +1056,10 @@ void PathSettings::impl_purgeKnownPaths(PathSettings::PathInfo& rPath,
++pIt ) ++pIt )
{ {
const OUString& rItem = *pIt; const OUString& rItem = *pIt;
OUStringList::iterator pItem = lList.find(rItem); OUStringList::iterator pItem = find(lList, rItem);
if (pItem != lList.end()) if (pItem != lList.end())
lList.erase(pItem); lList.erase(pItem);
pItem = rPath.lUserPaths.find(rItem); pItem = find(rPath.lUserPaths, rItem);
if (pItem != rPath.lUserPaths.end()) if (pItem != rPath.lUserPaths.end())
rPath.lUserPaths.erase(pItem); rPath.lUserPaths.erase(pItem);
} }
...@@ -1067,7 +1069,7 @@ void PathSettings::impl_purgeKnownPaths(PathSettings::PathInfo& rPath, ...@@ -1067,7 +1069,7 @@ void PathSettings::impl_purgeKnownPaths(PathSettings::PathInfo& rPath,
while ( pIt != rPath.lUserPaths.end() ) while ( pIt != rPath.lUserPaths.end() )
{ {
const OUString& rItem = *pIt; const OUString& rItem = *pIt;
OUStringList::iterator pItem = lList.find(rItem); OUStringList::iterator pItem = find(lList, rItem);
if ( pItem == lList.end() ) if ( pItem == lList.end() )
{ {
rPath.lUserPaths.erase(pIt); rPath.lUserPaths.erase(pIt);
...@@ -1085,13 +1087,13 @@ void PathSettings::impl_purgeKnownPaths(PathSettings::PathInfo& rPath, ...@@ -1085,13 +1087,13 @@ void PathSettings::impl_purgeKnownPaths(PathSettings::PathInfo& rPath,
++pIt ) ++pIt )
{ {
const OUString& rItem = *pIt; const OUString& rItem = *pIt;
OUStringList::iterator pItem = lList.find(rItem); OUStringList::iterator pItem = find(lList, rItem);
if (pItem != lList.end()) if (pItem != lList.end())
lList.erase(pItem); lList.erase(pItem);
} }
// Erase the write path from lList // Erase the write path from lList
OUStringList::iterator pItem = lList.find(rPath.sWritePath); OUStringList::iterator pItem = find(lList, rPath.sWritePath);
if (pItem != lList.end()) if (pItem != lList.end())
lList.erase(pItem); lList.erase(pItem);
} }
...@@ -1173,13 +1175,13 @@ css::uno::Any PathSettings::impl_getPathValue(sal_Int32 nID) const ...@@ -1173,13 +1175,13 @@ css::uno::Any PathSettings::impl_getPathValue(sal_Int32 nID) const
case IDGROUP_INTERNAL_PATHS : case IDGROUP_INTERNAL_PATHS :
{ {
aVal <<= pPath->lInternalPaths.getAsConstList(); aVal <<= comphelper::containerToSequence(pPath->lInternalPaths);
} }
break; break;
case IDGROUP_USER_PATHS : case IDGROUP_USER_PATHS :
{ {
aVal <<= pPath->lUserPaths.getAsConstList(); aVal <<= comphelper::containerToSequence(pPath->lUserPaths);
} }
break; break;
...@@ -1249,8 +1251,9 @@ void PathSettings::impl_setPathValue( sal_Int32 nID , ...@@ -1249,8 +1251,9 @@ void PathSettings::impl_setPathValue( sal_Int32 nID ,
static_cast< ::cppu::OWeakObject* >(this)); static_cast< ::cppu::OWeakObject* >(this));
} }
OUStringList lList; css::uno::Sequence<OUString> lTmpList;
lList << aVal; aVal >>= lTmpList;
OUStringList lList = comphelper::sequenceToContainer<OUStringList>(lTmpList);
if (! impl_isValidPath(lList)) if (! impl_isValidPath(lList))
throw css::lang::IllegalArgumentException(); throw css::lang::IllegalArgumentException();
aChangePath.lInternalPaths = lList; aChangePath.lInternalPaths = lList;
...@@ -1269,8 +1272,9 @@ void PathSettings::impl_setPathValue( sal_Int32 nID , ...@@ -1269,8 +1272,9 @@ void PathSettings::impl_setPathValue( sal_Int32 nID ,
static_cast< ::cppu::OWeakObject* >(this)); static_cast< ::cppu::OWeakObject* >(this));
} }
OUStringList lList; css::uno::Sequence<OUString> lTmpList;
lList << aVal; aVal >>= lTmpList;
OUStringList lList = comphelper::sequenceToContainer<OUStringList>(lTmpList);
if (! impl_isValidPath(lList)) if (! impl_isValidPath(lList))
throw css::lang::IllegalArgumentException(); throw css::lang::IllegalArgumentException();
aChangePath.lUserPaths = lList; aChangePath.lUserPaths = lList;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment