namespace svl
{ /** Function object to check whether a style sheet a fulfills specific criteria. *DerivefromthisclassandoverridetheCheck()method.
*/ struct StyleSheetPredicate
{ virtualbool Check(const SfxStyleSheetBase& styleSheet) = 0; virtual ~StyleSheetPredicate() {}
};
/** Function object for cleanup-Strategy for IndexedSfxStyleSheets::Clear(). *DerivefromitanddowhatisnecessarytodisposeofastylesheetinDispose().
*/ struct StyleSheetDisposer
{ virtualvoid Dispose(rtl::Reference<SfxStyleSheetBase> styleSheet) = 0; virtual ~StyleSheetDisposer() {}
};
/** Function object to apply a method on all style sheets. *DerivefromitanddowhateveryouwanttowiththestylesheetintheDoIt()method.
*/ struct StyleSheetCallback
{ virtualvoid DoIt(const SfxStyleSheetBase& styleSheet) = 0; virtual ~StyleSheetCallback() {}
};
/** This class holds SfxStyleSheets and allows for access via an id and a name. * *@warning *Theidentificationofstylesheetshappensbytheirname.Ifthenameofasheetchanges, *itwillnotbefoundagain!PleasecallReindex()afterchangingastylesheet'sname. * *@internal *Thisclasswasimplementedtomitigatesolve#fdo30770. *TheissuedescribesanExcelfilewhichtakesseveralhourstoopen. *Ananalysisrevealedthatthetimeisspentsearchingforstylesheetswithlinearscansinanarray. *Thisclassimplementsaccesstothestylesheetsviatheirnamein(usually)constanttime. * *Thereturntypeformostmethodsisavectorofunsignedintegerswhichdenotetheposition *ofthestylesheetsinthevector,andnotofpointerstostylesheets. *Youwillneedanon-constStyleSheetPooltoobtaintheactualstylesheets. * * *Index-basedaccessisrequiredinseveralcodeportions.Hencewehavetostorethestylesheets *inavectoraswellasinamap.
*/ class SVL_DLLPUBLIC IndexedStyleSheets final
{ public:
IndexedStyleSheets();
/** Removes a style sheet. */ bool RemoveStyleSheet(const rtl::Reference<SfxStyleSheetBase>& style);
/** Check whether a specified style sheet is stored. */ bool HasStyleSheet(const rtl::Reference<SfxStyleSheetBase>& style) const;
/** Obtain the number of style sheets which are held */
sal_Int32 GetNumberOfStyleSheets() const { return mStyleSheets.size(); }
/** Obtain the number of style sheets for which a certain condition holds */
sal_Int32 GetNumberOfStyleSheetsWithPredicate(StyleSheetPredicate& predicate) const;
/** Return the stylesheet by its position. *Youcanobtainthepositionby,e.g.,FindStyleSheetPosition() *@internal *Methodisnotconstbecausethereturnedstylesheetisnotconst
*/
SfxStyleSheetBase* GetStyleSheetByPosition(sal_Int32 pos);
/** Find the position of a provided style. * *@throwsstd::runtime_errorifthestylehasnotbeenfound.
*/
sal_Int32 FindStyleSheetPosition(const SfxStyleSheetBase& style) const;
/** Obtain the positions of all styles which have a given name
*/
std::vector<sal_Int32> FindPositionsByName(const OUString& name) const;
enumclass SearchBehavior
{
ReturnAll,
ReturnFirst
}; /** Obtain the positions of all styles which have a certain name and fulfill a certain condition. * *Thismethodisfastbecauseitcanusethename-basedindex
*/
std::vector<sal_Int32>
FindPositionsByNameAndPredicate(const OUString& name, StyleSheetPredicate& predicate,
SearchBehavior behavior = SearchBehavior::ReturnAll) const;
/** Obtain the positions of all styles which fulfill a certain condition. * *Thismethodisslowbecauseitcannotusethename-basedindex
*/
std::vector<sal_Int32> FindPositionsByPredicate(StyleSheetPredicate& predicate) const;
/** Execute a callback on all style sheets */ void ApplyToAllStyleSheets(StyleSheetCallback& callback) const;
/** Clear the contents of the index. *TheStyleSheetDisposer::Dispose()methodiscalledoneachstylesheet,e.g.,ifyouwanttobroadcast *changes.
*/ void Clear(StyleSheetDisposer& cleanup);
/** Warning: counting for n starts at 0, i.e., the 0th style sheet is the first that is found. Returnsapointerifastylesheetisfound,andthepositionofthefoundstylesheet
*/
std::pair<SfxStyleSheetBase*, sal_Int32>
GetNthStyleSheetThatMatchesPredicate(sal_Int32 n, StyleSheetPredicate& predicate,
sal_Int32 startAt = 0);
/** Get the positions of the style sheets which belong to a certain family.
*/ const std::vector<SfxStyleSheetBase*>& GetStyleSheetsByFamily(SfxStyleFamily) const;
private: /** Register the position of a styleName in the index */ voidRegister(SfxStyleSheetBase& style, sal_Int32 pos);
typedef std::vector<rtl::Reference<SfxStyleSheetBase>> VectorType; /** Vector with the stylesheets to allow for index-based access.
*/
VectorType mStyleSheets;
/** The map type that is used to store the mapping from strings to ids in mStyleSheets * *@internal
* Must be an unordered map. A regular map is too slow for some files. */ typedef std::unordered_multimap<OUString, unsigned> MapType;
/** A map which stores the positions of style sheets by their name */
MapType mPositionsByName;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.