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

move container stuff out of sw::Ring<>

Change-Id: Idf72c16318735d6b3ef7f421aceacc225a7697bf
üst 1801b559
...@@ -31,7 +31,7 @@ class SwNodeIndex; ...@@ -31,7 +31,7 @@ class SwNodeIndex;
#define PCURCRSR (static_cast<SwPaM *>(&__r)) #define PCURCRSR (static_cast<SwPaM *>(&__r))
#define FOREACHPAM_START(pCURSH) \ #define FOREACHPAM_START(pCURSH) \
BOOST_FOREACH(SwPaM& __r, (pCURSH)->rangeRing()) \ for(SwPaM& __r : (pCURSH)->GetRingContainer()) \
{ {
#define FOREACHPAM_END() } #define FOREACHPAM_END() }
......
...@@ -27,9 +27,7 @@ ...@@ -27,9 +27,7 @@
namespace sw namespace sw
{ {
class Ring_node_traits; template <class T> class RingContainer;
template <class T> class RingIterator;
/** /**
* An intrusive container class double linking the contained nodes * An intrusive container class double linking the contained nodes
* @example sw/qa/core/uwriter.cxx * @example sw/qa/core/uwriter.cxx
...@@ -68,8 +66,8 @@ namespace sw ...@@ -68,8 +66,8 @@ namespace sw
*/ */
Ring( T* pRing ); Ring( T* pRing );
public: public:
typedef RingIterator<T> iterator; typedef RingContainer<T> ring_container;
typedef RingIterator<const T> const_iterator; typedef RingContainer<const T> const_ring_container;
virtual ~Ring() virtual ~Ring()
{ algo::unlink(static_cast< T* >(this)); }; { algo::unlink(static_cast< T* >(this)); };
/** /**
...@@ -96,36 +94,13 @@ namespace sw ...@@ -96,36 +94,13 @@ namespace sw
/** @return the previous item in the ring container */ /** @return the previous item in the ring container */
T* GetPrev() const T* GetPrev() const
{ return pPrev; } { return pPrev; }
/**
* iterator access
* @code
* for(Ring<SwPaM>::iterator ppRing = pPaM->beginRing(); ppRing != pPaM->endRing(); ++ppRing)
* do_stuff(*ppRing);
* @endcode
* @TODO: unfortunately we cant name these STL-conforming, as some derived classes
* also derive from other STL containers. This should be fixed though.
* That should allow this to be used directly with C++11s for( : )
* iteration statement.
*/
iterator beginRing();
iterator endRing();
const_iterator beginRing() const;
const_iterator endRing() const;
/**
* simplified iteration with BOOST_FOREACH (example for Ring<SwPaM>):
* @code
* BOOST_FOREACH(SwPaM& rPaM, pPaM->rangeRing())
* do_stuff(rPaM);
* @endcode
*/
std::pair<iterator, iterator> rangeRing()
{ return std::make_pair(beginRing(), endRing()); }
std::pair<const_iterator, const_iterator> rangeRing() const
{ return std::make_pair(beginRing(), endRing()); }
/** @return the number of elements in the container */ /** @return the number of elements in the container */
size_t size() const size_t size() const
{ return algo::count(static_cast< const T* >(this)); } { return algo::count(static_cast< const T* >(this)); }
/** @return a stl-like container with begin()/end() for iteration */
ring_container GetRingContainer();
/** @return a stl-like container with begin()/end() for const iteration */
const_ring_container GetRingContainer() const;
}; };
template <class T> template <class T>
...@@ -161,8 +136,37 @@ namespace sw ...@@ -161,8 +136,37 @@ namespace sw
std::swap(*(&pPrev), *(&pDestRing->pPrev)); std::swap(*(&pPrev), *(&pDestRing->pPrev));
} }
template <class T> class RingIterator;
template <class T> template <class T>
class RingIterator : public boost::iterator_facade< class RingContainer SAL_FINAL
{
T* m_pStart;
public:
RingContainer( T* pRing ) : m_pStart(pRing) {};
typedef RingIterator<T> iterator;
typedef RingIterator<const T> const_iterator;
/**
* iterator access
* @code
* for(Ring<SwPaM>::iterator ppRing = pPaM->beginRing(); ppRing != pPaM->endRing(); ++ppRing)
* do_stuff(*ppRing);
* @endcode
* @TODO: unfortunately we cant name these STL-conforming, as some derived classes
* also derive from other STL containers. This should be fixed though.
* That should allow this to be used directly with C++11s for( : )
* iteration statement.
*/
iterator begin();
iterator end();
const_iterator begin() const;
const_iterator end() const;
///** @return the number of elements in the container */
//size_t size() const
// { return algo::count(static_cast< const T* >(this)); }
};
template <class T>
class RingIterator SAL_FINAL : public boost::iterator_facade<
RingIterator<T> RingIterator<T>
, T , T
, boost::forward_traversal_tag , boost::forward_traversal_tag
...@@ -193,20 +197,28 @@ namespace sw ...@@ -193,20 +197,28 @@ namespace sw
}; };
template <class T> template <class T>
inline typename Ring<T>::iterator Ring<T>::beginRing() inline typename Ring<T>::ring_container Ring<T>::GetRingContainer()
{ return Ring<T>::iterator(static_cast< T* >(this)); }; { return Ring<T>::ring_container(static_cast< T* >(this)); };
template <class T>
inline typename Ring<T>::const_ring_container Ring<T>::GetRingContainer() const
{ return Ring<T>::const_ring_container(static_cast< const T* >(this)); };
template <class T>
inline typename RingContainer<T>::iterator RingContainer<T>::begin()
{ return RingContainer<T>::iterator(m_pStart); };
template <class T> template <class T>
inline typename Ring<T>::iterator Ring<T>::endRing() inline typename RingContainer<T>::iterator RingContainer<T>::end()
{ return Ring<T>::iterator(static_cast< T* >(this), false); }; { return RingContainer<T>::iterator(m_pStart, false); };
template <class T> template <class T>
inline typename Ring<T>::const_iterator Ring<T>::beginRing() const inline typename RingContainer<T>::const_iterator RingContainer<T>::begin() const
{ return Ring<T>::const_iterator(static_cast< const T* >(this)); }; { return RingContainer<T>::const_iterator(m_pStart); };
template <class T> template <class T>
inline typename Ring<T>::const_iterator Ring<T>::endRing() const inline typename RingContainer<T>::const_iterator RingContainer<T>::end() const
{ return Ring<T>::const_iterator(static_cast< const T* >(this), false); }; { return RingContainer<T>::const_iterator(m_pStart, false); };
} }
#endif #endif
......
...@@ -1317,14 +1317,14 @@ void SwDocTest::testIntrusiveRing() ...@@ -1317,14 +1317,14 @@ void SwDocTest::testIntrusiveRing()
CPPUNIT_ASSERT_EQUAL((*ppRing)->GetNext(), *ppNext); CPPUNIT_ASSERT_EQUAL((*ppRing)->GetNext(), *ppNext);
CPPUNIT_ASSERT_EQUAL((*ppNext)->GetPrev(), *ppRing); CPPUNIT_ASSERT_EQUAL((*ppNext)->GetPrev(), *ppRing);
} }
BOOST_FOREACH(TestRing& r, aRing1.rangeRing()) for(TestRing& r: aRing1.GetRingContainer())
{ {
TestRing* pRing = &r; TestRing* pRing = &r;
CPPUNIT_ASSERT(pRing); CPPUNIT_ASSERT(pRing);
//pRing->debug(); //pRing->debug();
} }
const TestRing* pConstRing = &aRing1; const TestRing* pConstRing = &aRing1;
BOOST_FOREACH(const TestRing& r, pConstRing->rangeRing()) // this should fail without r being const for(const TestRing& r: pConstRing->GetRingContainer()) // this should fail without r being const
{ {
const TestRing* pRing = &r; const TestRing* pRing = &r;
CPPUNIT_ASSERT(pRing); CPPUNIT_ASSERT(pRing);
......
...@@ -99,7 +99,7 @@ void PaMCorrAbs( const SwPaM& rRange, ...@@ -99,7 +99,7 @@ void PaMCorrAbs( const SwPaM& rRange,
if( pShell ) if( pShell )
{ {
BOOST_FOREACH(const SwViewShell& rShell, pShell->rangeRing()) for(const SwViewShell& rShell : pShell->GetRingContainer())
{ {
if(!rShell.IsA( TYPE( SwCrsrShell ))) if(!rShell.IsA( TYPE( SwCrsrShell )))
continue; continue;
...@@ -249,7 +249,7 @@ void PaMCorrRel( const SwNodeIndex &rOldNode, ...@@ -249,7 +249,7 @@ void PaMCorrRel( const SwNodeIndex &rOldNode,
SwCrsrShell const* pShell = pDoc->GetEditShell(); SwCrsrShell const* pShell = pDoc->GetEditShell();
if( pShell ) if( pShell )
{ {
BOOST_FOREACH(const SwViewShell& rShell, pShell->rangeRing()) for(const SwViewShell& rShell : pShell->GetRingContainer())
{ {
if(!rShell.IsA( TYPE( SwCrsrShell ))) if(!rShell.IsA( TYPE( SwCrsrShell )))
continue; continue;
...@@ -262,7 +262,7 @@ void PaMCorrRel( const SwNodeIndex &rOldNode, ...@@ -262,7 +262,7 @@ void PaMCorrRel( const SwNodeIndex &rOldNode,
((_pStkCrsr = static_cast<SwPaM *>(_pStkCrsr->GetNext())) != pCrsrShell->GetStkCrsr()) ); ((_pStkCrsr = static_cast<SwPaM *>(_pStkCrsr->GetNext())) != pCrsrShell->GetStkCrsr()) );
SwPaM* pStartPaM = pCrsrShell->_GetCrsr(); SwPaM* pStartPaM = pCrsrShell->_GetCrsr();
BOOST_FOREACH(SwPaM& rPaM, pStartPaM->rangeRing()) for(SwPaM& rPaM : pStartPaM->GetRingContainer())
{ {
lcl_PaMCorrRel1( &rPaM, pOldNode, aNewPos, nCntIdx); lcl_PaMCorrRel1( &rPaM, pOldNode, aNewPos, nCntIdx);
} }
......
...@@ -2538,7 +2538,7 @@ void SwEditShell::AutoFormat( const SvxSwAutoFmtFlags* pAFlags ) ...@@ -2538,7 +2538,7 @@ void SwEditShell::AutoFormat( const SvxSwAutoFmtFlags* pAFlags )
// There are more than one or a selection is open // There are more than one or a selection is open
if( pCrsr->GetNext() != pCrsr || pCrsr->HasMark() ) if( pCrsr->GetNext() != pCrsr || pCrsr->HasMark() )
{ {
BOOST_FOREACH(SwPaM& rPaM, GetCrsr()->rangeRing()) for(SwPaM& rPaM : GetCrsr()->GetRingContainer())
{ {
if( rPaM.HasMark() ) if( rPaM.HasMark() )
{ {
......
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