24#include <unordered_map>
25#include <osl/diagnose.h>
27typedef std::unordered_map< OUString,
37 void addStyleName(
const std::shared_ptr<SfxItemSet>& pStyle )
40 std::shared_ptr<SfxItemSet> getByName(
const OUString& rName ) {
return mMap[rName]; }
41 void clear() { mMap.clear(); }
46void SwStyleCache::addCompletePool(
StylePool& rPool )
48 std::unique_ptr<IStylePoolIteratorAccess> pIter = rPool.
createIterator();
49 std::shared_ptr<SfxItemSet> pStyle = pIter->getNext();
53 mMap[
aName ] = pStyle;
54 pStyle = pIter->getNext();
64 SwStyleCache maCharCache;
65 SwStyleCache maParaCache;
69 explicit SwStyleManager(
SfxItemSet const* pIgnorableParagraphItems)
70 : m_aAutoParaPool(pIgnorableParagraphItems)
74 const OUString* pParentName =
nullptr )
override;
75 virtual std::shared_ptr<SfxItemSet>
getByName(
const OUString& rName,
77 virtual void getAllStyles( std::vector<std::shared_ptr<SfxItemSet>> &rStyles,
80 SwAutoStyleFamily eFamily )
override;
88 return std::make_unique<SwStyleManager>( pIgnorableParagraphItems );
91void SwStyleManager::clearCaches()
97std::shared_ptr<SfxItemSet> SwStyleManager::getAutomaticStyle(
const SfxItemSet& rSet,
99 const OUString* pParentName )
107std::shared_ptr<SfxItemSet> SwStyleManager::cacheAutomaticStyle(
const SfxItemSet& rSet,
113 std::shared_ptr<SfxItemSet> pStyle = rAutoPool.
insertItemSet( rSet );
116 maCharCache.addStyleName( pStyle );
120 maParaCache.addStyleName( pStyle );
125std::shared_ptr<SfxItemSet> SwStyleManager::getByName(
const OUString& rName,
131 std::shared_ptr<SfxItemSet> pStyle = rCache.getByName( rName );
136 OSL_FAIL(
"Don't ask for uncached styles" );
137 rCache.addCompletePool( rAutoPool );
138 pStyle = rCache.getByName( rName );
144void SwStyleManager::getAllStyles( std::vector<std::shared_ptr<SfxItemSet>> &rStyles,
150 std::unique_ptr<IStylePoolIteratorAccess> pIter = rAutoPool.
createIterator(
true,
true );
151 std::shared_ptr<SfxItemSet> pStyle = pIter->getNext();
155 rStyles.push_back( pStyle );
157 pStyle = pIter->getNext();
virtual std::shared_ptr< SfxItemSet > getByName(const OUString &rName, SwAutoStyleFamily eFamily)=0
It's slow to iterate through a stylepool looking for a special name, but if the style has been insert...
virtual void clearCaches()=0
To release the cached styles (shared_pointer!)
virtual std::shared_ptr< SfxItemSet > cacheAutomaticStyle(const SfxItemSet &rSet, SwAutoStyleFamily eFamily)=0
insert the style to the pool and the cache (used during import)
virtual void getAllStyles(std::vector< std::shared_ptr< SfxItemSet > > &rStyles, SwAutoStyleFamily eFamily)=0
virtual std::shared_ptr< SfxItemSet > getAutomaticStyle(const SfxItemSet &rSet, SwAutoStyleFamily eFamily, const OUString *pParentName=nullptr)=0
static OUString nameOf(const std::shared_ptr< SfxItemSet > &pSet)
std::unique_ptr< IStylePoolIteratorAccess > createIterator(const bool bSkipUnusedItemSets=false, const bool bSkipIgnorableItems=false)
std::shared_ptr< SfxItemSet > insertItemSet(const SfxItemSet &rSet, const OUString *pParentName=nullptr)
std::unordered_map< OUString, std::shared_ptr< SfxItemSet > > SwStyleNameCache
std::unique_ptr< IStyleAccess > createStyleManager(SfxItemSet const *pIgnorableParagraphItems)