7fd59977 |
1 | // File: XmlMDataStd_RealListDriver.cxx |
2 | // Created: May 29 11:40:00 2007 |
3 | // Author: Vlad Romashko |
4 | // <vladislav.romashko@opencascade.com> |
5 | // Copyright: Open CASCADE |
6 | |
7 | #include <XmlMDataStd_RealListDriver.ixx> |
8 | #include <TDataStd_RealList.hxx> |
9 | #include <TColStd_ListIteratorOfListOfReal.hxx> |
10 | #include <XmlObjMgt.hxx> |
11 | |
12 | IMPLEMENT_DOMSTRING (FirstIndexString, "first") |
13 | IMPLEMENT_DOMSTRING (LastIndexString, "last") |
14 | |
15 | //======================================================================= |
16 | //function : XmlMDataStd_RealListDriver |
17 | //purpose : Constructor |
18 | //======================================================================= |
19 | XmlMDataStd_RealListDriver::XmlMDataStd_RealListDriver(const Handle(CDM_MessageDriver)& theMsgDriver) |
20 | : XmlMDF_ADriver (theMsgDriver, NULL) |
21 | { |
22 | |
23 | } |
24 | |
25 | //======================================================================= |
26 | //function : NewEmpty |
27 | //purpose : |
28 | //======================================================================= |
29 | Handle(TDF_Attribute) XmlMDataStd_RealListDriver::NewEmpty() const |
30 | { |
31 | return new TDataStd_RealList(); |
32 | } |
33 | |
34 | //======================================================================= |
35 | //function : Paste |
36 | //purpose : persistent -> transient (retrieve) |
37 | //======================================================================= |
38 | Standard_Boolean XmlMDataStd_RealListDriver::Paste(const XmlObjMgt_Persistent& theSource, |
39 | const Handle(TDF_Attribute)& theTarget, |
40 | XmlObjMgt_RRelocationTable& ) const |
41 | { |
42 | Standard_Real aValue; |
43 | Standard_Integer aFirstInd, aLastInd, ind; |
44 | const XmlObjMgt_Element& anElement = theSource; |
45 | |
46 | // Read the FirstIndex; if the attribute is absent initialize to 1 |
47 | XmlObjMgt_DOMString aFirstIndex= anElement.getAttribute(::FirstIndexString()); |
48 | if (aFirstIndex == NULL) |
49 | aFirstInd = 1; |
50 | else if (!aFirstIndex.GetInteger(aFirstInd)) |
51 | { |
52 | TCollection_ExtendedString aMessageString = |
53 | TCollection_ExtendedString("Cannot retrieve the first index" |
54 | " for RealList attribute as \"") |
55 | + aFirstIndex + "\""; |
56 | WriteMessage (aMessageString); |
57 | return Standard_False; |
58 | } |
59 | |
60 | // Read the LastIndex; the attribute should be present |
61 | if (!anElement.getAttribute(::LastIndexString()).GetInteger(aLastInd)) |
62 | { |
63 | TCollection_ExtendedString aMessageString = |
64 | TCollection_ExtendedString("Cannot retrieve the last index" |
65 | " for RealList attribute as \"") |
66 | + aFirstIndex + "\""; |
67 | WriteMessage (aMessageString); |
68 | return Standard_False; |
69 | } |
70 | |
71 | Handle(TDataStd_RealList) aRealList = Handle(TDataStd_RealList)::DownCast(theTarget); |
72 | |
73 | // Check the type of LDOMString |
74 | const XmlObjMgt_DOMString& aString = XmlObjMgt::GetStringValue(anElement); |
75 | if (aString.Type() == LDOMBasicString::LDOM_Integer) |
76 | { |
77 | if (aFirstInd == aLastInd) |
78 | { |
79 | Standard_Integer anIntValue; |
80 | if (aString.GetInteger(anIntValue)) |
81 | aRealList->Append(Standard_Real(anIntValue)); |
82 | } |
83 | else |
84 | { |
85 | TCollection_ExtendedString aMessageString = |
86 | TCollection_ExtendedString("Cannot retrieve array of real members" |
87 | " for RealList attribute from Integer \"") |
88 | + aString + "\""; |
89 | WriteMessage (aMessageString); |
90 | return Standard_False; |
91 | } |
92 | } |
93 | else |
94 | { |
95 | Standard_CString aValueStr = Standard_CString(aString.GetString()); |
96 | for (ind = aFirstInd; ind <= aLastInd; ind++) |
97 | { |
98 | if (!XmlObjMgt::GetReal(aValueStr, aValue)) { |
99 | TCollection_ExtendedString aMessageString = |
100 | TCollection_ExtendedString("Cannot retrieve real member" |
101 | " for RealList attribute as \"") |
102 | + aValueStr + "\""; |
103 | WriteMessage (aMessageString); |
104 | return Standard_False; |
105 | } |
106 | aRealList->Append(aValue); |
107 | } |
108 | } |
109 | |
110 | return Standard_True; |
111 | } |
112 | |
113 | //======================================================================= |
114 | //function : Paste |
115 | //purpose : transient -> persistent (store) |
116 | //======================================================================= |
117 | void XmlMDataStd_RealListDriver::Paste(const Handle(TDF_Attribute)& theSource, |
118 | XmlObjMgt_Persistent& theTarget, |
119 | XmlObjMgt_SRelocationTable& ) const |
120 | { |
121 | Handle(TDataStd_RealList) aRealList = Handle(TDataStd_RealList)::DownCast(theSource); |
122 | |
123 | Standard_Integer anU = aRealList->Extent(); |
124 | TCollection_AsciiString aValueStr; |
125 | |
126 | theTarget.Element().setAttribute(::LastIndexString(), anU); |
127 | if (anU >= 1) |
128 | { |
129 | TColStd_ListIteratorOfListOfReal itr(aRealList->List()); |
130 | for (; itr.More(); itr.Next()) |
131 | { |
132 | aValueStr += TCollection_AsciiString(itr.Value()); |
133 | aValueStr += ' '; |
134 | } |
135 | } |
136 | // No occurrence of '&', '<' and other irregular XML characters |
137 | XmlObjMgt::SetStringValue (theTarget, aValueStr.ToCString(), Standard_True); |
138 | } |