Salome HOME
PAL10670 - it is necessary to increase speed of selection and popup construction...
[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/
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 //********************************************************************
30 // SUIT_DataOwner class
31 //********************************************************************
32
33
34 /*! Constructor*/
35 SUIT_DataOwner::SUIT_DataOwner()
36 {
37 }
38
39 /*! Destructor*/
40 SUIT_DataOwner::~SUIT_DataOwner()
41 {
42 }
43
44 /*! operator== : compares two owners*/
45 bool operator==( const SUIT_DataOwnerPtr& p1, const SUIT_DataOwnerPtr& p2 )
46 {
47   if ( !p1.isNull() && !p2.isNull() )
48     return (p1->isEqual( *p2 ) && p2->isEqual( *p1 ));
49   return p1.isNull() && p2.isNull();
50 }
51
52 //********************************************************************
53 /*! \class SUIT_DataOwnerPtrList 
54  * implements value list with unique items (uniqueness is 
55  * provided by operator==())
56  */
57 //********************************************************************
58
59 //====================================================================
60 //! Constructor (default)
61 //====================================================================
62 SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList()
63   : QValueList<SUIT_DataOwnerPtr>(),
64     mySkipEqual( true )
65 {
66 }
67
68 //====================================================================
69 //! Constructor (default)
70 //====================================================================
71 SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList( const bool skipAllEqual )
72   : QValueList<SUIT_DataOwnerPtr>(),
73     mySkipEqual( skipAllEqual )
74 {
75 }
76
77 //====================================================================
78 //! Constructor (copy)
79 //====================================================================
80 SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList( const SUIT_DataOwnerPtrList& l )
81   : QValueList<SUIT_DataOwnerPtr>( l ),
82     mySkipEqual( true )
83 {
84 }
85
86 //====================================================================
87 //! Constructor (copy)
88 //====================================================================
89 SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList( const SUIT_DataOwnerPtrList& l, const bool skipAllEqual )
90   : QValueList<SUIT_DataOwnerPtr>(),
91     mySkipEqual( skipAllEqual )
92 {
93   if ( skipAllEqual == l.mySkipEqual )
94     operator =( l );
95   else
96   {
97     SUIT_DataOwnerPtrList::const_iterator beginIt = l.begin();
98     SUIT_DataOwnerPtrList::const_iterator endIt = l.end();
99     for( ; beginIt != endIt; ++beginIt )
100       append( *beginIt );
101   }
102 }
103
104 #ifndef QT_NO_STL
105 //====================================================================
106 //! Constructor (from stl)
107 //====================================================================
108 SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList( const std::list<SUIT_DataOwnerPtr>& l )
109   : QValueList<SUIT_DataOwnerPtr>( l ),
110     mySkipEqual( true )
111 {
112 }
113 #endif
114
115 #ifndef QT_NO_STL
116 //====================================================================
117 //! Constructor (from stl)
118 //====================================================================
119 SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList( const std::list<SUIT_DataOwnerPtr>& l, const bool skipAllEqual )
120   : QValueList<SUIT_DataOwnerPtr>(),
121     mySkipEqual( skipAllEqual )
122 {
123   std::list<SUIT_DataOwnerPtr>::const_iterator beginIt = l.begin();
124   std::list<SUIT_DataOwnerPtr>::const_iterator endIt = l.begin();
125   for( ; beginIt != endIt; ++beginIt )
126     append( *beginIt );
127 }
128 #endif
129
130 //====================================================================
131 //! Appends an item to the list
132 //====================================================================
133 SUIT_DataOwnerPtrList::iterator SUIT_DataOwnerPtrList::append( const SUIT_DataOwnerPtr& x )
134 {
135   if( mySkipEqual && myMap.contains( x ) ) //contains uses SUIT_DataOwnerPtr::operator==
136     return myMap[ x ];
137
138   iterator it = QValueList<SUIT_DataOwnerPtr>::append( x );
139
140   if( mySkipEqual )
141     myMap.insert( x, it );
142
143   return it;
144 }
145
146 //====================================================================
147 //! Clear list
148 //====================================================================
149 void SUIT_DataOwnerPtrList::clear()
150 {
151   if( mySkipEqual )
152     myMap.clear();
153   QValueList<SUIT_DataOwnerPtr>::clear();
154 }
155
156 //====================================================================
157 //! Remove an item from the list
158 //====================================================================
159 uint SUIT_DataOwnerPtrList::remove(const SUIT_DataOwnerPtr& x )
160 {
161   if( mySkipEqual && myMap.contains(x) )
162     myMap.remove(x);
163   return QValueList<SUIT_DataOwnerPtr>::remove( x );
164 }