0022922: Clean up warnings on uninitialized / unused variables
[occt.git] / src / XmlMDataStd / XmlMDataStd_NamedDataDriver.cxx
CommitLineData
7fd59977 1// File: XmlMDataStd_NamedDataDriver.cxx
2// Created: Tue Jul 3 11:17:43 2007
3// Author: Sergey ZARITCHNY
4// <sergey.zaritchny@opencascade.com>
5// Copyright: Open CasCade SA 2007
6
7#include <XmlMDataStd_NamedDataDriver.ixx>
8#include <XmlObjMgt.hxx>
9#include <XmlObjMgt_Document.hxx>
10#include <LDOM_MemManager.hxx>
11#include <TCollection_ExtendedString.hxx>
12#include <CDM_MessageDriver.hxx>
13#include <TDataStd_NamedData.hxx>
14#include <TColStd_HArray1OfReal.hxx>
15#include <TColStd_HArray1OfInteger.hxx>
16#include <TColStd_HArray1OfReal.hxx>
17#include <TColStd_DataMapOfStringInteger.hxx>
18#include <TDataStd_DataMapOfStringReal.hxx>
19#include <TDataStd_DataMapOfStringString.hxx>
20#include <TDataStd_DataMapOfStringByte.hxx>
21#include <TDataStd_DataMapOfStringHArray1OfInteger.hxx>
22#include <TDataStd_DataMapOfStringHArray1OfReal.hxx>
23#include <TColStd_DataMapIteratorOfDataMapOfStringInteger.hxx>
24#include <TDataStd_DataMapIteratorOfDataMapOfStringReal.hxx>
25#include <TDataStd_DataMapIteratorOfDataMapOfStringString.hxx>
26#include <TDataStd_DataMapIteratorOfDataMapOfStringByte.hxx>
27#include <TDataStd_DataMapIteratorOfDataMapOfStringHArray1OfInteger.hxx>
28#include <TDataStd_DataMapIteratorOfDataMapOfStringHArray1OfReal.hxx>
29IMPLEMENT_DOMSTRING (FirstIntegerIndex, "firstI")
30IMPLEMENT_DOMSTRING (LastIntegerIndex, "lastI")
31IMPLEMENT_DOMSTRING (FirstRealIndex, "firstR")
32IMPLEMENT_DOMSTRING (LastRealIndex, "lastR")
33IMPLEMENT_DOMSTRING (FirstStringIndex, "firstS")
34IMPLEMENT_DOMSTRING (LastStringIndex, "lastS")
35IMPLEMENT_DOMSTRING (FirstByteIndex, "firstB")
36IMPLEMENT_DOMSTRING (LastByteIndex, "lastB")
37IMPLEMENT_DOMSTRING (FirstIntArrIndex, "firstIA")
38IMPLEMENT_DOMSTRING (LastIntArrIndex, "lastIA")
39IMPLEMENT_DOMSTRING (FirstRealArrIndex, "firstRA")
40IMPLEMENT_DOMSTRING (LastRealArrIndex, "lastRA")
41
42IMPLEMENT_DOMSTRING (ExtString, "string")
43IMPLEMENT_DOMSTRING (Value, "value")
44
45#define OCC6010
46
47#ifdef WNT
48#define EXCEPTION ...
49#else
50#define EXCEPTION Standard_Failure
51#endif
52//=======================================================================
53//function : XmlMDataStd_NamedDataDriver
54//purpose : Constructor
55//=======================================================================
56XmlMDataStd_NamedDataDriver::XmlMDataStd_NamedDataDriver(const Handle(CDM_MessageDriver)& theMsgDriver)
57 : XmlMDF_ADriver (theMsgDriver, NULL)
58{
59
60}
61
62//=======================================================================
63//function : NewEmpty
64//purpose :
65//=======================================================================
66Handle(TDF_Attribute) XmlMDataStd_NamedDataDriver::NewEmpty() const
67{
68 return new TDataStd_NamedData();
69}
70
71//=======================================================================
72static TCollection_ExtendedString SplitItemFromEnd(TCollection_ExtendedString& Key)
73{
74 TCollection_ExtendedString aValue;
75 const Standard_Integer aPos = Key. SearchFromEnd (" ");
76 if(aPos == -1) return aValue;
77 aValue = Key.Split(aPos-1);
78 aValue.Remove(1,1);
79 return aValue;
80}
81//=======================================================================
82static TCollection_ExtendedString SplitItemFromStart(TCollection_ExtendedString& Key)
83{
84 TCollection_ExtendedString aValue;
85 const Standard_Integer aPos = Key. Search (" ");
86 if(aPos == -1) return aValue;
87 aValue = Key.Split(aPos);
88 Key.Remove(Key.Length(),1);
89 return aValue;
90}
91//=======================================================================
92Handle(TColStd_HArray1OfInteger) BuildIntArray(const TCollection_AsciiString& ValString,
93 const Standard_Integer theLen)
94{
95 Handle(TColStd_HArray1OfInteger) anArr;
96 if(ValString.Length() == 0 || !theLen) return anArr;
97 anArr = new TColStd_HArray1OfInteger (1, theLen, 0);
98 for(Standard_Integer i = 1;i <= theLen;i++) {
99 const TCollection_AsciiString& aSVal = ValString.Token(" ",i);
100 if(aSVal.Length())
101 anArr->SetValue(i, aSVal.IntegerValue());
102 }
103 return anArr;
104}
105
106//=======================================================================
107Handle(TColStd_HArray1OfReal) BuildRealArray(const TCollection_AsciiString& ValString,
108 const Standard_Integer theLen)
109{
110 Handle(TColStd_HArray1OfReal) anArr;
111 if(ValString.Length() == 0 || !theLen) return anArr;
112 anArr = new TColStd_HArray1OfReal (1, theLen, .0);
113 for(Standard_Integer i = 1;i <= theLen;i++) {
114 const TCollection_AsciiString& aSVal = ValString.Token(" ",i);
115 if(aSVal.Length())
116 anArr->SetValue(i, aSVal.RealValue());
117 }
118 return anArr;
119}
120//=======================================================================
121//function : Paste
122//purpose : persistent -> transient (retrieve)
123//=======================================================================
124Standard_Boolean XmlMDataStd_NamedDataDriver::Paste(const XmlObjMgt_Persistent& theSource,
125 const Handle(TDF_Attribute)& theTarget,
126 XmlObjMgt_RRelocationTable& ) const
127{
6e6cd5d9 128 Standard_Integer aFirstInd, aLastInd, ind;
7fd59977 129 const XmlObjMgt_Element& anElement = theSource;
130
131 //DataMapOfStringInteger: Read the FirstIndex; if the attribute is absent initialize to 1
132 XmlObjMgt_DOMString aFirstIndex = anElement.getAttribute(::FirstIntegerIndex());
133 if (aFirstIndex == NULL)
134 aFirstInd = 1;
135 else if (!aFirstIndex.GetInteger(aFirstInd))
136 {
137 TCollection_ExtendedString aMessageString =
138 TCollection_ExtendedString("Cannot retrieve the first index for NamedData"
139 " attribute (DataMapOfStringInteger) as \"")
140 + aFirstIndex + "\"";
141 WriteMessage (aMessageString);
142 return Standard_False;
143 }
144
145 // Read the LastIndex;
146 XmlObjMgt_DOMString aLastIndex = anElement.getAttribute(::LastIntegerIndex());
147 if(aLastIndex == NULL) {
148 aFirstInd = 0;
149 aLastInd = 0;
150 } else if (!aLastIndex.GetInteger(aLastInd)) {
151 TCollection_ExtendedString aMessageString =
152 TCollection_ExtendedString("Cannot retrieve the last index for NamedData"
153 " attribute (DataMapOfStringInteger) as \"")
154 + aLastIndex + "\"";
155 WriteMessage (aMessageString);
156 return Standard_False;
157 }
158 try {
159 Handle(TDataStd_NamedData) T = Handle(TDataStd_NamedData)::DownCast(theTarget);
160 LDOM_Node aCurNode;
161
162 if((aFirstInd | aLastInd) && aLastInd >= aFirstInd) {
163 if ( !anElement.hasChildNodes() )
164 {
165 TCollection_ExtendedString aMessageString =
166 TCollection_ExtendedString("Cannot retrieve DataMapOfStringInteger");
167 WriteMessage (aMessageString);
168 return Standard_False;
169 }
170 aCurNode = anElement.getFirstChild();
171 LDOM_Element* aCurElement = (LDOM_Element*)&aCurNode;
172 TCollection_ExtendedString aValueStr, aKey;
173 TColStd_DataMapOfStringInteger aMap;
174 for (ind = aFirstInd; ind < aLastInd; ind++) {
175 XmlObjMgt::GetExtendedString( *aCurElement, aKey );
176 aValueStr = SplitItemFromEnd(aKey);
177 if(aValueStr.Length() == 0) {
178 TCollection_ExtendedString aMessageString =
179 TCollection_ExtendedString("Cannot retrieve a value from item = ") + aKey;
180 WriteMessage (aMessageString);
181 return Standard_False;
182 }
183 TCollection_AsciiString aVal(aValueStr,'?');
184 Standard_Integer aValue = aVal.IntegerValue();
185 aMap.Bind(aKey, aValue);
186 aCurNode = aCurElement->getNextSibling();
187 aCurElement = (LDOM_Element*)&aCurNode;
188 }
189 XmlObjMgt::GetExtendedString( *aCurElement, aKey );
190 aValueStr = SplitItemFromEnd(aKey);
191 if(aValueStr.Length() == 0) {
192 TCollection_ExtendedString aMessageString =
193 TCollection_ExtendedString("Cannot retrieve a value from item = ") + aKey;
194 WriteMessage (aMessageString);
195 return Standard_False;
196 }
197 TCollection_AsciiString aVal(aValueStr,'?');
198 Standard_Integer aValue = aVal.IntegerValue();
199 aMap.Bind(aKey, aValue);
200 T->ChangeIntegers(aMap);
201 }
202
203//DataMapOfStringReal
204 aFirstIndex = anElement.getAttribute(::FirstRealIndex());
205 if (aFirstIndex == NULL)
206 aFirstInd = 1;
207 else if (!aFirstIndex.GetInteger(aFirstInd))
208 {
209 TCollection_ExtendedString aMessageString =
210 TCollection_ExtendedString("Cannot retrieve the first index for NamedData "
211 "attribute (DataMapOfStringReal) as \"")
212 + aFirstIndex + "\"";
213 WriteMessage (aMessageString);
214 return Standard_False;
215 }
216
217 // Read the LastIndex;
218 aLastIndex = anElement.getAttribute(::LastRealIndex());
219 if(aLastIndex == NULL) {
220 aFirstInd = 0;
221 aLastInd = 0;
222 } else if (!aLastIndex.GetInteger(aLastInd)) {
223 TCollection_ExtendedString aMessageString =
224 TCollection_ExtendedString("Cannot retrieve the last index for NamedData"
225 " attribute (DataMapOfStringReal) as \"")
226 + aLastIndex + "\"";
227 WriteMessage (aMessageString);
228 return Standard_False;
229 }
230
231 if((aFirstInd | aLastInd) && aLastInd >= aFirstInd) {
232 if ( !anElement.hasChildNodes())
233 {
234 TCollection_ExtendedString aMessageString =
235 TCollection_ExtendedString("Cannot retrieve DataMapOfStringReal");
236 WriteMessage (aMessageString);
237 return Standard_False;
238 }
239
240 LDOM_Element* aCurElement;
241 if (aCurNode.isNull())
242 aCurNode = anElement.getFirstChild();
243 else
244 aCurNode = aCurElement->getNextSibling();
245
246 aCurElement = (LDOM_Element*)&aCurNode;
247 TCollection_ExtendedString aValueStr, aKey;
248 TDataStd_DataMapOfStringReal aMap;
249 for (ind = aFirstInd; ind < aLastInd; ind++) {
250 XmlObjMgt::GetExtendedString( *aCurElement, aKey );
251 aValueStr = SplitItemFromEnd(aKey);
252 if(aValueStr.Length() == 0) {
253 TCollection_ExtendedString aMessageString =
254 TCollection_ExtendedString("Cannot retrieve a value from item = ") + aKey;
255 WriteMessage (aMessageString);
256 return Standard_False;
257 }
258 TCollection_AsciiString aVal(aValueStr,'?');
259 Standard_Real aValue = aVal.RealValue();
260 aMap.Bind(aKey, aValue);
261 aCurNode = aCurElement->getNextSibling();
262 aCurElement = (LDOM_Element*)&aCurNode;
263 }
264 XmlObjMgt::GetExtendedString( *aCurElement, aKey );
265 aValueStr = SplitItemFromEnd(aKey);
266 if(aValueStr.Length() == 0) {
267 TCollection_ExtendedString aMessageString =
268 TCollection_ExtendedString("Cannot retrieve a value from item = ") + aKey;
269 WriteMessage (aMessageString);
270 return Standard_False;
271 }
272 TCollection_AsciiString aVal(aValueStr,'?');
273 Standard_Real aValue = aVal.RealValue();
274 aMap.Bind(aKey, aValue);
275 T->ChangeReals(aMap);
276 }
277
278//DataMapOfStringString
279 aFirstIndex = anElement.getAttribute(::FirstStringIndex());
280 if (aFirstIndex == NULL)
281 aFirstInd = 1;
282 else if (!aFirstIndex.GetInteger(aFirstInd))
283 {
284 TCollection_ExtendedString aMessageString =
285 TCollection_ExtendedString("Cannot retrieve the first index for NamedData"
286 " attribute (DataMapOfStringString) as \"")
287 + aFirstIndex + "\"";
288 WriteMessage (aMessageString);
289 return Standard_False;
290 }
291 aLastIndex = anElement.getAttribute(::LastStringIndex());
292 if(aLastIndex == NULL) {
293 aFirstInd = 0;
294 aLastInd = 0;
295 } else if (!aLastIndex.GetInteger(aLastInd)) {
296 TCollection_ExtendedString aMessageString =
297 TCollection_ExtendedString("Cannot retrieve the last index for NamedData"
298 " attribute (DataMapOfStringString) as \"")
299 + aLastIndex + "\"";
300 WriteMessage (aMessageString);
301 return Standard_False;
302 }
303
304 if((aFirstInd | aLastInd) && aLastInd >= aFirstInd) {
305 if ( !anElement.hasChildNodes())
306 {
307 TCollection_ExtendedString aMessageString =
308 TCollection_ExtendedString("Cannot retrieve DataMapOfStringString");
309 WriteMessage (aMessageString);
310 return Standard_False;
311 }
312 LDOM_Element* aCurElement;
313 if (aCurNode.isNull())
314 aCurNode = anElement.getFirstChild();
315 else
316 aCurNode = aCurElement->getNextSibling();
317
318 aCurElement = (LDOM_Element*)&aCurNode;
319 TCollection_ExtendedString aValue, aKey;
320 TDataStd_DataMapOfStringString aMap;
321 for (ind = aFirstInd; ind < aLastInd; ind++) {
322 XmlObjMgt::GetExtendedString( *aCurElement, aKey );
323 aValue = SplitItemFromStart(aKey); // ==>from start
324 if(aValue.Length() == 0) {
325 TCollection_ExtendedString aMessageString =
326 TCollection_ExtendedString("Cannot retrieve a value from item = ") + aKey;
327 WriteMessage (aMessageString);
328 return Standard_False;
329 }
330 aMap.Bind(aKey, aValue);
331 aCurNode = aCurElement->getNextSibling();
332 aCurElement = (LDOM_Element*)&aCurNode;
333 }
334 XmlObjMgt::GetExtendedString( *aCurElement, aKey );
335 aValue = SplitItemFromStart(aKey);
336 if(aValue.Length() == 0) {
337 TCollection_ExtendedString aMessageString =
338 TCollection_ExtendedString("Cannot retrieve a value from item = ") + aKey;
339 WriteMessage (aMessageString);
340 return Standard_False;
341 }
342
343 aMap.Bind(aKey, aValue);
344 T->ChangeStrings(aMap);
345 }
346
347//DataMapOfStringByte
348 aFirstIndex = anElement.getAttribute(::FirstByteIndex());
349 if (aFirstIndex == NULL)
350 aFirstInd = 1;
351 else if (!aFirstIndex.GetInteger(aFirstInd))
352 {
353 TCollection_ExtendedString aMessageString =
354 TCollection_ExtendedString("Cannot retrieve the first index for NamedData "
355 "attribute (DataMapOfStringByte) as \"")
356 + aFirstIndex + "\"";
357 WriteMessage (aMessageString);
358 return Standard_False;
359 }
360
361 // Read the LastIndex;
362 aLastIndex = anElement.getAttribute(::LastByteIndex());
363 if(aLastIndex == NULL) {
364 aFirstInd = 0;
365 aLastInd = 0;
366 } else if (!aLastIndex.GetInteger(aLastInd)) {
367 TCollection_ExtendedString aMessageString =
368 TCollection_ExtendedString("Cannot retrieve the last index for NamedData"
369 " attribute (DataMapOfStringByte) as \"")
370 + aLastIndex + "\"";
371 WriteMessage (aMessageString);
372 return Standard_False;
373 }
374
375 if((aFirstInd | aLastInd) && aLastInd >= aFirstInd) {
376 if ( !anElement.hasChildNodes())
377 {
378 TCollection_ExtendedString aMessageString =
379 TCollection_ExtendedString("Cannot retrieve DataMapOfStringByte");
380 WriteMessage (aMessageString);
381 return Standard_False;
382 }
383
384 LDOM_Element* aCurElement;
385 if (aCurNode.isNull())
386 aCurNode = anElement.getFirstChild();
387 else
388 aCurNode = aCurElement->getNextSibling();
389
390 aCurElement = (LDOM_Element*)&aCurNode;
391 TCollection_ExtendedString aValueStr, aKey;
392 TDataStd_DataMapOfStringByte aMap;
393 for (ind = aFirstInd; ind < aLastInd; ind++) {
394 XmlObjMgt::GetExtendedString( *aCurElement, aKey );
395 aValueStr = SplitItemFromEnd(aKey);
396 if(aValueStr.Length() == 0) {
397 TCollection_ExtendedString aMessageString =
398 TCollection_ExtendedString("Cannot retrieve a value from item = ") + aKey;
399 WriteMessage (aMessageString);
400 return Standard_False;
401 }
402
403 TCollection_AsciiString aVal(aValueStr,'?');
404 Standard_Byte aValue = (Standard_Byte)aVal.IntegerValue();
405
406 aMap.Bind(aKey, aValue);
407 aCurNode = aCurElement->getNextSibling();
408 aCurElement = (LDOM_Element*)&aCurNode;
409 }
410 XmlObjMgt::GetExtendedString( *aCurElement, aKey );
411 aValueStr = SplitItemFromEnd(aKey);
412 if(aValueStr.Length() == 0) {
413 TCollection_ExtendedString aMessageString =
414 TCollection_ExtendedString("Cannot retrieve a value from item = ") + aKey;
415 WriteMessage (aMessageString);
416 return Standard_False;
417 }
418
419 TCollection_AsciiString aVal(aValueStr,'?');
420 Standard_Byte aValue = (Standard_Byte)aVal.IntegerValue();
421 aMap.Bind(aKey, aValue);
422 T->ChangeBytes(aMap);
423 }
424
425//DataMapOfStringHArray1OfInteger
426 aFirstIndex = anElement.getAttribute(::FirstIntArrIndex());
427 if (aFirstIndex == NULL)
428 aFirstInd = 1;
429 else if (!aFirstIndex.GetInteger(aFirstInd))
430 {
431 TCollection_ExtendedString aMessageString =
432 TCollection_ExtendedString("Cannot retrieve the first index for NamedData "
433 "attribute (DataMapOfStringHArray1OfInteger) as \"")
434 + aFirstIndex + "\"";
435 WriteMessage (aMessageString);
436 return Standard_False;
437 }
438
439 // Read the LastIndex;
440 aLastIndex = anElement.getAttribute(::LastIntArrIndex());
441 if(aLastIndex == NULL) {
442 aFirstInd = 0;
443 aLastInd = 0;
444 } else if (!aLastIndex.GetInteger(aLastInd)) {
445 TCollection_ExtendedString aMessageString =
446 TCollection_ExtendedString("Cannot retrieve the last index for NamedData"
447 " attribute (DataMapOfStringHArray1OfInteger) as \"")
448 + aLastIndex + "\"";
449 WriteMessage (aMessageString);
450 return Standard_False;
451 }
452
453 if((aFirstInd | aLastInd) && aLastInd >= aFirstInd) {
454 if ( !anElement.hasChildNodes())
455 {
456 TCollection_ExtendedString aMessageString =
457 TCollection_ExtendedString("Cannot retrieve DataMapOfStringHArray1OfInteger");
458 WriteMessage (aMessageString);
459 return Standard_False;
460 }
461 LDOM_Element* aCurElement;
462 if (aCurNode.isNull())
463 aCurNode = anElement.getFirstChild();
464 else
465 aCurNode = aCurElement->getNextSibling();
466
467 aCurElement = (LDOM_Element*)&aCurNode;
468 TCollection_ExtendedString aKey, aValueStr;
469 TDataStd_DataMapOfStringHArray1OfInteger aMap;
470
471 for (ind = aFirstInd; ind < aLastInd; ind++) {
472 XmlObjMgt::GetExtendedString( *aCurElement, aKey );// Len - at the end
473 aValueStr = SplitItemFromEnd(aKey);
474 if(aValueStr.Length() == 0) {
475 TCollection_ExtendedString aMessageString =
476 TCollection_ExtendedString("Cannot retrieve a value from item = ") + aKey;
477 WriteMessage (aMessageString);
478 return Standard_False;
479 }
480 TCollection_AsciiString aVal(aValueStr,'?');
481 Standard_Integer aLen = aVal.IntegerValue();
482
483#ifdef DEB
484// XmlObjMgt_DOMString aValStr = aCurElement->getAttribute(::Value());
485// const char* aS = aValStr.GetString();
486// cout << " Key = " << TCollection_AsciiString(aKey, '?') << " aValue = " << aS << endl;
487#endif
488
489 TCollection_AsciiString aValueString = aCurElement->getAttribute(::Value());
490 Handle(TColStd_HArray1OfInteger) aValue = BuildIntArray(aValueString, aLen);
491 if(aValue.IsNull()) {
492 TCollection_ExtendedString aMessageString =
493 TCollection_ExtendedString("Cannot retrieve a value from item = ") + aKey;
494 WriteMessage (aMessageString);
495 return Standard_False;
496 }
497
498 aMap.Bind(aKey, aValue);
499 aCurNode = aCurElement->getNextSibling();
500 aCurElement = (LDOM_Element*)&aCurNode;
501 }
502
503 XmlObjMgt::GetExtendedString( *aCurElement, aKey );
504 aValueStr = SplitItemFromEnd(aKey);
505 if(aValueStr.Length() == 0) {
506 TCollection_ExtendedString aMessageString =
507 TCollection_ExtendedString("Cannot retrieve a value from item = ") + aKey;
508 WriteMessage (aMessageString);
509 return Standard_False;
510 }
511 TCollection_AsciiString aVal(aValueStr,'?');
512 Standard_Integer aLen = aVal.IntegerValue();
513#ifdef DEB
514// XmlObjMgt_DOMString aValStr = aCurElement->getAttribute(::Value());
515// const char* aS = aValStr.GetString();
516// cout << " Key = " << TCollection_AsciiString(aKey, '?') << " aValue = " <<aS<<endl;
517#endif
518 TCollection_AsciiString aValueString = aCurElement->getAttribute(::Value());
519 Handle(TColStd_HArray1OfInteger) aValue = BuildIntArray(aValueString, aLen);
520 if(aValue.IsNull()) {
521 TCollection_ExtendedString aMessageString =
522 TCollection_ExtendedString("Cannot retrieve a value from item = ") + aKey;
523 WriteMessage (aMessageString);
524 return Standard_False;
525 }
526 aMap.Bind(aKey, aValue);
527 T->ChangeArraysOfIntegers(aMap);
528 }
529
530//DataMapOfStringHArray1OfReal
531 aFirstIndex = anElement.getAttribute(::FirstRealArrIndex());
532 if (aFirstIndex == NULL)
533 aFirstInd = 1;
534 else if (!aFirstIndex.GetInteger(aFirstInd))
535 {
536 TCollection_ExtendedString aMessageString =
537 TCollection_ExtendedString("Cannot retrieve the first index for NamedData "
538 "attribute (DataMapOfStringHArray1OfReal) as \"")
539 + aFirstIndex + "\"";
540 WriteMessage (aMessageString);
541 return Standard_False;
542 }
543
544 // Read the LastIndex;
545 aLastIndex = anElement.getAttribute(::LastRealArrIndex());
546 if(aLastIndex == NULL) {
547 aFirstInd = 0;
548 aLastInd = 0;
549 } else if (!aLastIndex.GetInteger(aLastInd)) {
550 TCollection_ExtendedString aMessageString =
551 TCollection_ExtendedString("Cannot retrieve the last index for NamedData"
552 " attribute (DataMapOfStringHArray1OfReal) as \"")
553 + aLastIndex + "\"";
554 WriteMessage (aMessageString);
555 return Standard_False;
556 }
557
558 if((aFirstInd | aLastInd) && aLastInd >= aFirstInd) {
559 if ( !anElement.hasChildNodes())
560 {
561 TCollection_ExtendedString aMessageString =
562 TCollection_ExtendedString("Cannot retrieve DataMapOfStringHArray1OfReal");
563 WriteMessage (aMessageString);
564 return Standard_False;
565 }
566
567 LDOM_Element* aCurElement;
568 if (aCurNode.isNull())
569 aCurNode = anElement.getFirstChild();
570 else
571 aCurNode = aCurElement->getNextSibling();
572
573 aCurElement = (LDOM_Element*)&aCurNode;
574 TCollection_ExtendedString aKey, aValueStr;
575 TDataStd_DataMapOfStringHArray1OfReal aMap;
576
577 for (ind = aFirstInd; ind < aLastInd; ind++) {
578 XmlObjMgt::GetExtendedString( *aCurElement, aKey );// Len - at the end
579 aValueStr = SplitItemFromEnd(aKey);
580 if(aValueStr.Length() == 0) {
581 TCollection_ExtendedString aMessageString =
582 TCollection_ExtendedString("Cannot retrieve a value from item = ") + aKey;
583 WriteMessage (aMessageString);
584 return Standard_False;
585 }
586 TCollection_AsciiString aVal(aValueStr,'?');
587 Standard_Integer aLen = aVal.IntegerValue();
588
589 TCollection_AsciiString aValueString = aCurElement->getAttribute(::Value());
590 Handle(TColStd_HArray1OfReal) aValue = BuildRealArray(aValueString, aLen);
591 if(aValue.IsNull()) {
592 TCollection_ExtendedString aMessageString =
593 TCollection_ExtendedString("Cannot retrieve a value from item = ") + aKey;
594 WriteMessage (aMessageString);
595 return Standard_False;
596 }
597
598 aMap.Bind(aKey, aValue);
599 aCurNode = aCurElement->getNextSibling();
600 aCurElement = (LDOM_Element*)&aCurNode;
601 }
602
603 XmlObjMgt::GetExtendedString( *aCurElement, aKey );
604 aValueStr = SplitItemFromEnd(aKey);
605 if(aValueStr.Length() == 0) {
606 TCollection_ExtendedString aMessageString =
607 TCollection_ExtendedString("Cannot retrieve a value from item = ") + aKey;
608 WriteMessage (aMessageString);
609 return Standard_False;
610 }
611 TCollection_AsciiString aVal(aValueStr,'?');
612 Standard_Integer aLen = aVal.IntegerValue();
613
614 TCollection_AsciiString aValueString = aCurElement->getAttribute(::Value());
615 Handle(TColStd_HArray1OfReal) aValue = BuildRealArray(aValueString, aLen);
616 if(aValue.IsNull()) {
617 TCollection_ExtendedString aMessageString =
618 TCollection_ExtendedString("Cannot retrieve a value from item = ") + aKey;
619 WriteMessage (aMessageString);
620 return Standard_False;
621 }
622
623 aMap.Bind(aKey, aValue);
624 T->ChangeArraysOfReals(aMap);
625 }
626 } catch (EXCEPTION) {
627 TCollection_ExtendedString aMessageString =
628 TCollection_ExtendedString("Unknown exception during data retrieve in NamedDatDriver ");
629 WriteMessage (aMessageString);
630 return Standard_False;}
631
632 return Standard_True;
633}
634
635//=======================================================================
636//function : Paste
637//purpose : transient -> persistent (store)
638//=======================================================================
639void XmlMDataStd_NamedDataDriver::Paste(const Handle(TDF_Attribute)& theSource,
640 XmlObjMgt_Persistent& theTarget,
641 XmlObjMgt_SRelocationTable& ) const
642{
643 Handle(TDataStd_NamedData) S = Handle(TDataStd_NamedData)::DownCast(theSource);
644 if(S.IsNull()) {
645 WriteMessage ("NamedDataDriver:: The source attribute is Null.");
646 return;}
647
648 Standard_Integer i=0, up;
649 XmlObjMgt_Element& anElement = theTarget;
650 XmlObjMgt_Document aDoc = anElement.getOwnerDocument().Doc();
651 if(S->HasIntegers() && !S->GetIntegersContainer().IsEmpty()) {
652 // store a set of elements with string in each of them
653 up = S->GetIntegersContainer().Extent();
654 theTarget.Element().setAttribute(::LastIntegerIndex(), up);
655
656 TColStd_DataMapIteratorOfDataMapOfStringInteger itr(S->GetIntegersContainer());
657 for (i=1; itr.More(); itr.Next(),i++) {
658 const TCollection_ExtendedString aValueStr =
659 itr.Key() + ' ' + TCollection_ExtendedString(itr.Value());// key - value;
660 XmlObjMgt_Element aCurTarget = aDoc.createElement( ::ExtString() );
661 XmlObjMgt::SetExtendedString( aCurTarget, aValueStr );
662 anElement.appendChild( aCurTarget );
663 }
664 }
665
666 if(S->HasReals() && !S->GetRealsContainer().IsEmpty()) {
667 up = S->GetRealsContainer().Extent();
668 theTarget.Element().setAttribute(::LastRealIndex(), up);
669 TDataStd_DataMapIteratorOfDataMapOfStringReal itr(S->GetRealsContainer());
670 for (i=1; itr.More(); itr.Next(),i++) {
671 const TCollection_ExtendedString aValueStr =
672 itr.Key() + ' ' + TCollection_ExtendedString(itr.Value());// key - value;
673 XmlObjMgt_Element aCurTarget = aDoc.createElement( ::ExtString() );
674 XmlObjMgt::SetExtendedString( aCurTarget, aValueStr );
675 anElement.appendChild( aCurTarget );
676 }
677 }
678
679 if(S->HasStrings() && !S->GetStringsContainer().IsEmpty()) {
680 up = S->GetStringsContainer().Extent();
681 theTarget.Element().setAttribute(::LastStringIndex(), up);
682 TDataStd_DataMapIteratorOfDataMapOfStringString itr(S->GetStringsContainer());
683 for (i=1; itr.More(); itr.Next(),i++) {
684 const TCollection_ExtendedString aValueStr =
685 itr.Key() + ' ' + TCollection_ExtendedString(itr.Value());// key(without blanks) - value;
686 XmlObjMgt_Element aCurTarget = aDoc.createElement( ::ExtString() );
687 XmlObjMgt::SetExtendedString( aCurTarget, aValueStr );
688 anElement.appendChild( aCurTarget );
689 }
690 }
691
692 if(S->HasBytes() && !S->GetBytesContainer().IsEmpty()) {
693 up = S->GetBytesContainer().Extent();
694 theTarget.Element().setAttribute(::LastByteIndex(), up);
695 TDataStd_DataMapIteratorOfDataMapOfStringByte itr(S->GetBytesContainer());
696 for (i=1; itr.More(); itr.Next(),i++) {
697 const TCollection_ExtendedString aValueStr =
698 itr.Key() + ' ' + TCollection_ExtendedString(itr.Value());// key - value;
699 XmlObjMgt_Element aCurTarget = aDoc.createElement( ::ExtString() );
700 XmlObjMgt::SetExtendedString( aCurTarget, aValueStr );
701 anElement.appendChild( aCurTarget );
702 }
703 }
704
705 if(S->HasArraysOfIntegers() && !S->GetArraysOfIntegersContainer().IsEmpty()) {
706 up = S->GetArraysOfIntegersContainer().Extent();
707 theTarget.Element().setAttribute(::LastIntArrIndex(), up);
708 TDataStd_DataMapIteratorOfDataMapOfStringHArray1OfInteger itr(S->GetArraysOfIntegersContainer());
709 for (i=1; itr.More(); itr.Next(),i++) {
710 const TColStd_Array1OfInteger& anArr1 = itr.Value()->Array1();
711 const Standard_Integer aLen = anArr1.Upper() - anArr1.Lower() +1;
712
713 const TCollection_ExtendedString aValueStr =
714 itr.Key() + ' ' + TCollection_ExtendedString(aLen);// key - Num_of_Arr_elements;
715 XmlObjMgt_Element aCurTarget = aDoc.createElement( ::ExtString() );
716 XmlObjMgt::SetExtendedString( aCurTarget, aValueStr); //key
717 anElement.appendChild( aCurTarget );
718
719 //Value = Array
720 TCollection_AsciiString aValueStr2;
721 Standard_Integer j = anArr1.Lower();
722 while (1) {
723 aValueStr2 += TCollection_AsciiString(anArr1.Value(j));
724 if (j >= anArr1.Upper()) break;
725 aValueStr2 += ' ';
726 j++;
727 }
728
729 aCurTarget.setAttribute(::Value(), aValueStr2.ToCString());
730 }
731 }
732
733 if(S->HasArraysOfReals() && !S->GetArraysOfRealsContainer().IsEmpty()) {
734 up = S->GetArraysOfRealsContainer().Extent();
735 theTarget.Element().setAttribute(::LastRealArrIndex(), up);
736 TDataStd_DataMapIteratorOfDataMapOfStringHArray1OfReal itr(S->GetArraysOfRealsContainer());
737 for (i=1; itr.More(); itr.Next(),i++) {
738 const TColStd_Array1OfReal& anArr1 = itr.Value()->Array1();
739 const Standard_Integer aLen = anArr1.Upper() - anArr1.Lower() +1;
740
741 //key
742 const TCollection_ExtendedString aValueStr =
743 itr.Key() + ' ' + TCollection_ExtendedString(aLen);// key - Num_of_Arr_elements;
744 XmlObjMgt_Element aCurTarget = aDoc.createElement( ::ExtString() );
745 XmlObjMgt::SetExtendedString( aCurTarget, aValueStr); //key
746 anElement.appendChild( aCurTarget );
747
748 //Value = Array
749 TCollection_AsciiString aValueStr2;
750 Standard_Integer j = anArr1.Lower();
751 while (1) {
752#ifndef OCC6010
753 aValueStr2 += TCollection_AsciiString(anArr1.Value(j));
754#else
755 char aValueChar[32];
756 sprintf(aValueChar, "%.15g", anArr1.Value(j));
757 TCollection_AsciiString aValueStr(aValueChar);
758 aValueStr2 += aValueStr;
759#endif
760 if (j >= anArr1.Upper()) break;
761 aValueStr2 += ' ';
762 j++;
763 }
764 aCurTarget.setAttribute(::Value(), aValueStr2.ToCString());
765
766 }
767 }
768}