summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan-Marek Glogowski <glogow@fbihome.de>2014-06-08 19:41:53 +0200
committerJan-Marek Glogowski <glogow@fbihome.de>2014-09-30 09:56:40 +0200
commita26a516143762b4d6b53e05054f8725d8d9283a0 (patch)
tree6ab1503a0eb7bbcdb4cbf4e61f6e740440940f03
parentafb2ea42e413ce328fd6bd06d0d3f3d8816c5887 (diff)
Convert SwFrmFmts to a o3tl::sorted_vector
(cherry picked from commit ec88c524a764b89c034d9347926ba903d6a24402) Conflicts: sw/qa/extras/ooxmlexport/ooxmlexport.cxx Change-Id: I6ca87d3dd9a3b7067380bb7ebaef306b87516dfb
-rw-r--r--include/o3tl/sorted_vector.hxx11
-rw-r--r--sw/inc/calbck.hxx2
-rw-r--r--sw/inc/docary.hxx38
-rw-r--r--sw/source/core/doc/docfmt.cxx95
-rw-r--r--sw/source/core/layout/atrfrm.cxx8
5 files changed, 78 insertions, 76 deletions
diff --git a/include/o3tl/sorted_vector.hxx b/include/o3tl/sorted_vector.hxx
index 551a06d6bc68..98c6cf113ad2 100644
--- a/include/o3tl/sorted_vector.hxx
+++ b/include/o3tl/sorted_vector.hxx
@@ -77,6 +77,7 @@ public:
using base_t::clear;
using base_t::empty;
using base_t::size;
+ using base_t::reserve;
sorted_vector( bool FirstDefault=false )
{
@@ -219,6 +220,16 @@ public:
std::stable_sort(begin_nonconst() + mOffset, end_nonconst(), Compare());
}
+ void newDefault( const_iterator const& position )
+ {
+ if ( !mOffset || position == begin() || position == end() )
+ return;
+ value_type tmp = front();
+ base_t::operator[]( 0 ) = *position;
+ erase( position );
+ insert( tmp );
+ }
+
private:
typename base_t::iterator begin_nonconst() { return base_t::begin(); }
diff --git a/sw/inc/calbck.hxx b/sw/inc/calbck.hxx
index 105ba9dd4aec..c2267c3f73b5 100644
--- a/sw/inc/calbck.hxx
+++ b/sw/inc/calbck.hxx
@@ -100,7 +100,7 @@ public:
// controlled access to Modify method
// mba: this is still considered a hack and it should be fixed; the name makes grep-ing easier
void ModifyNotification( const SfxPoolItem *pOldValue, const SfxPoolItem *pNewValue ) { Modify ( pOldValue, pNewValue ); }
- void SwClientNotifyCall( const SwModify& rModify, const SfxHint& rHint ) { SwClientNotify( rModify, rHint ); }
+ void SwClientNotifyCall( const SwModify& rModify, const SfxHint& rHint ) { SwClientNotify( rModify, rHint ); }
const SwModify* GetRegisteredIn() const { return pRegisteredIn; }
bool IsLast() const { return !pLeft && !pRight; }
diff --git a/sw/inc/docary.hxx b/sw/inc/docary.hxx
index ebb85d402d5b..5035528d8e57 100644
--- a/sw/inc/docary.hxx
+++ b/sw/inc/docary.hxx
@@ -99,42 +99,38 @@ public:
virtual ~SwGrfFmtColls() {}
};
-typedef std::vector<SwFrmFmt*> SwFrmFmtsBase;
+struct CompareSwFrmFmts
+{
+ bool operator()(SwFrmFmt* const& lhs, SwFrmFmt* const& rhs) const;
+};
+
+typedef o3tl::sorted_vector<SwFrmFmt*, CompareSwFrmFmts,
+ o3tl::find_partialorder_ptrequals> SwFrmFmtsBase;
/// Specific frame formats (frames, DrawObjects).
/// Mimics o3tl::sorted_vector interface
-class SW_DLLPUBLIC SwFrmFmts : private SwFrmFmtsBase, public SwFmtsBase
+class SW_DLLPUBLIC SwFrmFmts : public SwFrmFmtsBase, public SwFmtsBase
{
public:
typedef SwFrmFmtsBase::const_iterator const_iterator;
typedef SwFrmFmtsBase::size_type size_type;
typedef SwFrmFmtsBase::value_type value_type;
- typedef std::pair<const_iterator,bool> find_insert_type;
+ typedef SwFrmFmtsBase::find_insert_type find_insert_type;
- virtual ~SwFrmFmts();
-
- void DeleteAndDestroyAll( bool offset = false );
+private:
+ find_insert_type insert( const value_type& x, bool isNewRoot );
- using SwFrmFmtsBase::clear;
- using SwFrmFmtsBase::empty;
- using SwFrmFmtsBase::reserve;
- using SwFrmFmtsBase::size;
+public:
+ SwFrmFmts();
+ virtual ~SwFrmFmts();
find_insert_type insert( const value_type& x );
size_type erase( const value_type& x );
void erase( size_type index );
void erase( const_iterator const& position );
- const value_type& front() const { return SwFrmFmtsBase::front(); }
- const value_type& back() const { return SwFrmFmtsBase::back(); }
- const value_type& operator[]( size_t index ) const
- { return SwFrmFmtsBase::operator[]( index ); }
-
const_iterator find( const value_type& x ) const;
- const_iterator begin() const { return SwFrmFmtsBase::begin(); }
- const_iterator end() const { return SwFrmFmtsBase::end(); }
-
bool Contains( const value_type& x ) const;
virtual size_t GetFmtCount() const SAL_OVERRIDE
@@ -145,12 +141,6 @@ public:
void dumpAsXml(xmlTextWriterPtr w, const char* pName);
bool newDefault( const value_type& x );
-
-private:
- typedef SwFrmFmtsBase::iterator iterator;
- iterator begin_nonconst() { return SwFrmFmtsBase::begin(); }
- iterator end_nonconst() { return SwFrmFmtsBase::end(); }
- void newDefault( const_iterator const& position );
};
/// Unsorted, undeleting SwFrmFmt vector
diff --git a/sw/source/core/doc/docfmt.cxx b/sw/source/core/doc/docfmt.cxx
index 64b554237938..5b64c86c4e8e 100644
--- a/sw/source/core/doc/docfmt.cxx
+++ b/sw/source/core/doc/docfmt.cxx
@@ -2653,87 +2653,88 @@ namespace docfunc
}
}
+SwFrmFmts::SwFrmFmts() : SwFrmFmtsBase( true )
+{
+}
+
SwFrmFmts::~SwFrmFmts()
{
DeleteAndDestroyAll();
}
-void SwFrmFmts::DeleteAndDestroyAll( bool keepDefault )
+SwFrmFmts::const_iterator SwFrmFmts::find( const value_type& x ) const
{
- if ( empty() )
- return;
- const int _offset = keepDefault ? 1 : 0;
- for( const_iterator it = begin() + _offset; it != end(); ++it )
- delete *it;
- if ( _offset )
- SwFrmFmtsBase::erase( begin_nonconst() + _offset, end_nonconst() );
- else
- clear();
+ return SwFrmFmtsBase::find( x );
}
-SwFrmFmts::find_insert_type SwFrmFmts::insert( const value_type& x )
+bool CompareSwFrmFmts::operator()(SwFrmFmt* const& lhs, SwFrmFmt* const& rhs) const
{
- SwFrmFmtsBase::push_back( x );
- SAL_WARN_IF(x->list != 0, "sw", "Inserting already assigned item");
+ if (lhs->Which() < rhs->Which())
+ return true;
+ if (lhs->Which() > rhs->Which())
+ return false;
+ return (lhs->GetName().CompareTo( rhs->GetName() ) < 0);
+}
+
+SwFrmFmts::find_insert_type SwFrmFmts::insert( const value_type& x, bool isNewRoot )
+{
+ find_insert_type ret = SwFrmFmtsBase::insert( x );
+ SAL_WARN_IF(x->list != 0, "sw", "Inserting already assigned SwFrmFmt");
+ SAL_WARN_IF(isNewRoot == ret.second, "sw", "Error condition in insert SwFrmFmt");
x->list = this;
- return std::make_pair(end() - 1 , true);
+ return ret;
+}
+
+std::pair<SwFrmFmts::const_iterator,bool> SwFrmFmts::insert( const value_type& x )
+{
+ return insert( x, false );
}
SwFrmFmts::size_type SwFrmFmts::erase( const value_type& x )
{
- const_iterator const ret = find( x );
- SAL_WARN_IF(x->list != this, "sw", "Removing invalid / unassigned item");
- if (ret != end()) {
- SwFrmFmtsBase::erase( begin_nonconst() + (ret - begin()) );
+ size_type ret = SwFrmFmtsBase::erase( x );
+ if (ret) {
+ SAL_WARN_IF(x->list != this, "sw", "Removed invalid / unassigned SwFrmFmt");
x->list = 0;
- return 1;
}
- return 0;
+ return ret;
}
void SwFrmFmts::erase( size_type index )
{
- erase( begin_nonconst() + index );
+ erase( begin() + index );
}
void SwFrmFmts::erase( const_iterator const& position )
{
+ SAL_WARN_IF((*position)->list != this, "sw", "Removing invalid / unassigned SwFrmFmt");
(*position)->list = 0;
- SwFrmFmtsBase::erase( begin_nonconst() + (position - begin()) );
+ SwFrmFmtsBase::erase( position );
}
-
-SwFrmFmts::const_iterator SwFrmFmts::find( const value_type& x ) const
+/*
+std::pair<SwFrmFmts::const_iterator, SwFrmFmts::const_iterator>
+ SwFrmFmts::find( const value_type& x, bool &root ) const
{
- return std::find( begin(), end(), x );
+ if ( emptry() ) {
+ root = false;
+ return std::pair<const_iterator, const_iterator>( end(), end() );
+ }
+ std::pair<const_iterator, const_iterator> const its =
+ std::equal_range(begin(), end(), x, CompareSwFrmFmts());
+ root = CompareSwPageDescs()(x, front());
+ return its;
}
-
-bool SwFrmFmts::Contains( const SwFrmFmts::value_type& x ) const
+*/
+bool SwFrmFmts::Contains( const value_type& x ) const
{
return (x->list == this);
}
bool SwFrmFmts::newDefault( const value_type& x )
{
- bool inserted = false;
- const_iterator it = find( x );
- if (it == end()) {
- push_back( x );
- it = end() - 1;
- inserted = true;
- }
- newDefault( it );
- return inserted;
-}
-
-void SwFrmFmts::newDefault( const_iterator const& position )
-{
- if (position == begin())
- return;
- SwFrmFmt *tmp;
- tmp = front();
- erase( position );
- SwFrmFmtsBase::operator[]( 0 ) = *position;
- insert( tmp );
+ find_insert_type ret = insert( x, true );
+ SwFrmFmtsBase::newDefault( ret.first );
+ return ret.second;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/layout/atrfrm.cxx b/sw/source/core/layout/atrfrm.cxx
index d02976c5111c..365632eb6719 100644
--- a/sw/source/core/layout/atrfrm.cxx
+++ b/sw/source/core/layout/atrfrm.cxx
@@ -2416,10 +2416,10 @@ void SwFrmFmt::SetName( const String& rNewName, sal_Bool bBroadcast )
SwFrmFmts::const_iterator it;
bool move_entry = false;
- if (list) {
- it = list->find( this );
- SAL_WARN_IF( list->end() == it, "sw", "SwFrmFmt not found in expected list" );
-// move_entry = (it != list->begin());
+ if (_list) {
+ it = _list->find( this );
+ SAL_WARN_IF( _list->end() == it, "sw", "SwFrmFmt not found in expected list" );
+ move_entry = (it != list->begin());
if (move_entry)
// Clears list
list->erase( it );