Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[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
20 #include "SUIT_DataOwner.h"
21
22 #ifndef WNT
23 #include <typeinfo>
24 #define _typeinfo std::type_info
25 #else
26 #include <typeinfo.h>
27 #define _typeinfo type_info
28 #endif
29
30 /*! Constructor*/
31 SUIT_DataOwner::SUIT_DataOwner()
32 {
33 }
34
35 /*! Destructor*/
36 SUIT_DataOwner::~SUIT_DataOwner()
37 {
38 }
39
40 /*! Operator == compares two owners*/
41 bool operator==( const SUIT_DataOwnerPtr& p1, const SUIT_DataOwnerPtr& p2 )
42 {
43   if ( !p1.isNull() && !p2.isNull() )
44     return (p1->keyString() == p2->keyString());
45   return p1.isNull() && p2.isNull();
46 }
47
48 // *** jfa: The below function has been put here 14.02.2007 from branch BR_Dev_For_4_0
49 // *** and also improved for better comparison of DataOwners with DataSubOwners.
50 // *** This comment is to be removed after merging with BR_Dev_For_4_0.
51 /*! Operator < allows to order suit data owners for map */
52 bool operator<( const SUIT_DataOwnerPtr& p1, const SUIT_DataOwnerPtr& p2 )
53 {
54   if ( p1.isNull() && p2.isNull() )
55     return false;
56   else if ( p1.isNull() )
57     return true;
58   else if ( p2.isNull() )
59     return false;
60
61   return (p1->keyString() < p2->keyString());
62 }
63 // *** end
64
65 /*!
66   \class SUIT_DataOwnerPtrList 
67   implements value list with unique items (uniqueness is 
68   provided by operator==() and operator<())
69 */
70
71 /*!
72   Constructor (default)
73 */
74 SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList()
75   : QValueList<SUIT_DataOwnerPtr>(),
76     mySkipEqual( true )
77 {
78 }
79
80 /*!
81   Constructor (default)
82 */
83 SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList( const bool skipAllEqual )
84   : QValueList<SUIT_DataOwnerPtr>(),
85     mySkipEqual( skipAllEqual )
86 {
87 }
88
89 /*!
90   Constructor (copy)
91 */
92 SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList( const SUIT_DataOwnerPtrList& l )
93   : QValueList<SUIT_DataOwnerPtr>( l ),
94     mySkipEqual( true )
95 {
96 }
97
98 /*!
99   Constructor (copy)
100 */
101 SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList( const SUIT_DataOwnerPtrList& l, const bool skipAllEqual )
102   : QValueList<SUIT_DataOwnerPtr>(),
103     mySkipEqual( skipAllEqual )
104 {
105   if ( skipAllEqual == l.mySkipEqual )
106     operator =( l );
107   else
108   {
109     SUIT_DataOwnerPtrList::const_iterator beginIt = l.begin();
110     SUIT_DataOwnerPtrList::const_iterator endIt = l.end();
111     for( ; beginIt != endIt; ++beginIt )
112       append( *beginIt );
113   }
114 }
115
116 #ifndef QT_NO_STL
117 /*!
118   Constructor (from stl)
119 */
120 SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList( const std::list<SUIT_DataOwnerPtr>& l )
121   : QValueList<SUIT_DataOwnerPtr>( l ),
122     mySkipEqual( true )
123 {
124 }
125 #endif
126
127 #ifndef QT_NO_STL
128 /*!
129   Constructor (from stl)
130 */
131 SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList( const std::list<SUIT_DataOwnerPtr>& l, const bool skipAllEqual )
132   : QValueList<SUIT_DataOwnerPtr>(),
133     mySkipEqual( skipAllEqual )
134 {
135   std::list<SUIT_DataOwnerPtr>::const_iterator beginIt = l.begin();
136   std::list<SUIT_DataOwnerPtr>::const_iterator endIt = l.begin();
137   for( ; beginIt != endIt; ++beginIt )
138     append( *beginIt );
139 }
140 #endif
141
142 /*!
143   Appends an item to the list
144 */
145 SUIT_DataOwnerPtrList::iterator SUIT_DataOwnerPtrList::append( const SUIT_DataOwnerPtr& x )
146 {
147   if ( mySkipEqual && myMap.contains( x ) ) //contains uses SUIT_DataOwnerPtr::operator==
148     return myMap[ x ];
149
150   iterator it = QValueList<SUIT_DataOwnerPtr>::append( x );
151
152    if ( mySkipEqual )
153     myMap.insert( x, it );
154
155   return it;
156 }
157
158 /*!
159   Clear list
160 */
161 void SUIT_DataOwnerPtrList::clear()
162 {
163   if( mySkipEqual )
164     myMap.clear();
165   QValueList<SUIT_DataOwnerPtr>::clear();
166 }
167
168 /*!
169   Remove an item from the list
170 */
171 uint SUIT_DataOwnerPtrList::remove(const SUIT_DataOwnerPtr& x )
172 {
173   if( mySkipEqual && myMap.contains(x) )
174     myMap.remove(x);
175   return QValueList<SUIT_DataOwnerPtr>::remove( x );
176 }