1 // Created on: 2001-08-24
2 // Created by: Alexnder GRIGORIEV
3 // Copyright (c) 2001-2012 OPEN CASCADE SAS
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.
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.
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.
20 //AGV 150202: Changed prototype XmlObjMgt::SetStringValue()
22 #include <XmlMDataStd_IntegerArrayDriver.ixx>
23 #include <TDataStd_IntegerArray.hxx>
24 #include <NCollection_LocalArray.hxx>
25 #include <XmlObjMgt.hxx>
26 #include <XmlMDataStd.hxx>
28 IMPLEMENT_DOMSTRING (FirstIndexString, "first")
29 IMPLEMENT_DOMSTRING (LastIndexString, "last")
30 IMPLEMENT_DOMSTRING (IsDeltaOn, "delta")
31 //=======================================================================
32 //function : XmlMDataStd_IntegerArrayDriver
33 //purpose : Constructor
34 //=======================================================================
36 XmlMDataStd_IntegerArrayDriver::XmlMDataStd_IntegerArrayDriver
37 (const Handle(CDM_MessageDriver)& theMsgDriver)
38 : XmlMDF_ADriver (theMsgDriver, NULL)
41 //=======================================================================
44 //=======================================================================
45 Handle(TDF_Attribute) XmlMDataStd_IntegerArrayDriver::NewEmpty() const
47 return (new TDataStd_IntegerArray());
50 //=======================================================================
52 //purpose : persistent -> transient (retrieve)
53 //=======================================================================
54 Standard_Boolean XmlMDataStd_IntegerArrayDriver::Paste
55 (const XmlObjMgt_Persistent& theSource,
56 const Handle(TDF_Attribute)& theTarget,
57 XmlObjMgt_RRelocationTable& ) const
59 Standard_Integer aFirstInd, aLastInd, aValue, ind;
60 const XmlObjMgt_Element& anElement = theSource;
62 // Read the FirstIndex; if the attribute is absent initialize to 1
63 XmlObjMgt_DOMString aFirstIndex= anElement.getAttribute(::FirstIndexString());
64 if (aFirstIndex == NULL)
66 else if (!aFirstIndex.GetInteger(aFirstInd)) {
67 TCollection_ExtendedString aMessageString =
68 TCollection_ExtendedString("Cannot retrieve the first index"
69 " for IntegerArray attribute as \"")
71 WriteMessage (aMessageString);
72 return Standard_False;
75 // Read the LastIndex; the attribute should be present
76 if (!anElement.getAttribute(::LastIndexString()).GetInteger(aLastInd)) {
77 TCollection_ExtendedString aMessageString =
78 TCollection_ExtendedString("Cannot retrieve the last index"
79 " for IntegerArray attribute as \"")
81 WriteMessage (aMessageString);
82 return Standard_False;
85 Handle(TDataStd_IntegerArray) anIntArray =
86 Handle(TDataStd_IntegerArray)::DownCast(theTarget);
87 anIntArray->Init(aFirstInd, aLastInd);
89 if(aFirstInd == aLastInd) {
90 Standard_Integer anInteger;
91 if(!XmlObjMgt::GetStringValue(anElement).GetInteger( anInteger)) {
92 TCollection_ExtendedString aMessageString =
93 TCollection_ExtendedString("Cannot retrieve integer member"
94 " for IntegerArray attribute as \"");
95 WriteMessage (aMessageString);
96 return Standard_False;
98 anIntArray->SetValue(aFirstInd, anInteger);
102 // Warning: check implementation of XmlObjMgt_DOMString !! For LDOM this is OK
103 Standard_CString aValueStr =
104 Standard_CString(XmlObjMgt::GetStringValue(anElement).GetString());
106 for (ind = aFirstInd; ind <= aLastInd; ind++)
108 if (!XmlObjMgt::GetInteger(aValueStr, aValue)) {
109 TCollection_ExtendedString aMessageString =
110 TCollection_ExtendedString("Cannot retrieve integer member"
111 " for IntegerArray attribute as \"")
113 WriteMessage (aMessageString);
114 return Standard_False;
116 anIntArray->SetValue(ind, aValue);
120 //cout << "CurDocVersion = " << XmlMDataStd::DocumentVersion() <<endl;
122 Standard_Boolean aDelta(Standard_False);
124 if(XmlMDataStd::DocumentVersion() > 2) {
125 Standard_Integer aDeltaValue;
126 if (!anElement.getAttribute(::IsDeltaOn()).GetInteger(aDeltaValue))
128 TCollection_ExtendedString aMessageString =
129 TCollection_ExtendedString("Cannot retrieve the isDelta value"
130 " for IntegerArray attribute as \"")
131 + aDeltaValue + "\"";
132 WriteMessage (aMessageString);
133 return Standard_False;
136 aDelta = (Standard_Boolean)aDeltaValue;
139 else if(XmlMDataStd::DocumentVersion() == -1)
140 cout << "Current DocVersion field is not initialized. " <<endl;
142 anIntArray->SetDelta(aDelta);
144 return Standard_True;
147 //=======================================================================
149 //purpose : transient -> persistent (store)
150 //=======================================================================
151 void XmlMDataStd_IntegerArrayDriver::Paste
152 (const Handle(TDF_Attribute)& theSource,
153 XmlObjMgt_Persistent& theTarget,
154 XmlObjMgt_SRelocationTable& ) const
156 Handle(TDataStd_IntegerArray) anIntArray =
157 Handle(TDataStd_IntegerArray)::DownCast(theSource);
158 const Handle(TColStd_HArray1OfInteger)& hIntArray = anIntArray->Array();
159 const TColStd_Array1OfInteger& intArray = hIntArray->Array1();
160 Standard_Integer aL = intArray.Lower(), anU = intArray.Upper();
163 theTarget.Element().setAttribute(::FirstIndexString(), aL);
164 theTarget.Element().setAttribute(::LastIndexString(), anU);
165 theTarget.Element().setAttribute(::IsDeltaOn(), anIntArray->GetDelta());
167 // Allocation of 12 chars for each integer including the space.
168 // An example: -2 147 483 648
169 Standard_Integer iChar = 0;
170 NCollection_LocalArray<Standard_Character> str;
171 if (intArray.Length())
172 str.Allocate(12 * intArray.Length() + 1);
174 Standard_Integer i = aL;
177 iChar += Sprintf(&(str[iChar]), "%d ", intArray.Value(i));
183 if (intArray.Length())
185 // No occurrence of '&', '<' and other irregular XML characters
186 str[iChar - 1] = '\0';
187 XmlObjMgt::SetStringValue (theTarget, (Standard_Character*)str, Standard_True);