Salome HOME
4fcabeb97597e8222202bb28eca0b9595aed6325
[modules/gui.git] / src / SUIT / SUIT_DataOwner.cxx
1 // Copyright (C) 2007-2023  CEA, EDF, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "SUIT_DataOwner.h"
24
25 #ifndef WIN32
26 #include <typeinfo>
27 #define _typeinfo std::type_info
28 #else
29 #include <typeinfo.h>
30 #define _typeinfo type_info
31 #endif
32
33 /*! Constructor*/
34 SUIT_DataOwner::SUIT_DataOwner()
35 {
36 }
37
38 /*! Destructor*/
39 SUIT_DataOwner::~SUIT_DataOwner()
40 {
41 }
42
43 /*! Operator == compares two owners*/
44 bool operator==( const SUIT_DataOwnerPtr& p1, const SUIT_DataOwnerPtr& p2 )
45 {
46   if ( !p1.isNull() && !p2.isNull() )
47     return (p1->keyString() == p2->keyString());
48   return p1.isNull() && p2.isNull();
49 }
50
51
52 /*! Operator < allows to order suit data owners for map */
53 bool operator<( const SUIT_DataOwnerPtr& p1, const SUIT_DataOwnerPtr& p2 )
54 {
55   if ( p1.isNull() && p2.isNull() )
56     return false;
57   else if ( p1.isNull() )
58     return true;
59   else if ( p2.isNull() )
60     return false;
61
62   return (p1->keyString() < p2->keyString());
63 }
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 : QList<SUIT_DataOwnerPtr>(),
76 mySkipEqual( true )
77 {
78 }
79
80 /*!
81   Constructor (default)
82 */
83 SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList( const bool skipAllEqual )
84 : QList<SUIT_DataOwnerPtr>(),
85 mySkipEqual( skipAllEqual )
86 {
87 }
88
89 /*!
90   Constructor (copy)
91 */
92 SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList( const SUIT_DataOwnerPtrList& l )
93 : QList<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 : QList<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 /*!
117   Appends an item to the list
118 */
119 void SUIT_DataOwnerPtrList::append( const SUIT_DataOwnerPtr& x )
120 {
121   if ( mySkipEqual && myMap.contains( x ) ) //contains uses SUIT_DataOwnerPtr::operator==
122     return;
123
124   QList<SUIT_DataOwnerPtr>::append( x );
125
126   if ( mySkipEqual )
127     myMap.insert( x, 0 );
128 }
129
130 /*!
131   Clear list
132 */
133 void SUIT_DataOwnerPtrList::clear()
134 {
135   if ( mySkipEqual )
136     myMap.clear();
137
138   QList<SUIT_DataOwnerPtr>::clear();
139 }
140
141 /*!
142   Remove an item from the list
143 */
144 uint SUIT_DataOwnerPtrList::remove(const SUIT_DataOwnerPtr& x )
145 {
146   if ( mySkipEqual && myMap.contains(x) )
147     myMap.remove( x );
148
149   return QList<SUIT_DataOwnerPtr>::removeAll( x );
150 }