Salome HOME
Copyrights update
[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   SUIT_DataOwnerPtrList::iterator it = find( x );
136   if ( it != end() )
137   {
138     if ( mySkipEqual )
139       return it;
140
141     const _typeinfo& ti1 = typeid( *((*it).operator->()) );
142     const _typeinfo& ti2 = typeid( *(x.operator->()) );
143
144     if (ti1 == ti2)
145       return it;
146   }
147   return QValueList<SUIT_DataOwnerPtr>::append( x );
148 }