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 <XmlObjMgt.hxx>
25 #include <XmlMDataStd.hxx>
27 IMPLEMENT_DOMSTRING (FirstIndexString, "first")
28 IMPLEMENT_DOMSTRING (LastIndexString, "last")
29 IMPLEMENT_DOMSTRING (IsDeltaOn, "delta")
30 //=======================================================================
31 //function : XmlMDataStd_IntegerArrayDriver
32 //purpose : Constructor
33 //=======================================================================
35 XmlMDataStd_IntegerArrayDriver::XmlMDataStd_IntegerArrayDriver
36 (const Handle(CDM_MessageDriver)& theMsgDriver)
37 : XmlMDF_ADriver (theMsgDriver, NULL)
40 //=======================================================================
43 //=======================================================================
44 Handle(TDF_Attribute) XmlMDataStd_IntegerArrayDriver::NewEmpty() const
46 return (new TDataStd_IntegerArray());
49 //=======================================================================
51 //purpose : persistent -> transient (retrieve)
52 //=======================================================================
53 Standard_Boolean XmlMDataStd_IntegerArrayDriver::Paste
54 (const XmlObjMgt_Persistent& theSource,
55 const Handle(TDF_Attribute)& theTarget,
56 XmlObjMgt_RRelocationTable& ) const
58 Standard_Integer aFirstInd, aLastInd, aValue, ind;
59 const XmlObjMgt_Element& anElement = theSource;
61 // Read the FirstIndex; if the attribute is absent initialize to 1
62 XmlObjMgt_DOMString aFirstIndex= anElement.getAttribute(::FirstIndexString());
63 if (aFirstIndex == NULL)
65 else if (!aFirstIndex.GetInteger(aFirstInd)) {
66 TCollection_ExtendedString aMessageString =
67 TCollection_ExtendedString("Cannot retrieve the first index"
68 " for IntegerArray attribute as \"")
70 WriteMessage (aMessageString);
71 return Standard_False;
74 // Read the LastIndex; the attribute should be present
75 if (!anElement.getAttribute(::LastIndexString()).GetInteger(aLastInd)) {
76 TCollection_ExtendedString aMessageString =
77 TCollection_ExtendedString("Cannot retrieve the last index"
78 " for IntegerArray attribute as \"")
80 WriteMessage (aMessageString);
81 return Standard_False;
84 Handle(TDataStd_IntegerArray) anIntArray =
85 Handle(TDataStd_IntegerArray)::DownCast(theTarget);
86 anIntArray->Init(aFirstInd, aLastInd);
88 if(aFirstInd == aLastInd) {
89 Standard_Integer anInteger;
90 if(!XmlObjMgt::GetStringValue(anElement).GetInteger( anInteger)) {
91 TCollection_ExtendedString aMessageString =
92 TCollection_ExtendedString("Cannot retrieve integer member"
93 " for IntegerArray attribute as \"");
94 WriteMessage (aMessageString);
95 return Standard_False;
97 anIntArray->SetValue(aFirstInd, anInteger);
101 // Warning: check implementation of XmlObjMgt_DOMString !! For LDOM this is OK
102 Standard_CString aValueStr =
103 Standard_CString(XmlObjMgt::GetStringValue(anElement).GetString());
105 for (ind = aFirstInd; ind <= aLastInd; ind++)
107 if (!XmlObjMgt::GetInteger(aValueStr, aValue)) {
108 TCollection_ExtendedString aMessageString =
109 TCollection_ExtendedString("Cannot retrieve integer member"
110 " for IntegerArray attribute as \"")
112 WriteMessage (aMessageString);
113 return Standard_False;
115 anIntArray->SetValue(ind, aValue);
119 //cout << "CurDocVersion = " << XmlMDataStd::DocumentVersion() <<endl;
121 Standard_Boolean aDelta(Standard_False);
123 if(XmlMDataStd::DocumentVersion() > 2) {
124 Standard_Integer aDeltaValue;
125 if (!anElement.getAttribute(::IsDeltaOn()).GetInteger(aDeltaValue))
127 TCollection_ExtendedString aMessageString =
128 TCollection_ExtendedString("Cannot retrieve the isDelta value"
129 " for IntegerArray attribute as \"")
130 + aDeltaValue + "\"";
131 WriteMessage (aMessageString);
132 return Standard_False;
135 aDelta = (Standard_Boolean)aDeltaValue;
138 else if(XmlMDataStd::DocumentVersion() == -1)
139 cout << "Current DocVersion field is not initialized. " <<endl;
141 anIntArray->SetDelta(aDelta);
143 return Standard_True;
146 //=======================================================================
148 //purpose : transient -> persistent (store)
149 //=======================================================================
150 void XmlMDataStd_IntegerArrayDriver::Paste
151 (const Handle(TDF_Attribute)& theSource,
152 XmlObjMgt_Persistent& theTarget,
153 XmlObjMgt_SRelocationTable& ) const
155 Handle(TDataStd_IntegerArray) anIntArray =
156 Handle(TDataStd_IntegerArray)::DownCast(theSource);
158 Standard_Integer aL = anIntArray->Lower(), anU = anIntArray->Upper();
159 TCollection_AsciiString aValueStr;
161 if (aL != 1) theTarget.Element().setAttribute (::FirstIndexString(), aL);
162 theTarget.Element().setAttribute(::LastIndexString(), anU);
163 theTarget.Element().setAttribute(::IsDeltaOn(), anIntArray->GetDelta());
165 Standard_Integer i = aL;
167 aValueStr += TCollection_AsciiString(anIntArray->Value(i));
172 // No occurrence of '&', '<' and other irregular XML characters
173 XmlObjMgt::SetStringValue (theTarget, aValueStr.ToCString(), Standard_True);