0024162: Eliminate CLang compiler warning
[occt.git] / src / TDataStd / TDataStd_IntPackedMap.cxx
CommitLineData
b311480e 1// Created on: 2007-07-31
2// Created by: Sergey ZARITCHNY
3// Copyright (c) 2007-2012 OPEN CASCADE SAS
4//
5// The content of this file is subject to the Open CASCADE Technology Public
6// License Version 6.5 (the "License"). You may not use the content of this file
7// except in compliance with the License. Please obtain a copy of the License
8// at http://www.opencascade.org and read it completely before using this file.
9//
10// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12//
13// The Original Code and all software distributed under the License is
14// distributed on an "AS IS" basis, without warranty of any kind, and the
15// Initial Developer hereby disclaims all such warranties, including without
16// limitation, any warranties of merchantability, fitness for a particular
17// purpose or non-infringement. Please see the License for the specific terms
18// and conditions governing the rights and limitations under the License.
19
7fd59977 20
21
22#include <TDataStd_IntPackedMap.ixx>
23#include <TColStd_PackedMapOfInteger.hxx>
24#include <TColStd_HPackedMapOfInteger.hxx>
25#include <TDF_DefaultDeltaOnModification.hxx>
26#include <TDataStd_DeltaOnModificationOfIntPackedMap.hxx>
27#include <Standard_GUID.hxx>
28#include <TDF_Label.hxx>
29#include <TDF_Attribute.hxx>
30//=======================================================================
31//function : GetID
32//purpose :
33//=======================================================================
34
35const Standard_GUID& TDataStd_IntPackedMap::GetID()
36{
37 static Standard_GUID theGUID ("7031faff-161e-44df-8239-7c264a81f5a1");
38 return theGUID;
39}
40
41//=======================================================================
42//function : Set
43//purpose :
44//=======================================================================
45
46Handle(TDataStd_IntPackedMap) TDataStd_IntPackedMap::Set (const TDF_Label& theLabel,
47 const Standard_Boolean isDelta)
48{
49 Handle(TDataStd_IntPackedMap) anAtt;
50 if (!theLabel.FindAttribute(TDataStd_IntPackedMap::GetID(), anAtt))
51 {
52 anAtt = new TDataStd_IntPackedMap;
53 anAtt->Clear();
54 anAtt->SetDelta(isDelta);
55 theLabel.AddAttribute(anAtt);
56 }
57 return anAtt;
58}
59//=======================================================================
60//function : Constructor
61//purpose :
62//=======================================================================
63TDataStd_IntPackedMap::TDataStd_IntPackedMap ()
64 :myIsDelta(Standard_False)
65{
66 myMap = new TColStd_HPackedMapOfInteger ();
67}
68//=======================================================================
69//function : ChangeMap
70//purpose :
71//=======================================================================
72
73Standard_Boolean TDataStd_IntPackedMap::ChangeMap (const Handle(TColStd_HPackedMapOfInteger)& theMap)
74{
75 if(theMap.IsNull()) return Standard_False;
76 if (myMap != theMap)
77 {
78 if (!myMap->Map().IsEqual(theMap->Map()))
79 {
80 Backup();
81 myMap->ChangeMap().Assign(theMap->Map());
82 return Standard_True;
83 }
84 }
85 return Standard_False;
86}
87//=======================================================================
88//function : Clear
89//purpose :
90//=======================================================================
91
92Standard_Boolean TDataStd_IntPackedMap::Clear ()
93{
94 if (!myMap->Map().IsEmpty())
95 {
96 Backup();
97 myMap = new TColStd_HPackedMapOfInteger;
98 return Standard_True;
99 }
100 return Standard_False;
101}
102
103//=======================================================================
104//function : Contains
105//purpose :
106//=======================================================================
107Standard_Boolean TDataStd_IntPackedMap::Contains(const Standard_Integer theKey) const
108{
109 return myMap->Map().Contains(theKey);
110}
111
112//=======================================================================
113//function : Add
114//purpose :
115//=======================================================================
116
117Standard_Boolean TDataStd_IntPackedMap::Add(const Standard_Integer theKey)
118{
119 Standard_Boolean aResult = !myMap->Map().Contains(theKey);
120 if (aResult)
121 {
122 Backup();
123 aResult = myMap->ChangeMap().Add(theKey);
124 }
125 return aResult;
126}
127//=======================================================================
128//function : Remove
129//purpose :
130//=======================================================================
131
132Standard_Boolean TDataStd_IntPackedMap::Remove(const Standard_Integer theKey)
133{
134 Standard_Boolean aResult = myMap->Map().Contains(theKey);
135 if (aResult)
136 {
137 Backup();
138 aResult = myMap->ChangeMap().Remove(theKey);
139 }
140 return aResult;
141}
142
143//=======================================================================
144//function : NewEmpty
145//purpose :
146//=======================================================================
147
148Handle(TDF_Attribute) TDataStd_IntPackedMap::NewEmpty () const
149{
150 return new TDataStd_IntPackedMap;
151}
152
153//=======================================================================
154//function : Restore
155//purpose :
156//=======================================================================
157
158void TDataStd_IntPackedMap::Restore (const Handle(TDF_Attribute)& theWith)
159{
160 Handle(TDataStd_IntPackedMap) aWith =
161 Handle(TDataStd_IntPackedMap)::DownCast(theWith);
162 if (aWith->myMap.IsNull())
163 myMap.Nullify();
164 else
165 {
166 myMap = new TColStd_HPackedMapOfInteger;
167 myMap->ChangeMap().Assign(aWith->myMap->Map());
168 myIsDelta = aWith->myIsDelta;
169 }
170}
171
172//=======================================================================
173//function : Paste
174//purpose :
175//=======================================================================
176
177void TDataStd_IntPackedMap::Paste (const Handle(TDF_Attribute)& theInto,
178 const Handle(TDF_RelocationTable)&) const
179{
180 Handle(TDataStd_IntPackedMap) anInto =
181 Handle(TDataStd_IntPackedMap)::DownCast(theInto);
182 if(!anInto.IsNull()) {
183 anInto->ChangeMap(myMap);
184 anInto->SetDelta(myIsDelta);
185 }
186}
187
188//=======================================================================
189//function : ID
190//purpose :
191//=======================================================================
192const Standard_GUID& TDataStd_IntPackedMap::ID() const
193{ return GetID(); }
194
195//=======================================================================
196//function : Dump
197//purpose :
198//=======================================================================
199
200Standard_OStream& TDataStd_IntPackedMap::Dump(Standard_OStream& theOS) const
201{
202 Standard_OStream& anOS = TDF_Attribute::Dump( theOS );
203 anOS << "IntPackedMap size = " << Extent();
eb901da6 204 anOS << " Delta is " << (myIsDelta ? "ON":"OFF");
7fd59977 205 anOS << endl;
206 return anOS;
207}
208
209//=======================================================================
210//function : DeltaOnModification
211//purpose :
212//=======================================================================
213
214Handle(TDF_DeltaOnModification) TDataStd_IntPackedMap::DeltaOnModification
215(const Handle(TDF_Attribute)& OldAttribute) const
216{
217 if(myIsDelta)
218 return new TDataStd_DeltaOnModificationOfIntPackedMap(*((Handle(TDataStd_IntPackedMap)*)&OldAttribute));
219 else return new TDF_DefaultDeltaOnModification(OldAttribute);
220}
221
222