summaryrefslogtreecommitdiff
path: root/sw/inc/ring.hxx
diff options
context:
space:
mode:
authorBjoern Michaelsen <bjoern.michaelsen@canonical.com>2014-12-01 16:40:54 +0100
committerBjoern Michaelsen <bjoern.michaelsen@canonical.com>2014-12-02 00:33:21 +0100
commitef5051b59270b324968cb91304fb25f622b80329 (patch)
treef5006a3c012a6d476761d6d5df2c039f223dea14 /sw/inc/ring.hxx
parent02e2e6df7f089b121bc3599c8e267ffa7f9e46fb (diff)
make ring header only
Change-Id: If8a52d12cb145120be4477ee79f8cdc55329c36c
Diffstat (limited to 'sw/inc/ring.hxx')
-rw-r--r--sw/inc/ring.hxx52
1 files changed, 47 insertions, 5 deletions
diff --git a/sw/inc/ring.hxx b/sw/inc/ring.hxx
index 4dc03308bdfe..90e3465e8065 100644
--- a/sw/inc/ring.hxx
+++ b/sw/inc/ring.hxx
@@ -22,23 +22,37 @@
#include <swdllapi.h>
#include <swtypes.hxx>
#include <boost/iterator/iterator_facade.hpp>
+#include <boost/intrusive/circular_list_algorithms.hpp>
class Ring_node_traits;
class RingIterator;
class SW_DLLPUBLIC Ring
{
+ struct Ring_node_traits
+ {
+ typedef Ring node;
+ typedef Ring* node_ptr;
+ typedef const Ring* const_node_ptr;
+ static node_ptr get_next(const_node_ptr n) { return n->GetNext(); };
+ static void set_next(node_ptr n, node_ptr next) { n->pNext = next; };
+ static node_ptr get_previous(const_node_ptr n) { return n->GetPrev(); };
+ static void set_previous(node_ptr n, node_ptr previous) { n->pPrev = previous; };
+ };
friend class Ring_node_traits;
+ typedef boost::intrusive::circular_list_algorithms<Ring_node_traits> algo;
Ring* pNext;
Ring* pPrev; ///< In order to speed up inserting and deleting.
protected:
- Ring();
+ Ring()
+ { algo::init_header(this); }
Ring( Ring * );
public:
typedef RingIterator iterator;
typedef RingIterator const_iterator;
- virtual ~Ring();
+ virtual ~Ring()
+ { algo::unlink(this); };
void MoveTo( Ring *pDestRing );
void MoveRingTo( Ring *pDestRing );
@@ -49,9 +63,39 @@ public:
iterator beginRing();
iterator endRing();
- sal_uInt32 numberOf() const;
+ sal_uInt32 numberOf() const
+ { return algo::count(this); }
};
+inline Ring::Ring( Ring *pObj )
+{
+ if( !pObj )
+ algo::init_header(this);
+ else
+ algo::link_before(pObj, this);
+}
+
+inline void Ring::MoveTo(Ring *pDestRing)
+{
+ // insert into "new"
+ if( pDestRing )
+ {
+ if(algo::unique(this))
+ algo::link_before(pDestRing, this);
+ else
+ algo::transfer(pDestRing, this);
+ }
+ else
+ algo::unlink(this);
+
+}
+
+inline void Ring::MoveRingTo(Ring *pDestRing)
+{
+ std::swap(*(&pPrev->pNext), *(&pDestRing->pPrev->pNext));
+ std::swap(*(&pPrev), *(&pDestRing->pPrev));
+}
+
class RingIterator : public boost::iterator_facade<
RingIterator
, Ring
@@ -88,8 +132,6 @@ inline Ring::iterator Ring::beginRing()
inline Ring::iterator Ring::endRing()
{ return Ring::iterator(this, false); };
-
-
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */