Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[modules/gui.git] / src / SUIT / SUIT_DataOwner.cxx
1 // Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
2 // 
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either 
6 // version 2.1 of the License.
7 // 
8 // This library is distributed in the hope that it will be useful 
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public  
14 // License along with this library; if not, write to the Free Software 
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 #include "SUIT_DataOwner.h"
20
21 #ifndef WNT
22 #include <typeinfo>
23 #define _typeinfo std::type_info
24 #else
25 #include <typeinfo.h>
26 #define _typeinfo type_info
27 #endif
28
29 /*! Constructor*/
30 SUIT_DataOwner::SUIT_DataOwner()
31 {
32 }
33
34 /*! Destructor*/
35 SUIT_DataOwner::~SUIT_DataOwner()
36 {
37 }
38
39 /*! operator== : compares two owners*/
40 bool operator==( const SUIT_DataOwnerPtr& p1, const SUIT_DataOwnerPtr& p2 )
41 {
42   if ( !p1.isNull() && !p2.isNull() )
43     return (p1->isEqual( *p2 ) && p2->isEqual( *p1 ));
44   return p1.isNull() && p2.isNull();
45 }
46
47 /*!
48   \class SUIT_DataOwnerPtrList 
49   implements value list with unique items (uniqueness is 
50   provided by operator==())
51 */
52
53 /*!
54   Constructor (default)
55 */
56 SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList()
57   : QValueList<SUIT_DataOwnerPtr>(),
58     mySkipEqual( true )
59 {
60 }
61
62 /*!
63   Constructor (default)
64 */
65 SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList( const bool skipAllEqual )
66   : QValueList<SUIT_DataOwnerPtr>(),
67     mySkipEqual( skipAllEqual )
68 {
69 }
70
71 /*!
72   Constructor (copy)
73 */
74 SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList( const SUIT_DataOwnerPtrList& l )
75   : QValueList<SUIT_DataOwnerPtr>( l ),
76     mySkipEqual( true )
77 {
78 }
79
80 /*!
81   Constructor (copy)
82 */
83 SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList( const SUIT_DataOwnerPtrList& l, const bool skipAllEqual )
84   : QValueList<SUIT_DataOwnerPtr>(),
85     mySkipEqual( skipAllEqual )
86 {
87   if ( skipAllEqual == l.mySkipEqual )
88     operator =( l );
89   else
90   {
91     SUIT_DataOwnerPtrList::const_iterator beginIt = l.begin();
92     SUIT_DataOwnerPtrList::const_iterator endIt = l.end();
93     for( ; beginIt != endIt; ++beginIt )
94       append( *beginIt );
95   }
96 }
97
98 #ifndef QT_NO_STL
99 /*!
100   Constructor (from stl)
101 */
102 SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList( const std::list<SUIT_DataOwnerPtr>& l )
103   : QValueList<SUIT_DataOwnerPtr>( l ),
104     mySkipEqual( true )
105 {
106 }
107 #endif
108
109 #ifndef QT_NO_STL
110 /*!
111   Constructor (from stl)
112 */
113 SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList( const std::list<SUIT_DataOwnerPtr>& l, const bool skipAllEqual )
114   : QValueList<SUIT_DataOwnerPtr>(),
115     mySkipEqual( skipAllEqual )
116 {
117   std::list<SUIT_DataOwnerPtr>::const_iterator beginIt = l.begin();
118   std::list<SUIT_DataOwnerPtr>::const_iterator endIt = l.begin();
119   for( ; beginIt != endIt; ++beginIt )
120     append( *beginIt );
121 }
122 #endif
123
124 /*!
125   Appends an item to the list
126 */
127 SUIT_DataOwnerPtrList::iterator SUIT_DataOwnerPtrList::append( const SUIT_DataOwnerPtr& x )
128 {
129   if( mySkipEqual && myMap.contains( x ) ) //contains uses SUIT_DataOwnerPtr::operator==
130     return myMap[ x ];
131
132   iterator it = QValueList<SUIT_DataOwnerPtr>::append( x );
133
134   if( mySkipEqual )
135     myMap.insert( x, it );
136
137   return it;
138 }
139
140 /*!
141   Clear list
142 */
143 void SUIT_DataOwnerPtrList::clear()
144 {
145   if( mySkipEqual )
146     myMap.clear();
147   QValueList<SUIT_DataOwnerPtr>::clear();
148 }
149
150 /*!
151   Remove an item from the list
152 */
153 uint SUIT_DataOwnerPtrList::remove(const SUIT_DataOwnerPtr& x )
154 {
155   if( mySkipEqual && myMap.contains(x) )
156     myMap.remove(x);
157   return QValueList<SUIT_DataOwnerPtr>::remove( x );
158 }
159
160 /*!
161   Operator < allows to order suit data owners for map
162 */
163 bool operator<( const SUIT_DataOwnerPtr& p1, const SUIT_DataOwnerPtr& p2 )
164 {
165   return p1.get()<p2.get();
166 }