b311480e |
1 | // Created on: 2007-07-31 |
2 | // Created by: Sergey ZARITCHNY |
973c2be1 |
3 | // Copyright (c) 2007-2014 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
b311480e |
6 | // |
d5f74e42 |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
11 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
7fd59977 |
15 | |
bc73b006 |
16 | #include <TDataStd_IntPackedMap.hxx> |
42cf5bc1 |
17 | |
bc73b006 |
18 | #include <Standard_Dump.hxx> |
42cf5bc1 |
19 | #include <Standard_GUID.hxx> |
20 | #include <Standard_Type.hxx> |
7fd59977 |
21 | #include <TColStd_HPackedMapOfInteger.hxx> |
42cf5bc1 |
22 | #include <TColStd_PackedMapOfInteger.hxx> |
7fd59977 |
23 | #include <TDataStd_DeltaOnModificationOfIntPackedMap.hxx> |
7fd59977 |
24 | #include <TDF_Attribute.hxx> |
42cf5bc1 |
25 | #include <TDF_DefaultDeltaOnModification.hxx> |
26 | #include <TDF_DeltaOnModification.hxx> |
27 | #include <TDF_Label.hxx> |
28 | #include <TDF_RelocationTable.hxx> |
29 | |
92efcf78 |
30 | IMPLEMENT_STANDARD_RTTIEXT(TDataStd_IntPackedMap,TDF_Attribute) |
31 | |
7fd59977 |
32 | //======================================================================= |
33 | //function : GetID |
34 | //purpose : |
35 | //======================================================================= |
7fd59977 |
36 | const Standard_GUID& TDataStd_IntPackedMap::GetID() |
37 | { |
38 | static Standard_GUID theGUID ("7031faff-161e-44df-8239-7c264a81f5a1"); |
39 | return theGUID; |
40 | } |
41 | |
42 | //======================================================================= |
43 | //function : Set |
44 | //purpose : |
45 | //======================================================================= |
46 | |
47 | Handle(TDataStd_IntPackedMap) TDataStd_IntPackedMap::Set (const TDF_Label& theLabel, |
48 | const Standard_Boolean isDelta) |
49 | { |
50 | Handle(TDataStd_IntPackedMap) anAtt; |
51 | if (!theLabel.FindAttribute(TDataStd_IntPackedMap::GetID(), anAtt)) |
52 | { |
53 | anAtt = new TDataStd_IntPackedMap; |
54 | anAtt->Clear(); |
55 | anAtt->SetDelta(isDelta); |
56 | theLabel.AddAttribute(anAtt); |
57 | } |
58 | return anAtt; |
59 | } |
60 | //======================================================================= |
61 | //function : Constructor |
62 | //purpose : |
63 | //======================================================================= |
64 | TDataStd_IntPackedMap::TDataStd_IntPackedMap () |
65 | :myIsDelta(Standard_False) |
66 | { |
67 | myMap = new TColStd_HPackedMapOfInteger (); |
68 | } |
69 | //======================================================================= |
70 | //function : ChangeMap |
71 | //purpose : |
72 | //======================================================================= |
73 | |
74 | Standard_Boolean TDataStd_IntPackedMap::ChangeMap (const Handle(TColStd_HPackedMapOfInteger)& theMap) |
75 | { |
76 | if(theMap.IsNull()) return Standard_False; |
77 | if (myMap != theMap) |
78 | { |
79 | if (!myMap->Map().IsEqual(theMap->Map())) |
80 | { |
81 | Backup(); |
82 | myMap->ChangeMap().Assign(theMap->Map()); |
83 | return Standard_True; |
84 | } |
85 | } |
86 | return Standard_False; |
87 | } |
14abe5dc |
88 | |
89 | //======================================================================= |
90 | //function : ChangeMap |
91 | //purpose : |
92 | //======================================================================= |
93 | Standard_Boolean TDataStd_IntPackedMap::ChangeMap (const TColStd_PackedMapOfInteger& theMap) |
94 | { |
95 | if (!myMap->Map().IsEqual(theMap)) |
96 | { |
97 | Backup(); |
98 | myMap->ChangeMap().Assign(theMap); |
99 | return Standard_True; |
100 | } |
101 | return Standard_False; |
102 | } |
7fd59977 |
103 | //======================================================================= |
104 | //function : Clear |
105 | //purpose : |
106 | //======================================================================= |
107 | |
108 | Standard_Boolean TDataStd_IntPackedMap::Clear () |
109 | { |
110 | if (!myMap->Map().IsEmpty()) |
111 | { |
112 | Backup(); |
113 | myMap = new TColStd_HPackedMapOfInteger; |
114 | return Standard_True; |
115 | } |
116 | return Standard_False; |
117 | } |
118 | |
119 | //======================================================================= |
120 | //function : Contains |
121 | //purpose : |
122 | //======================================================================= |
123 | Standard_Boolean TDataStd_IntPackedMap::Contains(const Standard_Integer theKey) const |
124 | { |
125 | return myMap->Map().Contains(theKey); |
126 | } |
127 | |
128 | //======================================================================= |
129 | //function : Add |
130 | //purpose : |
131 | //======================================================================= |
132 | |
133 | Standard_Boolean TDataStd_IntPackedMap::Add(const Standard_Integer theKey) |
134 | { |
135 | Standard_Boolean aResult = !myMap->Map().Contains(theKey); |
136 | if (aResult) |
137 | { |
138 | Backup(); |
139 | aResult = myMap->ChangeMap().Add(theKey); |
140 | } |
141 | return aResult; |
142 | } |
143 | //======================================================================= |
144 | //function : Remove |
145 | //purpose : |
146 | //======================================================================= |
147 | |
148 | Standard_Boolean TDataStd_IntPackedMap::Remove(const Standard_Integer theKey) |
149 | { |
150 | Standard_Boolean aResult = myMap->Map().Contains(theKey); |
151 | if (aResult) |
152 | { |
153 | Backup(); |
154 | aResult = myMap->ChangeMap().Remove(theKey); |
155 | } |
156 | return aResult; |
157 | } |
158 | |
159 | //======================================================================= |
160 | //function : NewEmpty |
161 | //purpose : |
162 | //======================================================================= |
163 | |
164 | Handle(TDF_Attribute) TDataStd_IntPackedMap::NewEmpty () const |
165 | { |
166 | return new TDataStd_IntPackedMap; |
167 | } |
168 | |
169 | //======================================================================= |
170 | //function : Restore |
171 | //purpose : |
172 | //======================================================================= |
173 | |
174 | void TDataStd_IntPackedMap::Restore (const Handle(TDF_Attribute)& theWith) |
175 | { |
176 | Handle(TDataStd_IntPackedMap) aWith = |
177 | Handle(TDataStd_IntPackedMap)::DownCast(theWith); |
178 | if (aWith->myMap.IsNull()) |
179 | myMap.Nullify(); |
180 | else |
181 | { |
182 | myMap = new TColStd_HPackedMapOfInteger; |
183 | myMap->ChangeMap().Assign(aWith->myMap->Map()); |
184 | myIsDelta = aWith->myIsDelta; |
185 | } |
186 | } |
187 | |
188 | //======================================================================= |
189 | //function : Paste |
190 | //purpose : |
191 | //======================================================================= |
192 | |
193 | void TDataStd_IntPackedMap::Paste (const Handle(TDF_Attribute)& theInto, |
194 | const Handle(TDF_RelocationTable)&) const |
195 | { |
196 | Handle(TDataStd_IntPackedMap) anInto = |
197 | Handle(TDataStd_IntPackedMap)::DownCast(theInto); |
198 | if(!anInto.IsNull()) { |
199 | anInto->ChangeMap(myMap); |
200 | anInto->SetDelta(myIsDelta); |
201 | } |
202 | } |
203 | |
204 | //======================================================================= |
205 | //function : ID |
206 | //purpose : |
207 | //======================================================================= |
208 | const Standard_GUID& TDataStd_IntPackedMap::ID() const |
209 | { return GetID(); } |
210 | |
211 | //======================================================================= |
212 | //function : Dump |
213 | //purpose : |
214 | //======================================================================= |
215 | |
216 | Standard_OStream& TDataStd_IntPackedMap::Dump(Standard_OStream& theOS) const |
217 | { |
218 | Standard_OStream& anOS = TDF_Attribute::Dump( theOS ); |
219 | anOS << "IntPackedMap size = " << Extent(); |
eb901da6 |
220 | anOS << " Delta is " << (myIsDelta ? "ON":"OFF"); |
04232180 |
221 | anOS << std::endl; |
7fd59977 |
222 | return anOS; |
223 | } |
224 | |
225 | //======================================================================= |
226 | //function : DeltaOnModification |
227 | //purpose : |
228 | //======================================================================= |
229 | |
230 | Handle(TDF_DeltaOnModification) TDataStd_IntPackedMap::DeltaOnModification |
231 | (const Handle(TDF_Attribute)& OldAttribute) const |
232 | { |
233 | if(myIsDelta) |
c5f3a425 |
234 | return new TDataStd_DeltaOnModificationOfIntPackedMap(Handle(TDataStd_IntPackedMap)::DownCast (OldAttribute)); |
7fd59977 |
235 | else return new TDF_DefaultDeltaOnModification(OldAttribute); |
236 | } |
237 | |
bc73b006 |
238 | //======================================================================= |
239 | //function : DumpJson |
240 | //purpose : |
241 | //======================================================================= |
242 | void TDataStd_IntPackedMap::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const |
243 | { |
244 | OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream) |
7fd59977 |
245 | |
bc73b006 |
246 | OCCT_DUMP_BASE_CLASS (theOStream, theDepth, TDF_Attribute) |
247 | |
248 | for (TColStd_PackedMapOfInteger::Iterator aMapIt (myMap->Map()); aMapIt.More(); aMapIt.Next()) |
249 | { |
250 | Standard_Integer aKey = aMapIt.Key(); |
251 | OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, aKey) |
252 | } |
253 | |
254 | OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myIsDelta) |
255 | } |