23#include <unordered_map>
24#include <osl/diagnose.h>
26typedef std::unordered_map< OUString,
36 void addStyleName(
const std::shared_ptr<SfxItemSet>& pStyle )
39 std::shared_ptr<SfxItemSet> getByName(
const OUString& rName ) {
return mMap[rName]; }
40 void clear() { mMap.clear(); }
45void SwStyleCache::addCompletePool(
StylePool& rPool )
47 std::unique_ptr<IStylePoolIteratorAccess> pIter = rPool.
createIterator();
48 std::shared_ptr<SfxItemSet> pStyle = pIter->getNext();
52 mMap[
aName ] = pStyle;
53 pStyle = pIter->getNext();
63 SwStyleCache maCharCache;
64 SwStyleCache maParaCache;
68 explicit SwStyleManager(
SfxItemSet const* pIgnorableParagraphItems)
69 : m_aAutoParaPool(pIgnorableParagraphItems)
73 const OUString* pParentName =
nullptr )
override;
74 virtual std::shared_ptr<SfxItemSet>
getByName(
const OUString& rName,
76 virtual void getAllStyles( std::vector<std::shared_ptr<SfxItemSet>> &rStyles,
79 SwAutoStyleFamily eFamily )
override;
87 return std::make_unique<SwStyleManager>( pIgnorableParagraphItems );
90void SwStyleManager::clearCaches()
96std::shared_ptr<SfxItemSet> SwStyleManager::getAutomaticStyle(
const SfxItemSet& rSet,
98 const OUString* pParentName )
105std::shared_ptr<SfxItemSet> SwStyleManager::cacheAutomaticStyle(
const SfxItemSet& rSet,
110 std::shared_ptr<SfxItemSet> pStyle = rAutoPool.
insertItemSet( rSet );
113 maCharCache.addStyleName( pStyle );
117 maParaCache.addStyleName( pStyle );
122std::shared_ptr<SfxItemSet> SwStyleManager::getByName(
const OUString& rName,
128 std::shared_ptr<SfxItemSet> pStyle = rCache.getByName( rName );
133 OSL_FAIL(
"Don't ask for uncached styles" );
134 rCache.addCompletePool( rAutoPool );
135 pStyle = rCache.getByName( rName );
140void SwStyleManager::getAllStyles( std::vector<std::shared_ptr<SfxItemSet>> &rStyles,
146 std::unique_ptr<IStylePoolIteratorAccess> pIter = rAutoPool.
createIterator(
true,
true );
147 std::shared_ptr<SfxItemSet> pStyle = pIter->getNext();
150 rStyles.push_back( pStyle );
152 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)