23 #include <unordered_map>
24 #include <osl/diagnose.h>
26 typedef 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]; }
44 void SwStyleCache::addCompletePool(
StylePool& rPool )
46 std::unique_ptr<IStylePoolIteratorAccess> pIter = rPool.
createIterator();
47 std::shared_ptr<SfxItemSet> pStyle = pIter->getNext();
51 mMap[
aName ] = pStyle;
52 pStyle = pIter->getNext();
62 std::unique_ptr<SwStyleCache> mpCharCache;
63 std::unique_ptr<SwStyleCache> mpParaCache;
67 explicit SwStyleManager(
SfxItemSet const* pIgnorableParagraphItems)
68 : m_aAutoParaPool(pIgnorableParagraphItems)
72 const OUString* pParentName =
nullptr )
override;
73 virtual std::shared_ptr<SfxItemSet>
getByName(
const OUString& rName,
75 virtual void getAllStyles( std::vector<std::shared_ptr<SfxItemSet>> &rStyles,
78 SwAutoStyleFamily eFamily )
override;
86 return std::make_unique<SwStyleManager>( pIgnorableParagraphItems );
89 void SwStyleManager::clearCaches()
95 std::shared_ptr<SfxItemSet> SwStyleManager::getAutomaticStyle(
const SfxItemSet& rSet,
97 const OUString* pParentName )
104 std::shared_ptr<SfxItemSet> SwStyleManager::cacheAutomaticStyle(
const SfxItemSet& rSet,
109 std::shared_ptr<SfxItemSet> pStyle = rAutoPool.
insertItemSet( rSet );
113 mpCharCache.reset(
new SwStyleCache());
114 mpCharCache->addStyleName( pStyle );
119 mpParaCache.reset(
new SwStyleCache());
120 mpParaCache->addStyleName( pStyle );
125 std::shared_ptr<SfxItemSet> SwStyleManager::getByName(
const OUString& rName,
132 rpCache.reset(
new SwStyleCache());
133 std::shared_ptr<SfxItemSet> pStyle = rpCache->getByName( rName );
138 OSL_FAIL(
"Don't ask for uncached styles" );
139 rpCache->addCompletePool( rAutoPool );
140 pStyle = rpCache->getByName( rName );
145 void SwStyleManager::getAllStyles( std::vector<std::shared_ptr<SfxItemSet>> &rStyles,
151 std::unique_ptr<IStylePoolIteratorAccess> pIter = rAutoPool.
createIterator(
true,
true );
152 std::shared_ptr<SfxItemSet> pStyle = pIter->getNext();
155 rStyles.push_back( pStyle );
157 pStyle = pIter->getNext();
virtual std::shared_ptr< SfxItemSet > getAutomaticStyle(const SfxItemSet &rSet, SwAutoStyleFamily eFamily, const OUString *pParentName=nullptr)=0
std::shared_ptr< SfxItemSet > insertItemSet(const SfxItemSet &rSet, const OUString *pParentName=nullptr)
std::unordered_map< OUString, std::shared_ptr< SfxItemSet > > SwStyleNameCache
static OUString nameOf(const std::shared_ptr< SfxItemSet > &pSet)
virtual void getAllStyles(std::vector< std::shared_ptr< SfxItemSet >> &rStyles, SwAutoStyleFamily eFamily)=0
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!)
std::unique_ptr< IStylePoolIteratorAccess > createIterator(const bool bSkipUnusedItemSets=false, const bool bSkipIgnorableItems=false)
std::unique_ptr< IStyleAccess > createStyleManager(SfxItemSet const *pIgnorableParagraphItems)
virtual std::shared_ptr< SfxItemSet > cacheAutomaticStyle(const SfxItemSet &rSet, SwAutoStyleFamily eFamily)=0
insert the style to the pool and the cache (used during import)