diff options
author | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-08-16 16:13:59 -0400 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-08-16 21:31:44 -0400 |
commit | 1b183738aecc32219920a698196c72afebcdd8c0 (patch) | |
tree | 2ce068499efac6011ce20e5def1156aef7d73e3f /xmloff/source | |
parent | e4f55865078e887a34d7b127b75d01ae374968de (diff) |
Use ptr_set for auto style parent list. That seems like a natural fit.
Change-Id: I9fc094ec4aa7e4a6d4e637c5940c361639d44c65
Diffstat (limited to 'xmloff/source')
-rw-r--r-- | xmloff/source/style/impastp1.cxx | 14 | ||||
-rw-r--r-- | xmloff/source/style/impastp3.cxx | 5 | ||||
-rw-r--r-- | xmloff/source/style/impastp4.cxx | 118 | ||||
-rw-r--r-- | xmloff/source/style/impastpl.hxx | 45 |
4 files changed, 84 insertions, 98 deletions
diff --git a/xmloff/source/style/impastp1.cxx b/xmloff/source/style/impastp1.cxx index 2e6f2ce879e5..4d813aed3a32 100644 --- a/xmloff/source/style/impastp1.cxx +++ b/xmloff/source/style/impastp1.cxx @@ -28,25 +28,27 @@ XMLFamilyData_Impl::XMLFamilyData_Impl( const OUString& rStrName, const UniReference < SvXMLExportPropertyMapper > &rMapper, const OUString& rStrPrefix, - sal_Bool bAsFam ) : + bool bAsFamily ) : mnFamily( nFamily ), maStrFamilyName( rStrName), mxMapper( rMapper ), - mnCount( 0 ), mnName( 0 ), maStrPrefix( rStrPrefix ), bAsFamily( bAsFam ) + mnCount( 0 ), mnName( 0 ), maStrPrefix( rStrPrefix ), mbAsFamily( bAsFamily ) { - mpParentList = new SvXMLAutoStylePoolParentsP_Impl; mpNameList = new SvXMLAutoStylePoolNamesP_Impl; } +XMLFamilyData_Impl::XMLFamilyData_Impl( sal_Int32 nFamily ) : + mnFamily( nFamily ), mpNameList( NULL ), mnCount( 0 ), mnName( 0 ), + mbAsFamily( false ) +{} + XMLFamilyData_Impl::~XMLFamilyData_Impl() { - delete mpParentList; delete mpNameList; } void XMLFamilyData_Impl::ClearEntries() { - delete mpParentList; - mpParentList = new SvXMLAutoStylePoolParentsP_Impl; + maParents.clear(); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/impastp3.cxx b/xmloff/source/style/impastp3.cxx index 91fff88fad03..c99fd9e4d7c9 100644 --- a/xmloff/source/style/impastp3.cxx +++ b/xmloff/source/style/impastp3.cxx @@ -146,4 +146,9 @@ OUString SvXMLAutoStylePoolParentP_Impl::Find( const XMLFamilyData_Impl& rFamily return sName; } +bool SvXMLAutoStylePoolParentP_Impl::operator< (const SvXMLAutoStylePoolParentP_Impl& rOther) const +{ + return msParent < rOther.msParent; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/impastp4.cxx b/xmloff/source/style/impastp4.cxx index c8f3798bd3e8..5f5dffa79f4c 100644 --- a/xmloff/source/style/impastp4.cxx +++ b/xmloff/source/style/impastp4.cxx @@ -149,80 +149,70 @@ void SvXMLAutoStylePoolP_Impl::GetRegisteredNames( // if not added, yet. bool SvXMLAutoStylePoolP_Impl::Add( - OUString& rName, sal_Int32 nFamily, const OUString& rParent, + OUString& rName, sal_Int32 nFamily, const OUString& rParentName, const ::std::vector< XMLPropertyState >& rProperties, bool bDontSeek ) { - bool bRet = false; - XMLFamilyData_Impl aTemporary( nFamily ); FamilyListType::iterator aFind = maFamilyList.find(aTemporary); DBG_ASSERT(aFind != maFamilyList.end(), "SvXMLAutoStylePool_Impl::Add: unknown family"); - if (aFind != maFamilyList.end()) - { - XMLFamilyData_Impl &rFamily = *aFind; + if (aFind == maFamilyList.end()) + return false; - SvXMLAutoStylePoolParentP_Impl aTmp( rParent ); - SvXMLAutoStylePoolParentP_Impl *pParent = 0; + XMLFamilyData_Impl &rFamily = *aFind; - SvXMLAutoStylePoolParentsP_Impl *pParents = rFamily.mpParentList; - SvXMLAutoStylePoolParentsP_Impl::const_iterator const it2 = - pParents->find(&aTmp); - if (it2 != pParents->end()) - { - pParent = *it2; - } - else - { - pParent = new SvXMLAutoStylePoolParentP_Impl( rParent ); - pParents->insert( pParent ); - } + SvXMLAutoStylePoolParentP_Impl aTmp(rParentName); + XMLFamilyData_Impl::ParentsType::iterator it2 = rFamily.maParents.find(aTmp); + if (it2 == rFamily.maParents.end()) + { + std::pair<XMLFamilyData_Impl::ParentsType::iterator,bool> r = + rFamily.maParents.insert(new SvXMLAutoStylePoolParentP_Impl(rParentName)); + it2 = r.first; + } - if( pParent->Add( rFamily, rProperties, rName, bDontSeek ) ) - { - rFamily.mnCount++; - bRet = true; - } + SvXMLAutoStylePoolParentP_Impl& rParent = *it2; + + bool bRet = false; + if (rParent.Add(rFamily, rProperties, rName, bDontSeek)) + { + rFamily.mnCount++; + bRet = true; } return bRet; } -sal_Bool SvXMLAutoStylePoolP_Impl::AddNamed(const OUString& rName, sal_Int32 nFamily, - const OUString& rParent, const ::std::vector< XMLPropertyState >& rProperties ) +bool SvXMLAutoStylePoolP_Impl::AddNamed( + const OUString& rName, sal_Int32 nFamily, const OUString& rParentName, + const ::std::vector< XMLPropertyState >& rProperties ) { // get family and parent the same way as in Add() - sal_Bool bRet(sal_False); XMLFamilyData_Impl aTemporary( nFamily ); FamilyListType::iterator aFind = maFamilyList.find(aTemporary); DBG_ASSERT(aFind != maFamilyList.end(), "SvXMLAutoStylePool_Impl::Add: unknown family"); - if (aFind != maFamilyList.end()) - { - XMLFamilyData_Impl &rFamily = *aFind; + if (aFind == maFamilyList.end()) + return false; - SvXMLAutoStylePoolParentP_Impl aTmp( rParent ); - SvXMLAutoStylePoolParentP_Impl *pParent = 0; + XMLFamilyData_Impl &rFamily = *aFind; - SvXMLAutoStylePoolParentsP_Impl *pParents = rFamily.mpParentList; - SvXMLAutoStylePoolParentsP_Impl::const_iterator const it2 = - pParents->find(&aTmp); - if (it2 != pParents->end()) - { - pParent = *it2; - } - else - { - pParent = new SvXMLAutoStylePoolParentP_Impl( rParent ); - pParents->insert( pParent ); - } + SvXMLAutoStylePoolParentP_Impl aTmp(rParentName); + XMLFamilyData_Impl::ParentsType::iterator it2 = rFamily.maParents.find(aTmp); + if (it2 == rFamily.maParents.end()) + { + std::pair<XMLFamilyData_Impl::ParentsType::iterator,bool> r = + rFamily.maParents.insert(new SvXMLAutoStylePoolParentP_Impl(rParentName)); + it2 = r.first; + } - if( pParent->AddNamed( rFamily, rProperties, rName ) ) - { - rFamily.mnCount++; - bRet = sal_True; - } + SvXMLAutoStylePoolParentP_Impl& rParent = *it2; + + bool bRet = false; + if (rParent.AddNamed(rFamily, rProperties, rName)) + { + rFamily.mnCount++; + bRet = true; } return bRet; @@ -245,15 +235,11 @@ OUString SvXMLAutoStylePoolP_Impl::Find( sal_Int32 nFamily, if (iter != maFamilyList.end()) { XMLFamilyData_Impl const& rFamily = *iter; - const SvXMLAutoStylePoolParentsP_Impl* pParents = - rFamily.mpParentList; - SvXMLAutoStylePoolParentP_Impl aTmp( rParent ); - SvXMLAutoStylePoolParentsP_Impl::const_iterator const it2 = - pParents->find(&aTmp); - if (it2 != pParents->end()) + XMLFamilyData_Impl::ParentsType::const_iterator it2 = rFamily.maParents.find(aTmp); + if (it2 != rFamily.maParents.end()) { - sName = (*it2)->Find( rFamily, rProperties ); + sName = it2->Find(rFamily, rProperties); } } @@ -288,9 +274,6 @@ void SvXMLAutoStylePoolP_Impl::exportXML( // create, initialize and fill helper-structure (SvXMLAutoStylePoolProperties_Impl) // which contains a parent-name and a SvXMLAutoStylePoolProperties_Impl // - const SvXMLAutoStylePoolParentsP_Impl *pParents = - rFamily.mpParentList; - SvXMLAutoStylePoolPExport_Impl* aExpStyles = new SvXMLAutoStylePoolPExport_Impl[nCount]; @@ -301,14 +284,15 @@ void SvXMLAutoStylePoolP_Impl::exportXML( aExpStyles[i].mpProperties = 0; } - for (size_t k = 0; k < pParents->size(); k++) + XMLFamilyData_Impl::ParentsType::const_iterator it = rFamily.maParents.begin(), itEnd = rFamily.maParents.end(); + for (; it != itEnd; ++it) { - const SvXMLAutoStylePoolParentP_Impl *const pParent = (*pParents)[k]; - size_t nProperties = pParent->GetPropertiesList().size(); + const SvXMLAutoStylePoolParentP_Impl& rParent = *it; + size_t nProperties = rParent.GetPropertiesList().size(); for( size_t j = 0; j < nProperties; j++ ) { const SvXMLAutoStylePoolPropertiesP_Impl* pProperties = - pParent->GetPropertiesList()[ j ]; + rParent.GetPropertiesList()[ j ]; sal_uLong nPos = pProperties->GetPos(); DBG_ASSERT( nPos < nCount, "SvXMLAutoStylePool_Impl::exportXML: wrong position" ); @@ -317,7 +301,7 @@ void SvXMLAutoStylePoolP_Impl::exportXML( DBG_ASSERT( !aExpStyles[nPos].mpProperties, "SvXMLAutoStylePool_Impl::exportXML: double position" ); aExpStyles[nPos].mpProperties = pProperties; - aExpStyles[nPos].mpParent = &pParent->GetParent(); + aExpStyles[nPos].mpParent = &rParent.GetParent(); } } } @@ -338,7 +322,7 @@ void SvXMLAutoStylePoolP_Impl::exportXML( XML_NAMESPACE_STYLE, XML_NAME, aExpStyles[i].mpProperties->GetName() ); - if( rFamily.bAsFamily ) + if( rFamily.mbAsFamily ) { GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_FAMILY, aStrFamilyName ); @@ -353,7 +337,7 @@ void SvXMLAutoStylePoolP_Impl::exportXML( } OUString sName; - if( rFamily.bAsFamily ) + if( rFamily.mbAsFamily ) sName = GetXMLToken(XML_STYLE); else sName = rFamily.maStrFamilyName; diff --git a/xmloff/source/style/impastpl.hxx b/xmloff/source/style/impastpl.hxx index 84bfdfb781c9..b004115a4705 100644 --- a/xmloff/source/style/impastpl.hxx +++ b/xmloff/source/style/impastpl.hxx @@ -28,12 +28,14 @@ #include <com/sun/star/uno/Reference.h> #include <com/sun/star/xml/sax/XAttributeList.hpp> #include <com/sun/star/xml/sax/XDocumentHandler.hpp> -#include <o3tl/sorted_vector.hxx> #include <xmloff/maptype.hxx> #include <xmloff/xmlexppr.hxx> +#include <boost/noncopyable.hpp> +#include <boost/ptr_container/ptr_set.hpp> + class SvXMLAutoStylePoolP; -class SvXMLAutoStylePoolParentsP_Impl; +class SvXMLAutoStylePoolParentP_Impl; typedef std::set<OUString> SvXMLAutoStylePoolNamesP_Impl; class SvXMLExportPropertyMapper; class SvXMLExport; @@ -42,31 +44,26 @@ class SvXMLExport; // Implementationclass for stylefamily-information -class XMLFamilyData_Impl +struct XMLFamilyData_Impl : boost::noncopyable { -public: - sal_uInt32 mnFamily; + typedef boost::ptr_set<SvXMLAutoStylePoolParentP_Impl> ParentsType; + + sal_uInt32 mnFamily; OUString maStrFamilyName; UniReference < SvXMLExportPropertyMapper > mxMapper; - SvXMLAutoStylePoolParentsP_Impl* mpParentList; + ParentsType maParents; SvXMLAutoStylePoolNamesP_Impl* mpNameList; sal_uInt32 mnCount; sal_uInt32 mnName; OUString maStrPrefix; - sal_Bool bAsFamily; + bool mbAsFamily; -public: XMLFamilyData_Impl( sal_Int32 nFamily, const OUString& rStrName, - const UniReference < SvXMLExportPropertyMapper > & rMapper, - const OUString& rStrPrefix, sal_Bool bAsFamily = sal_True ); + const UniReference<SvXMLExportPropertyMapper>& rMapper, + const OUString& rStrPrefix, bool bAsFamily = true ); - XMLFamilyData_Impl( sal_Int32 nFamily ) : - mnFamily( nFamily ), mpParentList( NULL ), - mpNameList( NULL ), mnCount( 0 ), mnName( 0 ), - bAsFamily( false ) - - {} + XMLFamilyData_Impl( sal_Int32 nFamily ); ~XMLFamilyData_Impl(); friend bool operator<(const XMLFamilyData_Impl& r1, const XMLFamilyData_Impl& r2); @@ -127,6 +124,8 @@ public: { return maPropertiesList; } + + bool operator< (const SvXMLAutoStylePoolParentP_Impl& rOther) const; }; struct SvXMLAutoStylePoolParentPCmp_Impl @@ -136,11 +135,6 @@ struct SvXMLAutoStylePoolParentPCmp_Impl return lhs->GetParent().compareTo( rhs->GetParent() ) < 0; } }; -class SvXMLAutoStylePoolParentsP_Impl : public o3tl::sorted_vector<SvXMLAutoStylePoolParentP_Impl*, SvXMLAutoStylePoolParentPCmp_Impl> -{ -public: - ~SvXMLAutoStylePoolParentsP_Impl() { DeleteAndDestroyAll(); } -}; // Implementationclass of SvXMLAutoStylePool @@ -171,13 +165,14 @@ public: bool Add( OUString& rName, sal_Int32 nFamily, - const OUString& rParent, + const OUString& rParentName, const ::std::vector< XMLPropertyState >& rProperties, bool bDontSeek = false ); - sal_Bool AddNamed( const OUString& rName, sal_Int32 nFamily, - const OUString& rParent, - const ::std::vector< XMLPropertyState >& rProperties ); + bool AddNamed( + const OUString& rName, sal_Int32 nFamily, + const OUString& rParentName, + const ::std::vector< XMLPropertyState >& rProperties ); OUString Find( sal_Int32 nFamily, const OUString& rParent, const ::std::vector< XMLPropertyState >& rProperties ) const; |