summaryrefslogtreecommitdiff
path: root/sw/inc/docary.hxx
diff options
context:
space:
mode:
authorJan-Marek Glogowski <glogow@fbihome.de>2015-04-10 21:32:36 +0200
committerJan-Marek Glogowski <glogow@fbihome.de>2016-08-29 13:13:14 +0200
commitd460ec312a5510955828be1ff35f92faef89e755 (patch)
treea962dbfd313dff57d91551ef907c0ea55c3228e7 /sw/inc/docary.hxx
parent9c3d9e9fb49318ceda69f060a8e847b15d679245 (diff)
Convert SwFrameFormats to boost::multi_index
This is almost the same situation as SwPageDescs. What makes this more complicated is the fact, that actually duplicated draw objects are allowed, in regard to the key values "type" and "name". And actually for some types, duplicate names are not allowed, e.g. SwDoc::FindFlyByName( const OUString& rName, sal_Int8 nNdTyp ) expects a single result! Change-Id: I6e0ea1099c1c1e6cfe90926170e27179722e88b8
Diffstat (limited to 'sw/inc/docary.hxx')
-rw-r--r--sw/inc/docary.hxx111
1 files changed, 110 insertions, 1 deletions
diff --git a/sw/inc/docary.hxx b/sw/inc/docary.hxx
index 6eff3f31effc..e4a0b263bfcf 100644
--- a/sw/inc/docary.hxx
+++ b/sw/inc/docary.hxx
@@ -25,6 +25,13 @@
#include <algorithm>
#include <o3tl/sorted_vector.hxx>
+#include <boost/multi_index_container.hpp>
+#include <boost/multi_index/composite_key.hpp>
+#include <boost/multi_index/identity.hpp>
+#include <boost/multi_index/mem_fun.hpp>
+#include <boost/multi_index/ordered_index.hpp>
+#include <boost/multi_index/random_access_index.hpp>
+
class SwRangeRedline;
class SwExtraRedline;
class SwUnoCursor;
@@ -46,6 +53,7 @@ namespace com { namespace sun { namespace star { namespace i18n {
#include <fldbas.hxx>
#include <tox.hxx>
#include <numrule.hxx>
+#include <frmfmt.hxx>
/** provides some methods for generic operations on lists that contain
SwFormat* subclasses. */
@@ -140,11 +148,112 @@ public:
SwGrfFormatColls() : SwFormatsModifyBase( DestructorPolicy::KeepElements ) {}
};
+namespace bmi = boost::multi_index;
+
+// Like o3tl::find_partialorder_ptrequals
+// We don't allow duplicated object entries!
+struct type_name_key:bmi::composite_key<
+ SwFrameFormat*,
+ bmi::const_mem_fun<SwFormat,sal_uInt16,&SwFormat::Which>,
+ bmi::const_mem_fun<SwFormat,const OUString&,&SwFormat::GetName>,
+ bmi::identity<SwFrameFormat*> // the actual object pointer
+>{};
+
+typedef boost::multi_index_container<
+ SwFrameFormat*,
+ bmi::indexed_by<
+ bmi::random_access<>,
+ bmi::ordered_unique< type_name_key >
+ >
+ >
+ SwFrameFormatsBase;
+
/// Specific frame formats (frames, DrawObjects).
-class SW_DLLPUBLIC SwFrameFormats : public SwFormatsModifyBase<SwFrameFormat*>
+class SW_DLLPUBLIC SwFrameFormats : public SwFrameFormatsBase, public SwFormatsBase
{
+ // function updating ByName index via modify
+ friend void SwFrameFormat::SetName( const OUString&, bool );
+
+ typedef nth_index<0>::type ByPos;
+ typedef nth_index<1>::type ByTypeAndName;
+ typedef ByPos::iterator iterator;
+
+ using ByPos::modify;
+
public:
+ typedef ByPos::const_iterator const_iterator;
+ typedef ByTypeAndName::const_iterator const_range_iterator;
+ typedef SwFrameFormatsBase::size_type size_type;
+ typedef SwFrameFormatsBase::value_type value_type;
+
+ // frees all SwFrameFormat!
+ virtual ~SwFrameFormats();
+
+ using SwFrameFormatsBase::clear;
+ using SwFrameFormatsBase::empty;
+ using SwFrameFormatsBase::size;
+
+ // Only fails, if you try to insert the same object twice
+ std::pair<const_iterator,bool> push_back( const value_type& x );
+
+ // This will try to remove the exact object!
+ bool erase( const value_type& x );
+ void erase( size_type index );
+ void erase( const_iterator const& position );
+
+ // Get the iterator of the exact object (includes pointer!),
+ // e.g for position with std::distance.
+ // There is also Contains, if you don't need the position.
+ const_iterator find( const value_type& x ) const;
+
+ // As this array is non-unique related to type and name,
+ // we always get ranges for the "key" values.
+ std::pair<const_range_iterator,const_range_iterator>
+ rangeFind( sal_uInt16 type, const OUString& name ) const;
+ // Convenience function, which just uses type and name!
+ // To look for the exact object use find.
+ std::pair<const_range_iterator,const_range_iterator>
+ rangeFind( const value_type& x ) const;
+ // So we can actually check for end()
+ const_range_iterator rangeEnd() const { return ByTypeAndName::end(); }
+ inline const_iterator rangeProject( const_range_iterator const& position )
+ { return project<0>( position ); }
+
+ const value_type& operator[]( size_t index_ ) const
+ { return ByPos::operator[]( index_ ); }
+ const value_type& front() const { return ByPos::front(); }
+ const value_type& back() const { return ByPos::back(); }
+ const_iterator begin() const { return ByPos::begin(); }
+ const_iterator end() const { return ByPos::end(); }
+
void dumpAsXml(struct _xmlTextWriter* pWriter, const char* pName) const;
+
+ virtual size_t GetFormatCount() const { return size(); }
+ virtual SwFormat* GetFormat(size_t idx) const { return operator[]( idx ); }
+
+ bool Contains( const value_type& x ) const;
+ inline bool Contains( const SwFormat* p ) const;
+
+ void DeleteAndDestroy( int aStartIdx, int aEndIdx );
+ void DeleteAndDestroyAll( bool keepDefault = false );
+
+ size_t GetPos( const value_type& x ) const;
+
+ bool newDefault( const value_type& x );
+ void newDefault( const_iterator const& position );
+};
+
+inline bool SwFrameFormats::Contains( const SwFormat* p ) const
+{
+ value_type p2 = dynamic_cast<value_type>(const_cast<SwFormat*>( p ));
+ return p2 != nullptr && this->Contains( p2 );
+}
+
+/// Unsorted, undeleting SwFrameFormat vector
+class SwFrameFormatsV : public SwFormatsModifyBase<SwFrameFormat*>
+{
+public:
+ SwFrameFormatsV() : SwFormatsModifyBase( DestructorPolicy::KeepElements ) {}
};
class SwCharFormats : public SwFormatsModifyBase<SwCharFormat*>