diff options
author | Luboš Luňák <l.lunak@collabora.com> | 2014-11-09 15:30:08 +0100 |
---|---|---|
committer | Luboš Luňák <l.lunak@collabora.com> | 2014-11-09 19:45:27 +0100 |
commit | 738fb2ad77e5a1a4d6e2dc540886a17f4527e4db (patch) | |
tree | 2c0e0b5c4c4cef085bf4ed41766099502b0ac46e /sw/inc/frmfmt.hxx | |
parent | b21df5a993a3815cf736fe3d2eab73eee646b38e (diff) |
faster mapping from nodes to SwFrmFmt's anchored at them
The SwFrmFmtAnchorMap class provides reverse mapping
to SwFrmFmt::GetAnchor().GetCntntAnchor(), so that when code somewhere needs
to update SwFrmFmt's anchored at a position, it's not necessary to iterate
over all of them (which can be a large number e.g. with mail merge).
One special catch with the multimap of SwNodeIndex keys is that
the values of those keys change (whenever the node structure of the document
changes, indexes of nodes change as a result). This makes it impossible to use
any hashing container, as the hashes would change without the container
noticing, but multimap should work fine, as it just requires that the keys
remain sorted, and that is the case. Nevertheless, the old code in the two
converted places is intentionally left there in debug mode to verify the reverse
mapping is updated correctly.
I intentionally went with SwNodeIndex rather than SwPosition, as SwIndex
(the other component of SwPosition) was causing some trouble (see e.g. the
SwPosition comparison operator< , where two same positions are different if one
is registered and the other not) and it doesn't appear to be actually necessary.
Change-Id: I7f1768558f60155d4ba83c84aa7f9e34dc65ebf9
Diffstat (limited to 'sw/inc/frmfmt.hxx')
-rw-r--r-- | sw/inc/frmfmt.hxx | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/sw/inc/frmfmt.hxx b/sw/inc/frmfmt.hxx index 8b33ec20dd90..ca2c2dc193ad 100644 --- a/sw/inc/frmfmt.hxx +++ b/sw/inc/frmfmt.hxx @@ -23,6 +23,8 @@ #include <cppuhelper/weakref.hxx> #include <tools/gen.hxx> #include <format.hxx> +#include <map> +#include <ndindex.hxx> #include "swdllapi.h" class SwFlyFrm; @@ -67,6 +69,7 @@ protected: public: TYPEINFO_OVERRIDE(); ///< Already in base class Client. + virtual ~SwFrmFmt(); /// Destroys all Frms in aDepend (Frms are identified via PTR_CAST). virtual void DelFrms(); @@ -300,6 +303,30 @@ public: SW_DLLPUBLIC bool IsFlyFrmFmtInHeader(const SwFrmFmt& rFmt); +/** + Fast mapping from node positions to SwFrmFmt objects anchored at them. + + SwFrmFmt::GetAnchor().GetCntntAnchor() provides the position where the object is anchored. + This class provides the reverse mapping. It intentionally uses SwNodeIndex instead of SwPosition + to allow simpler implementation, do SwIndex checking explicitly if needed. +*/ +class SwFrmFmtAnchorMap +{ +public: + SwFrmFmtAnchorMap( const SwDoc* doc ); + void Add( SwFrmFmt* fmt, const SwNodeIndex& index ); + void Remove( SwFrmFmt* fmt, const SwNodeIndex& index ); + typedef std::multimap< SwNodeIndex, SwFrmFmt* >::const_iterator const_iterator; + typedef std::pair< const_iterator, const_iterator > const_iterator_pair; + const_iterator_pair equal_range( const SwNodeIndex& pos ) const; + const_iterator lower_bound( const SwNodeIndex& pos ) const; + const_iterator upper_bound( const SwNodeIndex& pos ) const; + const_iterator end() const; +private: + std::multimap< SwNodeIndex, SwFrmFmt* > items; + const SwDoc* doc; +}; + #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |