Salome HOME
300a88e7c0295975a0e8b21a08c5fa57d3e25953
[modules/gui.git] / src / SUIT / SUIT_DataOwner.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, 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.
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 #include "SUIT_DataOwner.h"
23
24 #ifndef WIN32
25 #include <typeinfo>
26 #define _typeinfo std::type_info
27 #else
28 #include <typeinfo.h>
29 #define _typeinfo type_info
30 #endif
31
32 /*! Constructor*/
33 SUIT_DataOwner::SUIT_DataOwner()
34 {
35 }
36
37 /*! Destructor*/
38 SUIT_DataOwner::~SUIT_DataOwner()
39 {
40 }
41
42 /*! Operator == compares two owners*/
43 bool operator==( const SUIT_DataOwnerPtr& p1, const SUIT_DataOwnerPtr& p2 )
44 {
45   if ( !p1.isNull() && !p2.isNull() )
46     return (p1->keyString() == p2->keyString());
47   return p1.isNull() && p2.isNull();
48 }
49
50
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
64 /*!
65   \class SUIT_DataOwnerPtrList 
66   implements value list with unique items (uniqueness is 
67   provided by operator==() and operator<())
68 */
69
70 /*!
71   Constructor (default)
72 */
73 SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList()
74 : QList<SUIT_DataOwnerPtr>(),
75 mySkipEqual( true )
76 {
77 }
78
79 /*!
80   Constructor (default)
81 */
82 SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList( const bool skipAllEqual )
83 : QList<SUIT_DataOwnerPtr>(),
84 mySkipEqual( skipAllEqual )
85 {
86 }
87
88 /*!
89   Constructor (copy)
90 */
91 SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList( const SUIT_DataOwnerPtrList& l )
92 : QList<SUIT_DataOwnerPtr>( l ),
93 mySkipEqual( true )
94 {
95 }
96
97 /*!
98   Constructor (copy)
99 */
100 SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList( const SUIT_DataOwnerPtrList& l, const bool skipAllEqual )
101 : QList<SUIT_DataOwnerPtr>(),
102 mySkipEqual( skipAllEqual )
103 {
104   if ( skipAllEqual == l.mySkipEqual )
105     operator =( l );
106   else
107   {
108     SUIT_DataOwnerPtrList::const_iterator beginIt = l.begin();
109     SUIT_DataOwnerPtrList::const_iterator endIt = l.end();
110     for ( ; beginIt != endIt; ++beginIt )
111       append( *beginIt );
112   }
113 }
114
115 /*!
116   Appends an item to the list
117 */
118 void SUIT_DataOwnerPtrList::append( const SUIT_DataOwnerPtr& x )
119 {
120   if ( mySkipEqual && myMap.contains( x ) ) //contains uses SUIT_DataOwnerPtr::operator==
121     return;
122
123   QList<SUIT_DataOwnerPtr>::append( x );
124
125   if ( mySkipEqual )
126     myMap.insert( x, 0 );
127 }
128
129 /*!
130   Clear list
131 */
132 void SUIT_DataOwnerPtrList::clear()
133 {
134   if ( mySkipEqual )
135     myMap.clear();
136
137   QList<SUIT_DataOwnerPtr>::clear();
138 }
139
140 /*!
141   Remove an item from the list
142 */
143 uint SUIT_DataOwnerPtrList::remove(const SUIT_DataOwnerPtr& x )
144 {
145   if ( mySkipEqual && myMap.contains(x) )
146     myMap.remove( x );
147
148   return QList<SUIT_DataOwnerPtr>::removeAll( x );
149 }