X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSUIT%2FSUIT_DataOwner.cxx;h=c16fd76a8428cae967c1d377751b8fce554317bf;hb=efe3cdefadc31ad9cdaa9fd7fc368e2931cebdf1;hp=401b763df028bb442d8cd19b17d93d7d23975221;hpb=e33513df23f984db5f4b687157c39c684d77b581;p=modules%2Fgui.git diff --git a/src/SUIT/SUIT_DataOwner.cxx b/src/SUIT/SUIT_DataOwner.cxx index 401b763df..c16fd76a8 100755 --- a/src/SUIT/SUIT_DataOwner.cxx +++ b/src/SUIT/SUIT_DataOwner.cxx @@ -1,6 +1,28 @@ +// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + #include "SUIT_DataOwner.h" -#ifndef WNT +#ifndef WIN32 #include #define _typeinfo std::type_info #else @@ -8,11 +30,6 @@ #define _typeinfo type_info #endif -//******************************************************************** -// SUIT_DataOwner class -//******************************************************************** - - /*! Constructor*/ SUIT_DataOwner::SUIT_DataOwner() { @@ -23,104 +40,111 @@ SUIT_DataOwner::~SUIT_DataOwner() { } -/*! operator== : compares two owners*/ +/*! Operator == compares two owners*/ bool operator==( const SUIT_DataOwnerPtr& p1, const SUIT_DataOwnerPtr& p2 ) { if ( !p1.isNull() && !p2.isNull() ) - return p1->isEqual( *p2 ); + return (p1->keyString() == p2->keyString()); return p1.isNull() && p2.isNull(); } -//******************************************************************** -/*! \class SUIT_DataOwnerPtrList - * implements value list with unique items (uniqueness is - * provided by operator==()) - */ -//******************************************************************** -//==================================================================== -//! Constructor (default) -//==================================================================== +/*! Operator < allows to order suit data owners for map */ +bool operator<( const SUIT_DataOwnerPtr& p1, const SUIT_DataOwnerPtr& p2 ) +{ + if ( p1.isNull() && p2.isNull() ) + return false; + else if ( p1.isNull() ) + return true; + else if ( p2.isNull() ) + return false; + + return (p1->keyString() < p2->keyString()); +} + +/*! + \class SUIT_DataOwnerPtrList + implements value list with unique items (uniqueness is + provided by operator==() and operator<()) +*/ + +/*! + Constructor (default) +*/ SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList() -: QValueList() +: QList(), +mySkipEqual( true ) { } -//==================================================================== -//! Constructor (default) -//==================================================================== -SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList( const bool skipAllEqal ) -: QValueList(), -mySkipEqual( skipAllEqal ) +/*! + Constructor (default) +*/ +SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList( const bool skipAllEqual ) +: QList(), +mySkipEqual( skipAllEqual ) { } -//==================================================================== -//! Constructor (copy) -//==================================================================== +/*! + Constructor (copy) +*/ SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList( const SUIT_DataOwnerPtrList& l ) -: QValueList( l ) +: QList( l ), +mySkipEqual( true ) { } -//==================================================================== -//! Constructor (copy) -//==================================================================== -SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList( const SUIT_DataOwnerPtrList& l, const bool skipAllEqal ) -: QValueList(), -mySkipEqual( skipAllEqal ) +/*! + Constructor (copy) +*/ +SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList( const SUIT_DataOwnerPtrList& l, const bool skipAllEqual ) +: QList(), +mySkipEqual( skipAllEqual ) { - if ( skipAllEqal == l.mySkipEqual ) + if ( skipAllEqual == l.mySkipEqual ) operator =( l ); else { SUIT_DataOwnerPtrList::const_iterator beginIt = l.begin(); SUIT_DataOwnerPtrList::const_iterator endIt = l.end(); - for( ; beginIt != endIt; ++beginIt ) + for ( ; beginIt != endIt; ++beginIt ) append( *beginIt ); } } -#ifndef QT_NO_STL -//==================================================================== -//! Constructor (from stl) -//==================================================================== -SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList( const std::list& l ) -: QValueList( l ) +/*! + Appends an item to the list +*/ +void SUIT_DataOwnerPtrList::append( const SUIT_DataOwnerPtr& x ) { + if ( mySkipEqual && myMap.contains( x ) ) //contains uses SUIT_DataOwnerPtr::operator== + return; + + QList::append( x ); + + if ( mySkipEqual ) + myMap.insert( x, 0 ); } -#endif -#ifndef QT_NO_STL -//==================================================================== -//! Constructor (from stl) -//==================================================================== -SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList( const std::list& l, const bool skipAllEqal ) -: QValueList(), -mySkipEqual( skipAllEqal ) +/*! + Clear list +*/ +void SUIT_DataOwnerPtrList::clear() { - std::list::const_iterator beginIt = l.begin(); - std::list::const_iterator endIt = l.begin(); - for( ; beginIt != endIt; ++beginIt ) - append( *beginIt ); + if ( mySkipEqual ) + myMap.clear(); + + QList::clear(); } -#endif -//==================================================================== -//! Appends an item to the list -//==================================================================== -SUIT_DataOwnerPtrList::iterator SUIT_DataOwnerPtrList::append( const SUIT_DataOwnerPtr& x ) +/*! + Remove an item from the list +*/ +uint SUIT_DataOwnerPtrList::remove(const SUIT_DataOwnerPtr& x ) { - SUIT_DataOwnerPtrList::iterator it = find( x ); - if ( it != end() ) - { - if ( mySkipEqual ) - return it; - const _typeinfo& ti1 = typeid( *((*it).operator->()) ); - const _typeinfo& ti2 = typeid( *(x.operator->()) ); + if ( mySkipEqual && myMap.contains(x) ) + myMap.remove( x ); - if (ti1 == ti2) - return it; - } - return QValueList::append( x ); + return QList::removeAll( x ); }