Salome HOME
Parent object parameter added to constructor.
[modules/gui.git] / src / SUIT / SUIT_DataOwner.cxx
index 2726fefb99d396d7a1c72bb54577d3692375a167..b1c9e8bba3823ce8c8a215dca7f947f1ecc90127 100755 (executable)
@@ -1,3 +1,21 @@
+// Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
+// 
+// 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.
+// 
+// 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/
+//
 #include "SUIT_DataOwner.h"
 
 #ifndef WNT
 // SUIT_DataOwner class
 //********************************************************************
 
-//====================================================================
-// Constructor
-//====================================================================
+
+/*! Constructor*/
 SUIT_DataOwner::SUIT_DataOwner()
 {
 }
 
-//====================================================================
-// Destructor
-//====================================================================
+/*! Destructor*/
 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->isEqual( *p2 ) && p2->isEqual( *p1 ));
   return p1.isNull() && p2.isNull();
 }
 
 //********************************************************************
-// SUIT_DataOwnerPtrList class: implements value list with unique
-// items (uniqueness is provided by operator==())
+/*! \class SUIT_DataOwnerPtrList 
+ * implements value list with unique items (uniqueness is 
+ * provided by operator==())
+ */
 //********************************************************************
 
 //====================================================================
-// Constructor (default)
+//! Constructor (default)
 //====================================================================
 SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList()
-: QValueList<SUIT_DataOwnerPtr>()
+  : QValueList<SUIT_DataOwnerPtr>(),
+    mySkipEqual( true )
 {
 }
 
 //====================================================================
-// Constructor (copy)
+//! Constructor (default)
+//====================================================================
+SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList( const bool skipAllEqual )
+  : QValueList<SUIT_DataOwnerPtr>(),
+    mySkipEqual( skipAllEqual )
+{
+}
+
+//====================================================================
+//! Constructor (copy)
 //====================================================================
 SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList( const SUIT_DataOwnerPtrList& l )
-: QValueList<SUIT_DataOwnerPtr>( l )
+  : QValueList<SUIT_DataOwnerPtr>( l ),
+    mySkipEqual( true )
 {
 }
 
+//====================================================================
+//! Constructor (copy)
+//====================================================================
+SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList( const SUIT_DataOwnerPtrList& l, const bool skipAllEqual )
+  : QValueList<SUIT_DataOwnerPtr>(),
+    mySkipEqual( skipAllEqual )
+{
+  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 )
+      append( *beginIt );
+  }
+}
+
 #ifndef QT_NO_STL
 //====================================================================
-// Constructor (from stl)
+//! Constructor (from stl)
 //====================================================================
 SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList( const std::list<SUIT_DataOwnerPtr>& l )
-: QValueList<SUIT_DataOwnerPtr>( l )
+  : QValueList<SUIT_DataOwnerPtr>( l ),
+    mySkipEqual( true )
+{
+}
+#endif
+
+#ifndef QT_NO_STL
+//====================================================================
+//! Constructor (from stl)
+//====================================================================
+SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList( const std::list<SUIT_DataOwnerPtr>& l, const bool skipAllEqual )
+  : QValueList<SUIT_DataOwnerPtr>(),
+    mySkipEqual( skipAllEqual )
 {
+  std::list<SUIT_DataOwnerPtr>::const_iterator beginIt = l.begin();
+  std::list<SUIT_DataOwnerPtr>::const_iterator endIt = l.begin();
+  for( ; beginIt != endIt; ++beginIt )
+    append( *beginIt );
 }
 #endif
 
 //====================================================================
-// Appends an item to the list
+//! Appends an item to the list
 //====================================================================
 SUIT_DataOwnerPtrList::iterator SUIT_DataOwnerPtrList::append( const SUIT_DataOwnerPtr& x )
 {
   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<SUIT_DataOwnerPtr>::append( x );
 }