diff options
author | Bjoern Michaelsen <bjoern.michaelsen@canonical.com> | 2014-12-01 19:53:31 +0100 |
---|---|---|
committer | Bjoern Michaelsen <bjoern.michaelsen@canonical.com> | 2014-12-02 00:37:12 +0100 |
commit | 7902e30aab21968648d53356d9d3533bbac17172 (patch) | |
tree | 5ddc1a8b2014ced76a2c33b0acf6a6721b038616 /sw/inc/ring.hxx | |
parent | 6172730c6465c02a925ed07fbce7add390c437fc (diff) |
move Ring to sw::Ring
Change-Id: I3109185f747b821ee94aae5c58f86768ca30713a
Diffstat (limited to 'sw/inc/ring.hxx')
-rw-r--r-- | sw/inc/ring.hxx | 205 |
1 files changed, 104 insertions, 101 deletions
diff --git a/sw/inc/ring.hxx b/sw/inc/ring.hxx index cef2eef51a95..d5eb30ba0377 100644 --- a/sw/inc/ring.hxx +++ b/sw/inc/ring.hxx @@ -24,122 +24,125 @@ #include <boost/iterator/iterator_facade.hpp> #include <boost/intrusive/circular_list_algorithms.hpp> -class Ring_node_traits; -template <class T> class RingIterator; - -template <class T> -class SW_DLLPUBLIC Ring +namespace sw { - struct Ring_node_traits - { - typedef T node; - typedef T* node_ptr; - typedef const T* 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; - T* pNext; - T* pPrev; ///< In order to speed up inserting and deleting. + class Ring_node_traits; + template <class T> class RingIterator; -protected: - Ring() - { algo::init_header(static_cast< T* >(this)); } - Ring( T* ); -public: - typedef RingIterator<T> iterator; - typedef RingIterator<T> const_iterator; - virtual ~Ring() - { algo::unlink(static_cast< T* >(this)); }; - void MoveTo( T* pDestRing ); - void MoveRingTo( T* pDestRing ); + template <class T> + class SW_DLLPUBLIC Ring + { + struct Ring_node_traits + { + typedef T node; + typedef T* node_ptr; + typedef const T* 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; + T* pNext; + T* pPrev; ///< In order to speed up inserting and deleting. - T* GetNext() const { return pNext; } - T* GetPrev() const { return pPrev; } - // unfortunately we cant name these STL-conforming, as some derived classes - // also derive from other STL containers (which is bad anyway, but ...) - iterator beginRing(); - iterator endRing(); + protected: + Ring() + { algo::init_header(static_cast< T* >(this)); } + Ring( T* ); + public: + typedef RingIterator<T> iterator; + typedef RingIterator<T> const_iterator; + virtual ~Ring() + { algo::unlink(static_cast< T* >(this)); }; + void MoveTo( T* pDestRing ); + void MoveRingTo( T* pDestRing ); - sal_uInt32 numberOf() const - { return algo::count(static_cast< const T* >(this)); } -}; + T* GetNext() const { return pNext; } + T* GetPrev() const { return pPrev; } + // unfortunately we cant name these STL-conforming, as some derived classes + // also derive from other STL containers (which is bad anyway, but ...) + iterator beginRing(); + iterator endRing(); -template <class T> -inline Ring<T>::Ring( T* pObj ) -{ - T* pThis = static_cast< T* >(this); - if( !pObj ) - algo::init_header(pThis); - else - algo::link_before(pObj, pThis); -} + sal_uInt32 numberOf() const + { return algo::count(static_cast< const T* >(this)); } + }; -template <class T> -inline void Ring<T>::MoveTo(T* pDestRing) -{ - T* pThis = static_cast< T* >(this); - // insert into "new" - if( pDestRing ) + template <class T> + inline Ring<T>::Ring( T* pObj ) { - if(algo::unique(pThis)) - algo::link_before(pDestRing, pThis); + T* pThis = static_cast< T* >(this); + if( !pObj ) + algo::init_header(pThis); else - algo::transfer(pDestRing, pThis); + algo::link_before(pObj, pThis); } - else - algo::unlink(pThis); -} - -template <class T> -inline void Ring<T>::MoveRingTo(T* pDestRing) -{ - std::swap(*(&pPrev->pNext), *(&pDestRing->pPrev->pNext)); - std::swap(*(&pPrev), *(&pDestRing->pPrev)); -} -template <class T> -class RingIterator : public boost::iterator_facade< - RingIterator<T> - , T - , boost::forward_traversal_tag - > -{ - public: - RingIterator() - : m_pCurrent(nullptr) - , m_pStart(nullptr) - {} - explicit RingIterator(T* pRing, bool bStart = true) - : m_pCurrent(nullptr) - , m_pStart(pRing) + template <class T> + inline void Ring<T>::MoveTo(T* pDestRing) + { + T* pThis = static_cast< T* >(this); + // insert into "new" + if( pDestRing ) { - if(!bStart) - m_pCurrent = m_pStart; + if(algo::unique(pThis)) + algo::link_before(pDestRing, pThis); + else + algo::transfer(pDestRing, pThis); } - private: - friend class boost::iterator_core_access; - void increment() - { m_pCurrent = m_pCurrent ? m_pCurrent->GetNext() : m_pStart->GetNext(); } - bool equal(RingIterator const& other) const - { return m_pCurrent == other.m_pCurrent && m_pStart == m_pStart; } - T& dereference() const - { return m_pCurrent ? *m_pCurrent : * m_pStart; } - T* m_pCurrent; - T* m_pStart; -}; + else + algo::unlink(pThis); + } -template <class T> -inline typename Ring<T>::iterator Ring<T>::beginRing() - { return Ring<T>::iterator(static_cast< T* >(this)); }; + template <class T> + inline void Ring<T>::MoveRingTo(T* pDestRing) + { + std::swap(*(&pPrev->pNext), *(&pDestRing->pPrev->pNext)); + std::swap(*(&pPrev), *(&pDestRing->pPrev)); + } + + template <class T> + class RingIterator : public boost::iterator_facade< + RingIterator<T> + , T + , boost::forward_traversal_tag + > + { + public: + RingIterator() + : m_pCurrent(nullptr) + , m_pStart(nullptr) + {} + explicit RingIterator(T* pRing, bool bStart = true) + : m_pCurrent(nullptr) + , m_pStart(pRing) + { + if(!bStart) + m_pCurrent = m_pStart; + } + private: + friend class boost::iterator_core_access; + void increment() + { m_pCurrent = m_pCurrent ? m_pCurrent->GetNext() : m_pStart->GetNext(); } + bool equal(RingIterator const& other) const + { return m_pCurrent == other.m_pCurrent && m_pStart == m_pStart; } + T& dereference() const + { return m_pCurrent ? *m_pCurrent : * m_pStart; } + T* m_pCurrent; + T* m_pStart; + }; + + template <class T> + inline typename Ring<T>::iterator Ring<T>::beginRing() + { return Ring<T>::iterator(static_cast< T* >(this)); }; -template <class T> -inline typename Ring<T>::iterator Ring<T>::endRing() - { return Ring<T>::iterator(static_cast< T* >(this), false); }; + template <class T> + inline typename Ring<T>::iterator Ring<T>::endRing() + { return Ring<T>::iterator(static_cast< T* >(this), false); }; +} #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |