namespace sw
{ template <typename value_type> class RingContainer; template <typename value_type> class RingIterator; /** *Anintrusivecontainerclassdoublelinkingthecontainednodes *@examplesw/qa/core/uwriter.cxx
*/ template <typename value_type> class SAL_WARN_UNUSED Ring
{ public: typedeftypename std::add_const<value_type>::type const_value_type; typedef RingContainer<value_type> ring_container; typedef RingContainer<const_value_type> const_ring_container; virtual ~Ring() COVERITY_NOEXCEPT_FALSE
{ unlink(); }; /** algo::unlink is buggy! don't call it directly! */ void unlink()
{
algo::unlink(this);
m_pNext = this; // don't leave pointers to old list behind!
m_pPrev = this;
} /** *Removesthisitemfromitscurrentringcontainerandaddsitto *anotherringcontainer.Iftheitemwasnotaloneintheoriginal *ringcontainer,theotheritemsintheringwillstayintheold *ringcontainer. *Note:thenewlycreateditemwillbeinsertedjustbeforeitempDestRing. *@parampDestRingthecontainertoaddthisitemto
*/ void MoveTo( value_type* pDestRing ); /** @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;
protected: /** *Createsanewiteminaringcontainerallbyitself. *Note:Ringinstancescannewerbeoutsideacontainer.Atmost,they *arealoneinone.
*/
Ring()
: m_pNext(this)
, m_pPrev(this)
{ } /** *Createsanewitemandaddittoanexistingringcontainer. *Note:thenewlycreateditemwillbeinsertedjustbeforeitempRing. *@parampRingringcontainertoaddthecreateditemto
*/
Ring( value_type* pRing ); /** @return the next item in the ring container */
value_type* GetNextInRing()
{ returnstatic_cast<value_type *>(m_pNext); } /** @return the previous item in the ring container */
value_type* GetPrevInRing()
{ returnstatic_cast<value_type *>(m_pPrev); } /** @return the next item in the ring container */
const_value_type* GetNextInRing() const
{ returnstatic_cast<value_type *>(m_pNext); } /** @return the previous item in the ring container */
const_value_type* GetPrevInRing() const
{ returnstatic_cast<value_type *>(m_pPrev); } /** @return true if and only if this item is alone in its ring */ bool unique() const
{ return algo::unique(static_cast< const_value_type* >(this)); }
/** *helperclassthatprovidesSTL-stylecontaineriterationtothering
*/ template <typename value_type> class SAL_WARN_UNUSED RingContainer final
{ private: /** the item in the ring where iteration starts */
value_type* m_pStart; typedeftypename std::remove_const<value_type>::type nonconst_value_type;
public:
RingContainer( value_type* pRing ) : m_pStart(pRing) {}; typedef RingIterator<value_type> iterator; typedef RingIterator<const value_type> const_iterator; /** *iteratoraccess *@code *for(SwPaM&rCurrentPaM:pPaM->GetRingContainer()) *do_stuff(rCurrentPaM);// this gets called on every SwPaM in the same ring as pPaM *@endcode
*/
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 std::distance(begin(), end()); } /** *Mergestworingcontainers.Allitemfrombothringcontainerswill *beinthesameringcontainerintheend. *Note:Theitemsofthisringcontainerwillbeinsertedjustbefore *itempDestRing *@parampDestRingthecontainertomergethiscontainerwith
*/ void merge( RingContainer< value_type > aDestRing )
{ // first check that we aren't merged already, swapping would // actually un-merge in this case!
assert(m_pStart->m_pPrev != aDestRing.m_pStart);
assert(m_pStart != aDestRing.m_pStart->m_pPrev);
std::swap(m_pStart->m_pPrev->m_pNext, aDestRing.m_pStart->m_pPrev->m_pNext);
std::swap(m_pStart->m_pPrev, aDestRing.m_pStart->m_pPrev);
}
};
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.