b311480e |
1 | // Created on: 2007-05-29 |
2 | // Created by: Vlad Romashko |
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 | |
5a8d30b8 |
16 | #include <TDataStd_NamedData.hxx> |
7fd59977 |
17 | |
bc73b006 |
18 | #include <Standard_Dump.hxx> |
42cf5bc1 |
19 | #include <Standard_GUID.hxx> |
42cf5bc1 |
20 | #include <TCollection_ExtendedString.hxx> |
7fd59977 |
21 | #include <TColStd_DataMapIteratorOfDataMapOfStringInteger.hxx> |
7fd59977 |
22 | #include <TDataStd_DataMapIteratorOfDataMapOfStringByte.hxx> |
23 | #include <TDataStd_DataMapIteratorOfDataMapOfStringHArray1OfInteger.hxx> |
24 | #include <TDataStd_DataMapIteratorOfDataMapOfStringHArray1OfReal.hxx> |
42cf5bc1 |
25 | #include <TDataStd_DataMapIteratorOfDataMapOfStringReal.hxx> |
26 | #include <TDataStd_DataMapIteratorOfDataMapOfStringString.hxx> |
27 | #include <TDataStd_HDataMapOfStringByte.hxx> |
28 | #include <TDataStd_HDataMapOfStringHArray1OfInteger.hxx> |
29 | #include <TDataStd_HDataMapOfStringHArray1OfReal.hxx> |
30 | #include <TDataStd_HDataMapOfStringInteger.hxx> |
31 | #include <TDataStd_HDataMapOfStringReal.hxx> |
32 | #include <TDataStd_HDataMapOfStringString.hxx> |
5a8d30b8 |
33 | |
42cf5bc1 |
34 | #include <TDF_Label.hxx> |
35 | #include <TDF_RelocationTable.hxx> |
7fd59977 |
36 | |
92efcf78 |
37 | IMPLEMENT_STANDARD_RTTIEXT(TDataStd_NamedData,TDF_Attribute) |
38 | |
7fd59977 |
39 | //======================================================================= |
40 | //function : GetID |
41 | //purpose : |
42 | //======================================================================= |
43 | const Standard_GUID& TDataStd_NamedData::GetID() |
44 | { |
45 | static Standard_GUID TDataStd_NamedDataID ("F170FD21-CBAE-4e7d-A4B4-0560A4DA2D16"); |
46 | return TDataStd_NamedDataID; |
47 | } |
48 | |
49 | //======================================================================= |
50 | //function : TDataStd_NamedData |
51 | //purpose : Empty Constructor |
52 | //======================================================================= |
53 | TDataStd_NamedData::TDataStd_NamedData() |
54 | { |
55 | |
56 | } |
57 | |
58 | //======================================================================= |
59 | //function : Set |
60 | //purpose : |
61 | //======================================================================= |
62 | Handle(TDataStd_NamedData) TDataStd_NamedData::Set(const TDF_Label& label) |
63 | { |
64 | Handle(TDataStd_NamedData) A; |
65 | if (!label.FindAttribute (TDataStd_NamedData::GetID(), A)) |
66 | { |
67 | A = new TDataStd_NamedData; |
68 | label.AddAttribute(A); |
69 | } |
70 | return A; |
71 | } |
72 | |
5a8d30b8 |
73 | //======================================================================= |
74 | //function : clear |
75 | //purpose : |
76 | //======================================================================= |
77 | void TDataStd_NamedData::clear() |
78 | { |
79 | myIntegers.Nullify(); |
80 | myReals.Nullify(); |
81 | myStrings.Nullify(); |
82 | myBytes.Nullify(); |
83 | myArraysOfIntegers.Nullify(); |
84 | myArraysOfReals.Nullify(); |
85 | } |
7fd59977 |
86 | |
87 | //Category: Integers |
88 | |
89 | //======================================================================= |
90 | //function : HasInteger |
91 | //purpose : Returns true if the attribute contains this named integer. |
92 | //======================================================================= |
93 | Standard_Boolean TDataStd_NamedData::HasInteger(const TCollection_ExtendedString& theName) const |
94 | { |
95 | if(!HasIntegers()) return Standard_False; |
96 | return myIntegers->Map().IsBound(theName); |
97 | } |
98 | |
99 | //======================================================================= |
100 | //function : GetInteger |
101 | //purpose : Returns the named integer. It returns 0 if there is no such |
102 | // : a named integer(use HasInteger()). |
103 | //======================================================================= |
104 | Standard_Integer TDataStd_NamedData::GetInteger(const TCollection_ExtendedString& theName) |
105 | { |
106 | if(!HasIntegers()) { |
107 | TColStd_DataMapOfStringInteger aMap; |
108 | myIntegers = new TDataStd_HDataMapOfStringInteger(aMap); |
109 | } |
110 | return myIntegers->Map()(theName); |
111 | } |
112 | |
5a8d30b8 |
113 | //======================================================================= |
114 | //function : setInteger |
115 | //purpose : |
116 | //======================================================================= |
117 | void TDataStd_NamedData::setInteger (const TCollection_ExtendedString& theName, |
118 | const Standard_Integer theInteger) |
119 | { |
120 | if (!HasIntegers()) |
121 | { |
122 | TColStd_DataMapOfStringInteger aMap; |
123 | myIntegers = new TDataStd_HDataMapOfStringInteger (aMap); |
124 | } |
125 | myIntegers->ChangeMap().Bind (theName, theInteger); |
126 | } |
127 | |
7fd59977 |
128 | //======================================================================= |
129 | //function : SetInteger |
130 | //purpose : Defines a named integer. If the integer already exists, |
131 | // : it changes its value to <theInteger>. |
132 | //======================================================================= |
133 | void TDataStd_NamedData::SetInteger(const TCollection_ExtendedString& theName, |
134 | const Standard_Integer theInteger) |
135 | { |
5a8d30b8 |
136 | if (!HasIntegers()) |
137 | { |
7fd59977 |
138 | TColStd_DataMapOfStringInteger aMap; |
139 | myIntegers = new TDataStd_HDataMapOfStringInteger(aMap); |
140 | } |
5a8d30b8 |
141 | if (Standard_Integer* aValuePtr = myIntegers->ChangeMap().ChangeSeek (theName)) |
142 | { |
143 | if (*aValuePtr != theInteger) |
144 | { |
145 | Backup(); |
146 | *aValuePtr = theInteger; |
147 | } |
148 | } |
149 | else |
7fd59977 |
150 | { |
151 | Backup(); |
5a8d30b8 |
152 | myIntegers->ChangeMap().Bind (theName, theInteger); |
7fd59977 |
153 | } |
154 | } |
155 | |
156 | //======================================================================= |
157 | //function : GetIntegersContainer |
158 | //purpose : Returns the internal container of named integers. |
159 | // : Use before HasIntegers() |
160 | //======================================================================= |
161 | const TColStd_DataMapOfStringInteger& TDataStd_NamedData::GetIntegersContainer() |
162 | { |
163 | if(!HasIntegers()) { |
164 | TColStd_DataMapOfStringInteger aMap; |
165 | myIntegers = new TDataStd_HDataMapOfStringInteger(aMap); |
166 | } |
167 | return myIntegers->Map(); |
168 | } |
169 | |
170 | //======================================================================= |
171 | //function : ChangeIntegers |
172 | //purpose : Replace the container content by new content of the <theIntegers>. |
173 | //======================================================================= |
174 | void TDataStd_NamedData::ChangeIntegers(const TColStd_DataMapOfStringInteger& theIntegers) |
175 | { |
176 | if(!HasIntegers()) { |
177 | TColStd_DataMapOfStringInteger aMap; |
178 | myIntegers = new TDataStd_HDataMapOfStringInteger(aMap); |
179 | }; |
180 | if (&myIntegers->Map() == &theIntegers) return; |
181 | Backup(); |
182 | myIntegers->ChangeMap().Assign(theIntegers); |
183 | } |
184 | |
185 | |
186 | //Category: Reals |
187 | // ===== |
188 | |
189 | //======================================================================= |
190 | //function : HasReal |
191 | //purpose : Returns true if the attribute contains this named real. |
192 | //======================================================================= |
193 | Standard_Boolean TDataStd_NamedData::HasReal(const TCollection_ExtendedString& theName) const |
194 | { |
195 | if(!HasReals()) return Standard_False; |
196 | return myReals->Map().IsBound(theName); |
197 | } |
198 | |
199 | //======================================================================= |
200 | //function : GetReal |
201 | //purpose : Returns the named real. It returns 0 if there is no such |
202 | // : a named real (use HasReal()). |
203 | //======================================================================= |
204 | Standard_Real TDataStd_NamedData::GetReal(const TCollection_ExtendedString& theName) |
205 | { |
206 | if(!HasReals()) { |
207 | TDataStd_DataMapOfStringReal aMap; |
208 | myReals = new TDataStd_HDataMapOfStringReal(aMap); |
209 | } |
210 | return myReals->Map()(theName); |
211 | } |
212 | |
5a8d30b8 |
213 | //======================================================================= |
214 | //function : setReal |
215 | //purpose : |
216 | //======================================================================= |
217 | void TDataStd_NamedData::setReal (const TCollection_ExtendedString& theName, |
218 | const Standard_Real theReal) |
219 | { |
220 | if (!HasReals()) |
221 | { |
222 | TDataStd_DataMapOfStringReal aMap; |
223 | myReals = new TDataStd_HDataMapOfStringReal (aMap); |
224 | } |
225 | myReals->ChangeMap().Bind (theName, theReal); |
226 | } |
227 | |
7fd59977 |
228 | //======================================================================= |
229 | //function : SetReal |
230 | //purpose : Defines a named real. If the real already exists, |
231 | // : it changes its value to <theReal>. |
232 | //======================================================================= |
233 | void TDataStd_NamedData::SetReal(const TCollection_ExtendedString& theName, |
234 | const Standard_Real theReal) |
235 | { |
5a8d30b8 |
236 | if (!HasReals()) |
237 | { |
7fd59977 |
238 | TDataStd_DataMapOfStringReal aMap; |
239 | myReals = new TDataStd_HDataMapOfStringReal(aMap); |
5a8d30b8 |
240 | } |
241 | if (Standard_Real* aValuePtr = myReals->ChangeMap().ChangeSeek (theName)) |
7fd59977 |
242 | { |
5a8d30b8 |
243 | if (*aValuePtr != theReal) |
244 | { |
245 | Backup(); |
246 | *aValuePtr = theReal; |
247 | } |
248 | } |
249 | else |
250 | { |
251 | myReals->ChangeMap().Bind (theName, theReal); |
7fd59977 |
252 | } |
253 | } |
254 | |
255 | //======================================================================= |
256 | //function : GetRealsContainer |
257 | //purpose : Returns the internal container of named reals. |
258 | //======================================================================= |
259 | const TDataStd_DataMapOfStringReal& TDataStd_NamedData::GetRealsContainer() |
260 | { |
261 | if(!HasReals()) { |
262 | TDataStd_DataMapOfStringReal aMap; |
263 | myReals = new TDataStd_HDataMapOfStringReal(aMap); |
264 | } |
265 | return myReals->Map(); |
266 | } |
267 | |
268 | //======================================================================= |
269 | //function : ChangeReals |
270 | //purpose : Replace the container content by new content of the <theReals>. |
271 | //======================================================================= |
272 | void TDataStd_NamedData::ChangeReals(const TDataStd_DataMapOfStringReal& theReals) |
273 | { |
274 | if(!HasReals()) { |
275 | TDataStd_DataMapOfStringReal aMap; |
276 | myReals = new TDataStd_HDataMapOfStringReal(aMap); |
277 | } |
278 | if (&myReals->Map() == &theReals) return; |
279 | Backup(); |
280 | myReals->ChangeMap().Assign(theReals); |
281 | } |
282 | |
283 | |
284 | //Category: Strings |
285 | // ======= |
286 | //======================================================================= |
287 | //function : HasString |
288 | //purpose : Returns true if the attribute contains this named string. |
289 | //======================================================================= |
290 | Standard_Boolean TDataStd_NamedData::HasString(const TCollection_ExtendedString& theName) const |
291 | { |
292 | if(!HasStrings()) return Standard_False; |
293 | return myStrings->Map().IsBound(theName); |
294 | } |
295 | |
296 | //======================================================================= |
297 | //function : GetString |
298 | //purpose : Returns the named string.It returns empty string if there is |
299 | // : string specified by the Name(use HasString()). |
300 | //======================================================================= |
301 | const TCollection_ExtendedString& TDataStd_NamedData::GetString(const TCollection_ExtendedString& theName) |
302 | { |
303 | if(!HasStrings()) { |
304 | TDataStd_DataMapOfStringString aMap; |
305 | myStrings = new TDataStd_HDataMapOfStringString(aMap); |
306 | } |
307 | return myStrings->Map()(theName); |
308 | } |
309 | |
5a8d30b8 |
310 | //======================================================================= |
311 | //function : SetString |
312 | //purpose : |
313 | //======================================================================= |
314 | void TDataStd_NamedData::setString (const TCollection_ExtendedString& theName, |
315 | const TCollection_ExtendedString& theString) |
316 | { |
317 | if (!HasStrings()) |
318 | { |
319 | TDataStd_DataMapOfStringString aMap; |
320 | myStrings = new TDataStd_HDataMapOfStringString (aMap); |
321 | } |
322 | |
323 | myStrings->ChangeMap().Bind (theName, theString); |
324 | } |
325 | |
7fd59977 |
326 | //======================================================================= |
327 | //function : SetString |
328 | //purpose : Defines a named string. If the string already exists, |
329 | // : it changes its value to <theString>. |
330 | //======================================================================= |
331 | void TDataStd_NamedData::SetString(const TCollection_ExtendedString& theName, |
332 | const TCollection_ExtendedString& theString) |
333 | { |
5a8d30b8 |
334 | if (!HasStrings()) |
335 | { |
7fd59977 |
336 | TDataStd_DataMapOfStringString aMap; |
337 | myStrings = new TDataStd_HDataMapOfStringString(aMap); |
338 | } |
5a8d30b8 |
339 | |
340 | if (TCollection_ExtendedString* aValuePtr = myStrings->ChangeMap().ChangeSeek (theName)) |
341 | { |
342 | if (*aValuePtr != theString) |
343 | { |
344 | Backup(); |
345 | *aValuePtr = theString; |
346 | } |
347 | } |
348 | else |
7fd59977 |
349 | { |
350 | Backup(); |
5a8d30b8 |
351 | myStrings->ChangeMap().Bind(theName, theString); |
7fd59977 |
352 | } |
353 | } |
354 | |
355 | //======================================================================= |
356 | //function : GetStringsContainer |
357 | //purpose : Returns the internal container of named strings. |
358 | //======================================================================= |
359 | const TDataStd_DataMapOfStringString& TDataStd_NamedData::GetStringsContainer() |
360 | { |
361 | if(!HasStrings()) { |
362 | TDataStd_DataMapOfStringString aMap; |
363 | myStrings = new TDataStd_HDataMapOfStringString(aMap); |
364 | } |
365 | return myStrings->Map(); |
366 | } |
367 | |
368 | //======================================================================= |
369 | //function : ChangeStrings |
370 | //purpose : Replace the container content by new content of the <theStrings>. |
371 | //======================================================================= |
372 | void TDataStd_NamedData::ChangeStrings(const TDataStd_DataMapOfStringString& theStrings) |
373 | { |
374 | if(!HasStrings()) { |
375 | TDataStd_DataMapOfStringString aMap; |
376 | myStrings = new TDataStd_HDataMapOfStringString(aMap); |
377 | } |
378 | if (&myStrings->Map() == &theStrings) return; |
379 | Backup(); |
380 | myStrings->ChangeMap().Assign(theStrings); |
381 | } |
382 | |
383 | |
384 | //Category: Bytes |
385 | // ===== |
386 | //======================================================================= |
387 | //function : HasByte |
388 | //purpose : Returns true if the attribute contains this named byte. |
389 | //======================================================================= |
390 | Standard_Boolean TDataStd_NamedData::HasByte(const TCollection_ExtendedString& theName) const |
391 | { |
392 | if(!HasBytes()) return Standard_False; |
393 | return myBytes->Map().IsBound(theName); |
394 | } |
395 | |
396 | //======================================================================= |
397 | //function : GetByte |
398 | //purpose : Returns the named byte. It returns 0 if there is no such |
399 | // : a named byte (use HasByte()). |
400 | //======================================================================= |
401 | Standard_Byte TDataStd_NamedData::GetByte(const TCollection_ExtendedString& theName) |
402 | { |
403 | if(!HasBytes()) { |
404 | TDataStd_DataMapOfStringByte aMap; |
405 | myBytes = new TDataStd_HDataMapOfStringByte(aMap); |
406 | } |
407 | return myBytes->Map()(theName); |
408 | } |
409 | |
5a8d30b8 |
410 | //======================================================================= |
411 | //function : setByte |
412 | //purpose : |
413 | //======================================================================= |
414 | void TDataStd_NamedData::setByte (const TCollection_ExtendedString& theName, |
415 | const Standard_Byte theByte) |
416 | { |
417 | if (!HasBytes()) |
418 | { |
419 | TDataStd_DataMapOfStringByte aMap; |
420 | myBytes = new TDataStd_HDataMapOfStringByte (aMap); |
421 | } |
422 | myBytes->ChangeMap().Bind (theName, theByte); |
423 | } |
424 | |
7fd59977 |
425 | //======================================================================= |
426 | //function : SetByte |
427 | //purpose : Defines a named byte. If the byte already exists, |
428 | // : it changes its value to <theByte>. |
429 | //======================================================================= |
430 | void TDataStd_NamedData::SetByte(const TCollection_ExtendedString& theName, |
431 | const Standard_Byte theByte) |
432 | { |
5a8d30b8 |
433 | if (!HasBytes()) |
434 | { |
7fd59977 |
435 | TDataStd_DataMapOfStringByte aMap; |
5a8d30b8 |
436 | myBytes = new TDataStd_HDataMapOfStringByte (aMap); |
7fd59977 |
437 | } |
5a8d30b8 |
438 | |
439 | if (Standard_Byte* aValuePtr = myBytes->ChangeMap().ChangeSeek (theName)) |
440 | { |
441 | if (*aValuePtr != theByte) |
442 | { |
443 | Backup(); |
444 | *aValuePtr = theByte; |
445 | } |
446 | } |
447 | else |
7fd59977 |
448 | { |
449 | Backup(); |
5a8d30b8 |
450 | myBytes->ChangeMap().Bind (theName, theByte); |
7fd59977 |
451 | } |
452 | } |
453 | |
454 | //======================================================================= |
455 | //function : GetBytesContainer |
456 | //purpose : Returns the internal container of named bytes. |
457 | //======================================================================= |
458 | const TDataStd_DataMapOfStringByte& TDataStd_NamedData::GetBytesContainer() |
459 | { |
460 | if(!HasBytes()) { |
461 | TDataStd_DataMapOfStringByte aMap; |
462 | myBytes = new TDataStd_HDataMapOfStringByte(aMap); |
463 | } |
464 | return myBytes->Map(); |
465 | } |
466 | |
467 | //======================================================================= |
468 | //function : ChangeBytes |
469 | //purpose : Replace the container content by new content of the <theBytes>. |
470 | //======================================================================= |
471 | void TDataStd_NamedData::ChangeBytes(const TDataStd_DataMapOfStringByte& theBytes) |
472 | { |
473 | if(!HasBytes()) { |
474 | TDataStd_DataMapOfStringByte aMap; |
475 | myBytes = new TDataStd_HDataMapOfStringByte(aMap); |
476 | } |
477 | if (&myBytes->Map() == &theBytes) return; |
478 | Backup(); |
479 | myBytes->ChangeMap().Assign(theBytes); |
480 | } |
481 | |
482 | |
483 | //Category: Arrays of integers |
484 | // ================== |
485 | //======================================================================= |
486 | //function : HasArrayOfIntegers |
487 | //purpose : Returns true if the attribute contains this named array |
488 | // : of integer values. |
489 | //======================================================================= |
490 | Standard_Boolean TDataStd_NamedData::HasArrayOfIntegers |
491 | (const TCollection_ExtendedString& theName) const |
492 | { |
493 | if(!HasArraysOfIntegers()) return Standard_False; |
494 | return myArraysOfIntegers->Map().IsBound(theName); |
495 | } |
496 | |
497 | //======================================================================= |
498 | //function : GetArrayOfIntegers |
499 | //purpose : Returns the named array of integer values. It returns a NULL |
500 | // : Handle if there is no such a named array of integers |
501 | //======================================================================= |
502 | const Handle(TColStd_HArray1OfInteger)& TDataStd_NamedData::GetArrayOfIntegers |
503 | (const TCollection_ExtendedString& theName) |
504 | { |
505 | if(!HasArraysOfIntegers()) { |
506 | TDataStd_DataMapOfStringHArray1OfInteger aMap; |
507 | myArraysOfIntegers = new TDataStd_HDataMapOfStringHArray1OfInteger(aMap); |
508 | } |
509 | return myArraysOfIntegers->Map().Find(theName); |
510 | } |
511 | |
512 | //======================================================================= |
5a8d30b8 |
513 | //function : setArrayOfIntegers |
514 | //purpose : |
7fd59977 |
515 | //======================================================================= |
5a8d30b8 |
516 | void TDataStd_NamedData::setArrayOfIntegers (const TCollection_ExtendedString& theName, |
517 | const Handle(TColStd_HArray1OfInteger)& theArrayOfIntegers) |
7fd59977 |
518 | { |
5a8d30b8 |
519 | if (!HasArraysOfIntegers()) |
520 | { |
7fd59977 |
521 | TDataStd_DataMapOfStringHArray1OfInteger aMap; |
5a8d30b8 |
522 | myArraysOfIntegers = new TDataStd_HDataMapOfStringHArray1OfInteger (aMap); |
7fd59977 |
523 | } |
524 | |
5a8d30b8 |
525 | Handle(TColStd_HArray1OfInteger) anArray; |
7fd59977 |
526 | if (!theArrayOfIntegers.IsNull()) |
527 | { |
5a8d30b8 |
528 | // deep copy of the array |
529 | const Standard_Integer aLower = theArrayOfIntegers->Lower(), anUpper = theArrayOfIntegers->Upper(); |
530 | anArray = new TColStd_HArray1OfInteger (aLower, anUpper); |
531 | for (Standard_Integer anIter = aLower; anIter <= anUpper; ++anIter) |
7fd59977 |
532 | { |
5a8d30b8 |
533 | anArray->SetValue (anIter, theArrayOfIntegers->Value (anIter)); |
7fd59977 |
534 | } |
535 | } |
5a8d30b8 |
536 | myArraysOfIntegers->ChangeMap().Bind (theName, anArray); |
7fd59977 |
537 | } |
538 | |
539 | //======================================================================= |
540 | //function : GetArraysOfIntegersContainer |
541 | //purpose : Returns the internal container of named arrays of integer values. |
542 | //======================================================================= |
543 | const TDataStd_DataMapOfStringHArray1OfInteger& TDataStd_NamedData:: |
544 | GetArraysOfIntegersContainer() |
545 | { |
546 | if(!HasArraysOfIntegers()) { |
547 | TDataStd_DataMapOfStringHArray1OfInteger aMap; |
548 | myArraysOfIntegers = new TDataStd_HDataMapOfStringHArray1OfInteger(aMap); |
549 | } |
550 | return myArraysOfIntegers->Map(); |
551 | } |
552 | |
553 | //======================================================================= |
554 | //function : ChangeArraysOfIntegers |
555 | //purpose : Replace the container content by new content of the <theIntegers>. |
556 | //======================================================================= |
557 | void TDataStd_NamedData::ChangeArraysOfIntegers |
558 | (const TDataStd_DataMapOfStringHArray1OfInteger& theIntegers) |
559 | { |
560 | if(!HasArraysOfIntegers()) { |
561 | TDataStd_DataMapOfStringHArray1OfInteger aMap; |
562 | myArraysOfIntegers = new TDataStd_HDataMapOfStringHArray1OfInteger(aMap); |
563 | } |
564 | if (&myArraysOfIntegers->Map() == &theIntegers) return; |
565 | Backup(); |
566 | myArraysOfIntegers->ChangeMap().Assign(theIntegers); |
567 | } |
568 | |
569 | |
570 | //Category: Arrays of reals |
571 | // =============== |
572 | //======================================================================= |
573 | //function : HasArrayOfReals |
574 | //purpose : Returns true if the attribute contains this named array of |
575 | // : real values. |
576 | //======================================================================= |
577 | Standard_Boolean TDataStd_NamedData::HasArrayOfReals |
578 | (const TCollection_ExtendedString& theName) const |
579 | { |
580 | if(!HasArraysOfReals()) return Standard_False; |
581 | return myArraysOfReals->Map().IsBound(theName); |
582 | } |
583 | |
584 | //======================================================================= |
585 | //function : GetArrayOfReals |
586 | //purpose : Returns the named array of real values. It returns a NULL |
587 | // : Handle if there is no such a named array of reals. |
588 | //======================================================================= |
589 | const Handle(TColStd_HArray1OfReal)& TDataStd_NamedData::GetArrayOfReals |
590 | (const TCollection_ExtendedString& theName) |
591 | { |
592 | if(!HasArraysOfReals()) { |
593 | TDataStd_DataMapOfStringHArray1OfReal aMap; |
594 | myArraysOfReals = new TDataStd_HDataMapOfStringHArray1OfReal(aMap); |
595 | } |
596 | return myArraysOfReals->Map().Find(theName); |
597 | } |
598 | |
599 | //======================================================================= |
5a8d30b8 |
600 | //function : setArrayOfReals |
601 | //purpose : |
7fd59977 |
602 | //======================================================================= |
5a8d30b8 |
603 | void TDataStd_NamedData::setArrayOfReals (const TCollection_ExtendedString& theName, |
604 | const Handle(TColStd_HArray1OfReal)& theArrayOfReals) |
7fd59977 |
605 | { |
5a8d30b8 |
606 | if (!HasArraysOfReals()) |
607 | { |
7fd59977 |
608 | TDataStd_DataMapOfStringHArray1OfReal aMap; |
5a8d30b8 |
609 | myArraysOfReals = new TDataStd_HDataMapOfStringHArray1OfReal (aMap); |
7fd59977 |
610 | } |
7fd59977 |
611 | |
5a8d30b8 |
612 | Handle(TColStd_HArray1OfReal) anArray; |
7fd59977 |
613 | if (!theArrayOfReals.IsNull()) |
614 | { |
5a8d30b8 |
615 | // deep copy of the array |
616 | const Standard_Integer aLower = theArrayOfReals->Lower(), anUpper = theArrayOfReals->Upper(); |
617 | anArray = new TColStd_HArray1OfReal (aLower, anUpper); |
618 | for (Standard_Integer anIter = aLower; anIter <= anUpper; ++anIter) |
7fd59977 |
619 | { |
5a8d30b8 |
620 | anArray->SetValue (anIter, theArrayOfReals->Value (anIter)); |
7fd59977 |
621 | } |
622 | } |
5a8d30b8 |
623 | myArraysOfReals->ChangeMap().Bind (theName, anArray); |
7fd59977 |
624 | } |
625 | |
626 | //======================================================================= |
627 | //function : GetArraysOfRealsContainer |
628 | //purpose : Returns the internal container of named arrays of real values. |
629 | //======================================================================= |
630 | const TDataStd_DataMapOfStringHArray1OfReal& TDataStd_NamedData:: |
631 | GetArraysOfRealsContainer() |
632 | { |
633 | if(!HasArraysOfReals()) { |
634 | TDataStd_DataMapOfStringHArray1OfReal aMap; |
635 | myArraysOfReals = new TDataStd_HDataMapOfStringHArray1OfReal(aMap); |
636 | } |
637 | return myArraysOfReals->Map(); |
638 | } |
639 | |
640 | //======================================================================= |
641 | //function : ChangeArraysOfReals |
642 | //purpose : Replace the container content by new content of the <theReals>. |
643 | //======================================================================= |
644 | void TDataStd_NamedData::ChangeArraysOfReals |
645 | (const TDataStd_DataMapOfStringHArray1OfReal& theReals) |
646 | { |
647 | if(!HasArraysOfReals()) { |
648 | TDataStd_DataMapOfStringHArray1OfReal aMap; |
649 | myArraysOfReals = new TDataStd_HDataMapOfStringHArray1OfReal(aMap); |
650 | } |
651 | if (&myArraysOfReals->Map() == &theReals) return; |
652 | Backup(); |
653 | myArraysOfReals->ChangeMap().Assign(theReals); |
654 | } |
655 | |
656 | //======================================================================= |
657 | //function : ID |
658 | //purpose : |
659 | //======================================================================= |
660 | const Standard_GUID& TDataStd_NamedData::ID () const |
661 | { |
662 | return GetID(); |
663 | } |
664 | |
665 | //======================================================================= |
666 | //function : NewEmpty |
667 | //purpose : |
668 | //======================================================================= |
669 | Handle(TDF_Attribute) TDataStd_NamedData::NewEmpty () const |
670 | { |
671 | return new TDataStd_NamedData(); |
672 | } |
673 | |
674 | //======================================================================= |
675 | //function : Restore |
676 | //purpose : |
677 | //======================================================================= |
678 | void TDataStd_NamedData::Restore(const Handle(TDF_Attribute)& With) |
679 | { |
680 | |
681 | Handle(TDataStd_NamedData) ND = Handle(TDataStd_NamedData)::DownCast(With); |
682 | if(ND.IsNull()) return; |
683 | // Integers |
684 | if (!ND->GetIntegersContainer().IsEmpty()) |
685 | { |
686 | if(!HasIntegers()) { |
687 | TColStd_DataMapOfStringInteger aMap; |
688 | myIntegers = new TDataStd_HDataMapOfStringInteger(aMap); |
689 | } |
690 | myIntegers->ChangeMap().Assign(ND->GetIntegersContainer()); |
691 | } |
692 | |
693 | // Reals |
694 | if (!ND->GetRealsContainer().IsEmpty()) |
695 | { |
696 | if(!HasReals()) { |
697 | TDataStd_DataMapOfStringReal aMap; |
698 | myReals = new TDataStd_HDataMapOfStringReal(aMap); |
699 | } |
700 | myReals->ChangeMap().Assign(ND->GetRealsContainer()); |
701 | |
702 | } |
703 | |
704 | // Strings |
705 | if (!ND->GetStringsContainer().IsEmpty()) |
706 | { |
707 | if(!HasStrings()) { |
708 | TDataStd_DataMapOfStringString aMap; |
709 | myStrings = new TDataStd_HDataMapOfStringString(aMap); |
710 | } |
711 | myStrings->ChangeMap().Assign(ND->GetStringsContainer()); |
712 | |
713 | } |
714 | |
715 | // Bytes |
716 | if (!ND->GetBytesContainer().IsEmpty()) |
717 | { |
718 | if(!HasBytes()) { |
719 | TDataStd_DataMapOfStringByte aMap; |
720 | myBytes = new TDataStd_HDataMapOfStringByte(aMap); |
721 | } |
722 | myBytes->ChangeMap().Assign(ND->GetBytesContainer()); |
723 | |
724 | } |
725 | |
726 | // Arrays of integers |
727 | if (!ND->GetArraysOfIntegersContainer().IsEmpty()) |
728 | { |
729 | if(!HasArraysOfIntegers()) { |
730 | TDataStd_DataMapOfStringHArray1OfInteger aMap; |
731 | myArraysOfIntegers = new TDataStd_HDataMapOfStringHArray1OfInteger(aMap); |
732 | } |
733 | TDataStd_DataMapIteratorOfDataMapOfStringHArray1OfInteger itr(ND->GetArraysOfIntegersContainer()); |
734 | for (; itr.More(); itr.Next()) |
735 | { |
736 | // Deep copy of the arrays |
737 | const Handle(TColStd_HArray1OfInteger)& ints = itr.Value(); |
738 | Handle(TColStd_HArray1OfInteger) copied_ints; |
739 | if (!ints.IsNull()) |
740 | { |
741 | Standard_Integer lower = ints->Lower(), i = lower, upper = ints->Upper(); |
742 | copied_ints = new TColStd_HArray1OfInteger(lower, upper); |
743 | for (; i <= upper; i++) |
744 | { |
745 | copied_ints->SetValue(i, ints->Value(i)); |
746 | } |
747 | } |
748 | myArraysOfIntegers->ChangeMap().Bind(itr.Key(), copied_ints); |
749 | } |
750 | } |
751 | |
752 | // Arrays of realss |
753 | if (!ND->GetArraysOfRealsContainer().IsEmpty()) |
754 | { |
755 | if(!HasArraysOfReals()) { |
756 | TDataStd_DataMapOfStringHArray1OfReal aMap; |
757 | myArraysOfReals = new TDataStd_HDataMapOfStringHArray1OfReal(aMap); |
758 | } |
759 | TDataStd_DataMapIteratorOfDataMapOfStringHArray1OfReal itr(ND->GetArraysOfRealsContainer()); |
760 | for (; itr.More(); itr.Next()) |
761 | { |
762 | // Deep copy of the arrays |
763 | const Handle(TColStd_HArray1OfReal)& dbls = itr.Value(); |
764 | Handle(TColStd_HArray1OfReal) copied_dbls; |
765 | if (!dbls.IsNull()) |
766 | { |
767 | Standard_Integer lower = dbls->Lower(), i = lower, upper = dbls->Upper(); |
768 | copied_dbls = new TColStd_HArray1OfReal(lower, upper); |
769 | for (; i <= upper; i++) |
770 | { |
771 | copied_dbls->SetValue(i, dbls->Value(i)); |
772 | } |
773 | } |
774 | myArraysOfReals->ChangeMap().Bind(itr.Key(), copied_dbls); |
775 | } |
776 | } |
777 | } |
778 | |
779 | //======================================================================= |
780 | //function : Paste |
781 | //purpose : |
782 | //======================================================================= |
783 | void TDataStd_NamedData::Paste (const Handle(TDF_Attribute)& Into, |
784 | const Handle(TDF_RelocationTable)& ) const |
785 | { |
786 | Handle(TDataStd_NamedData) ND = Handle(TDataStd_NamedData)::DownCast(Into); |
787 | if (ND.IsNull()) return; |
788 | |
789 | // Integers |
790 | if (HasIntegers() && !myIntegers->Map().IsEmpty()) |
791 | { |
792 | if(!ND->HasIntegers()) { |
793 | TColStd_DataMapOfStringInteger aMap; |
794 | ND->myIntegers = new TDataStd_HDataMapOfStringInteger(aMap); |
795 | }; |
796 | ND->myIntegers->ChangeMap().Assign(myIntegers->Map()); |
797 | } |
798 | |
799 | // Reals |
800 | if (HasReals() && !myReals->Map().IsEmpty()) |
801 | { |
802 | if(!ND->HasReals()) { |
803 | TDataStd_DataMapOfStringReal aMap; |
804 | ND->myReals = new TDataStd_HDataMapOfStringReal(aMap); |
805 | }; |
806 | ND->myReals->ChangeMap().Assign(myReals->Map()); |
807 | |
808 | } |
809 | |
810 | // Strings |
811 | if (HasStrings() && !myStrings->Map().IsEmpty()) |
812 | { |
813 | if(!ND->HasStrings()) { |
814 | TDataStd_DataMapOfStringString aMap; |
815 | ND->myStrings = new TDataStd_HDataMapOfStringString(aMap); |
816 | }; |
817 | ND->myStrings->ChangeMap().Assign(myStrings->Map()); |
818 | } |
819 | |
820 | // Bytes |
821 | if (HasBytes() && !myBytes->Map().IsEmpty()) |
822 | { |
823 | if(!ND->HasBytes()) { |
824 | TDataStd_DataMapOfStringByte aMap; |
825 | ND->myBytes = new TDataStd_HDataMapOfStringByte(aMap); |
826 | }; |
827 | ND->myBytes->ChangeMap().Assign(myBytes->Map()); |
828 | } |
829 | |
830 | // Arrays of integers |
831 | if (HasArraysOfIntegers() && !myArraysOfIntegers->Map().IsEmpty()) |
832 | { |
833 | if(!ND->HasArraysOfIntegers()) { |
834 | TDataStd_DataMapOfStringHArray1OfInteger aMap; |
835 | ND->myArraysOfIntegers = new TDataStd_HDataMapOfStringHArray1OfInteger(aMap); |
836 | } |
837 | |
838 | TDataStd_DataMapIteratorOfDataMapOfStringHArray1OfInteger itr(myArraysOfIntegers->Map()); |
839 | for (; itr.More(); itr.Next()) |
840 | { |
841 | const Handle(TColStd_HArray1OfInteger)& ints = itr.Value(); |
842 | Handle(TColStd_HArray1OfInteger) copied_ints; |
843 | if (!ints.IsNull()) |
844 | { |
845 | Standard_Integer lower = ints->Lower(), i = lower, upper = ints->Upper(); |
846 | copied_ints = new TColStd_HArray1OfInteger(lower, upper); |
847 | for (; i <= upper; i++) |
848 | { |
849 | copied_ints->SetValue(i, ints->Value(i)); |
850 | } |
851 | } |
852 | ND->myArraysOfIntegers->ChangeMap().Bind(itr.Key(), copied_ints); |
853 | } |
854 | } |
855 | |
856 | // Arrays of reals |
857 | if (HasArraysOfReals() && !myArraysOfReals->Map().IsEmpty()) |
858 | { |
859 | if(!ND->HasArraysOfReals()) { |
860 | TDataStd_DataMapOfStringHArray1OfReal aMap; |
861 | ND->myArraysOfReals = new TDataStd_HDataMapOfStringHArray1OfReal(aMap); |
862 | } |
863 | TDataStd_DataMapIteratorOfDataMapOfStringHArray1OfReal itr(myArraysOfReals->Map()); |
864 | for (; itr.More(); itr.Next()) |
865 | { |
866 | const Handle(TColStd_HArray1OfReal)& dbls = itr.Value(); |
867 | Handle(TColStd_HArray1OfReal) copied_dbls; |
868 | if (!dbls.IsNull()) |
869 | { |
870 | Standard_Integer lower = dbls->Lower(), i = lower, upper = dbls->Upper(); |
871 | copied_dbls = new TColStd_HArray1OfReal(lower, upper); |
872 | for (; i <= upper; i++) |
873 | { |
874 | copied_dbls->SetValue(i, dbls->Value(i)); |
875 | } |
876 | } |
877 | ND->myArraysOfReals->ChangeMap().Bind(itr.Key(), copied_dbls); |
878 | } |
879 | } |
880 | } |
881 | |
882 | //======================================================================= |
883 | //function : Dump |
884 | //purpose : |
885 | //======================================================================= |
886 | Standard_OStream& TDataStd_NamedData::Dump (Standard_OStream& anOS) const |
887 | { |
888 | anOS << "NamedData: "; |
bd0b3e60 |
889 | anOS << "\tIntegers = " << (HasIntegers() ? myIntegers->Map().Extent() : 0); |
890 | anOS << "\tReals = " << (HasReals() ? myReals->Map().Extent() : 0); |
891 | anOS << "\tStrings = " << (HasStrings() ? myStrings->Map().Extent() : 0); |
892 | anOS << "\tBytes = " << (HasBytes() ? myBytes->Map().Extent() : 0); |
893 | anOS << "\tArraysOfIntegers = " << (HasArraysOfIntegers() ? myArraysOfIntegers->Map().Extent() : 0); |
894 | anOS << "\tArraysOfReals = " << (HasArraysOfReals() ? myArraysOfReals->Map().Extent() : 0); |
7fd59977 |
895 | return anOS; |
896 | } |
bc73b006 |
897 | |
898 | //======================================================================= |
899 | //function : DumpJson |
900 | //purpose : |
901 | //======================================================================= |
902 | void TDataStd_NamedData::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const |
903 | { |
904 | OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream) |
905 | |
906 | OCCT_DUMP_BASE_CLASS (theOStream, theDepth, TDF_Attribute) |
907 | |
908 | if (!myIntegers.IsNull()) |
909 | OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myIntegers->Map().Size()) |
910 | if (!myReals.IsNull()) |
911 | OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myReals->Map().Size()) |
912 | if (!myStrings.IsNull()) |
913 | OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myStrings->Map().Size()) |
914 | if (!myBytes.IsNull()) |
915 | OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myBytes->Map().Size()) |
916 | if (!myArraysOfIntegers.IsNull()) |
917 | OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myArraysOfIntegers->Map().Size()) |
918 | if (!myArraysOfReals.IsNull()) |
919 | OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myArraysOfReals->Map().Size()) |
920 | } |