Kaydet (Commit) 7902e30a authored tarafından Bjoern Michaelsen's avatar Bjoern Michaelsen

move Ring to sw::Ring

Change-Id: I3109185f747b821ee94aae5c58f86768ca30713a
üst 6172730c
......@@ -155,7 +155,7 @@ void _InitPam();
class SwPaM;
/// PaM is Point and Mark: a selection of the document model.
class SW_DLLPUBLIC SwPaM : public Ring<SwPaM>
class SW_DLLPUBLIC SwPaM : public sw::Ring<SwPaM>
{
SwPosition m_Bound1;
SwPosition m_Bound2;
......
......@@ -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: */
......@@ -95,7 +95,7 @@ enum FrameControlType
typedef boost::shared_ptr<SwRootFrm> SwRootFrmPtr;
class SwViewShell;
class SW_DLLPUBLIC SwViewShell : public Ring<SwViewShell>
class SW_DLLPUBLIC SwViewShell : public sw::Ring<SwViewShell>
{
friend void SetOutDev( SwViewShell *pSh, OutputDevice *pOut );
friend void SetOutDevAndWin( SwViewShell *pSh, OutputDevice *pOut,
......
......@@ -1275,9 +1275,9 @@ void SwDocTest::testMarkMove()
namespace
{
struct TestRing : public Ring<TestRing>
struct TestRing : public sw::Ring<TestRing>
{
TestRing() : Ring<TestRing>() {};
TestRing() : sw::Ring<TestRing>() {};
void debug()
{
SAL_DEBUG("TestRing at: " << this << " prev: " << GetPrev() << " next: " << GetNext());
......
......@@ -1828,7 +1828,7 @@ long SwDoc::CompareDoc( const SwDoc& rDoc )
}
class _SaveMergeRedlines;
class _SaveMergeRedlines : public Ring<_SaveMergeRedlines>
class _SaveMergeRedlines : public sw::Ring<_SaveMergeRedlines>
{
const SwRangeRedline* pSrcRedl;
SwRangeRedline* pDestRedl;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment