From e33513df23f984db5f4b687157c39c684d77b581 Mon Sep 17 00:00:00 2001 From: ptv Date: Fri, 11 Nov 2005 11:39:40 +0000 Subject: [PATCH] improve DataOwnerList to append only non equal owners if additional flag is set --- src/SUIT/SUIT_DataOwner.cxx | 56 +++++++++++++++++++++++++++++++++---- src/SUIT/SUIT_DataOwner.h | 5 ++++ 2 files changed, 55 insertions(+), 6 deletions(-) diff --git a/src/SUIT/SUIT_DataOwner.cxx b/src/SUIT/SUIT_DataOwner.cxx index 3a85389bc..401b763df 100755 --- a/src/SUIT/SUIT_DataOwner.cxx +++ b/src/SUIT/SUIT_DataOwner.cxx @@ -46,6 +46,15 @@ SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList() { } +//==================================================================== +//! Constructor (default) +//==================================================================== +SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList( const bool skipAllEqal ) +: QValueList(), +mySkipEqual( skipAllEqal ) +{ +} + //==================================================================== //! Constructor (copy) //==================================================================== @@ -54,6 +63,24 @@ SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList( const SUIT_DataOwnerPtrList& l ) { } +//==================================================================== +//! Constructor (copy) +//==================================================================== +SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList( const SUIT_DataOwnerPtrList& l, const bool skipAllEqal ) +: QValueList(), +mySkipEqual( skipAllEqal ) +{ + if ( skipAllEqal == l.mySkipEqual ) + operator =( l ); + else + { + SUIT_DataOwnerPtrList::const_iterator beginIt = l.begin(); + SUIT_DataOwnerPtrList::const_iterator endIt = l.end(); + for( ; beginIt != endIt; ++beginIt ) + append( *beginIt ); + } +} + #ifndef QT_NO_STL //==================================================================== //! Constructor (from stl) @@ -64,6 +91,21 @@ SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList( const std::list } #endif +#ifndef QT_NO_STL +//==================================================================== +//! Constructor (from stl) +//==================================================================== +SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList( const std::list& l, const bool skipAllEqal ) +: QValueList(), +mySkipEqual( skipAllEqal ) +{ + std::list::const_iterator beginIt = l.begin(); + std::list::const_iterator endIt = l.begin(); + for( ; beginIt != endIt; ++beginIt ) + append( *beginIt ); +} +#endif + //==================================================================== //! Appends an item to the list //==================================================================== @@ -71,12 +113,14 @@ SUIT_DataOwnerPtrList::iterator SUIT_DataOwnerPtrList::append( const SUIT_DataOw { SUIT_DataOwnerPtrList::iterator it = find( x ); if ( it != end() ) - { - const _typeinfo& ti1 = typeid( *((*it).operator->()) ); - const _typeinfo& ti2 = typeid( *(x.operator->()) ); + { + if ( mySkipEqual ) + return it; + const _typeinfo& ti1 = typeid( *((*it).operator->()) ); + const _typeinfo& ti2 = typeid( *(x.operator->()) ); - if (ti1 == ti2) - return it; - } + if (ti1 == ti2) + return it; + } return QValueList::append( x ); } diff --git a/src/SUIT/SUIT_DataOwner.h b/src/SUIT/SUIT_DataOwner.h index faa0f283e..c78679e75 100755 --- a/src/SUIT/SUIT_DataOwner.h +++ b/src/SUIT/SUIT_DataOwner.h @@ -37,9 +37,12 @@ class SUIT_EXPORT SUIT_DataOwnerPtrList : public QValueList { public: SUIT_DataOwnerPtrList();//!< constructor + SUIT_DataOwnerPtrList( const bool skipAllEqal );//!< constructor SUIT_DataOwnerPtrList( const SUIT_DataOwnerPtrList& l );//!< copy constructor + SUIT_DataOwnerPtrList( const SUIT_DataOwnerPtrList& l, const bool skipAllEqal );//!< copy constructor #ifndef QT_NO_STL SUIT_DataOwnerPtrList( const std::list& l );//!< copy constructor for STL list + SUIT_DataOwnerPtrList( const std::list& l, const bool skipAllEqal );//!< copy constructor for STL list #endif iterator append ( const SUIT_DataOwnerPtr& x );//!< append function @@ -50,6 +53,8 @@ private: iterator insert ( iterator it, const SUIT_DataOwnerPtr& x );//!< hide method void push_front ( const SUIT_DataOwnerPtr& x );//!< hide method void push_back ( const SUIT_DataOwnerPtr& x );//!< hide method +private: + bool mySkipEqual; }; #ifdef WIN32 -- 2.39.2