Back to index

salome-gui  6.5.0
SUIT_DataOwner.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #include "SUIT_DataOwner.h"
00024 
00025 #ifndef WIN32
00026 #include <typeinfo>
00027 #define _typeinfo std::type_info
00028 #else
00029 #include <typeinfo.h>
00030 #define _typeinfo type_info
00031 #endif
00032 
00034 SUIT_DataOwner::SUIT_DataOwner()
00035 {
00036 }
00037 
00039 SUIT_DataOwner::~SUIT_DataOwner()
00040 {
00041 }
00042 
00044 bool operator==( const SUIT_DataOwnerPtr& p1, const SUIT_DataOwnerPtr& p2 )
00045 {
00046   if ( !p1.isNull() && !p2.isNull() )
00047     return (p1->keyString() == p2->keyString());
00048   return p1.isNull() && p2.isNull();
00049 }
00050 
00051 
00053 bool operator<( const SUIT_DataOwnerPtr& p1, const SUIT_DataOwnerPtr& p2 )
00054 {
00055   if ( p1.isNull() && p2.isNull() )
00056     return false;
00057   else if ( p1.isNull() )
00058     return true;
00059   else if ( p2.isNull() )
00060     return false;
00061 
00062   return (p1->keyString() < p2->keyString());
00063 }
00064 
00074 SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList()
00075 : QList<SUIT_DataOwnerPtr>(),
00076 mySkipEqual( true )
00077 {
00078 }
00079 
00083 SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList( const bool skipAllEqual )
00084 : QList<SUIT_DataOwnerPtr>(),
00085 mySkipEqual( skipAllEqual )
00086 {
00087 }
00088 
00092 SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList( const SUIT_DataOwnerPtrList& l )
00093 : QList<SUIT_DataOwnerPtr>( l ),
00094 mySkipEqual( true )
00095 {
00096 }
00097 
00101 SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList( const SUIT_DataOwnerPtrList& l, const bool skipAllEqual )
00102 : QList<SUIT_DataOwnerPtr>(),
00103 mySkipEqual( skipAllEqual )
00104 {
00105   if ( skipAllEqual == l.mySkipEqual )
00106     operator =( l );
00107   else
00108   {
00109     SUIT_DataOwnerPtrList::const_iterator beginIt = l.begin();
00110     SUIT_DataOwnerPtrList::const_iterator endIt = l.end();
00111     for ( ; beginIt != endIt; ++beginIt )
00112       append( *beginIt );
00113   }
00114 }
00115 
00119 void SUIT_DataOwnerPtrList::append( const SUIT_DataOwnerPtr& x )
00120 {
00121   if ( mySkipEqual && myMap.contains( x ) ) //contains uses SUIT_DataOwnerPtr::operator==
00122     return;
00123 
00124   QList<SUIT_DataOwnerPtr>::append( x );
00125 
00126   if ( mySkipEqual )
00127     myMap.insert( x, 0 );
00128 }
00129 
00133 void SUIT_DataOwnerPtrList::clear()
00134 {
00135   if ( mySkipEqual )
00136     myMap.clear();
00137 
00138   QList<SUIT_DataOwnerPtr>::clear();
00139 }
00140 
00144 uint SUIT_DataOwnerPtrList::remove(const SUIT_DataOwnerPtr& x )
00145 {
00146   if ( mySkipEqual && myMap.contains(x) )
00147     myMap.remove( x );
00148 
00149   return QList<SUIT_DataOwnerPtr>::removeAll( x );
00150 }