1 // Created on: 2007-05-29
2 // Created by: Vlad Romashko
3 // Copyright (c) 2007-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.
21 #include <XmlMDataStd_BooleanListDriver.ixx>
22 #include <TDataStd_BooleanList.hxx>
23 #include <TDataStd_ListIteratorOfListOfByte.hxx>
24 #include <XmlObjMgt.hxx>
26 IMPLEMENT_DOMSTRING (FirstIndexString, "first")
27 IMPLEMENT_DOMSTRING (LastIndexString, "last")
29 //=======================================================================
30 //function : XmlMDataStd_BooleanListDriver
31 //purpose : Constructor
32 //=======================================================================
33 XmlMDataStd_BooleanListDriver::XmlMDataStd_BooleanListDriver(const Handle(CDM_MessageDriver)& theMsgDriver)
34 : XmlMDF_ADriver (theMsgDriver, NULL)
39 //=======================================================================
42 //=======================================================================
43 Handle(TDF_Attribute) XmlMDataStd_BooleanListDriver::NewEmpty() const
45 return new TDataStd_BooleanList();
48 //=======================================================================
50 //purpose : persistent -> transient (retrieve)
51 //=======================================================================
52 Standard_Boolean XmlMDataStd_BooleanListDriver::Paste(const XmlObjMgt_Persistent& theSource,
53 const Handle(TDF_Attribute)& theTarget,
54 XmlObjMgt_RRelocationTable& ) const
56 Standard_Integer aFirstInd, aLastInd, aValue, ind;
57 const XmlObjMgt_Element& anElement = theSource;
59 // Read the FirstIndex; if the attribute is absent initialize to 1
60 XmlObjMgt_DOMString aFirstIndex= anElement.getAttribute(::FirstIndexString());
61 if (aFirstIndex == NULL)
63 else if (!aFirstIndex.GetInteger(aFirstInd))
65 TCollection_ExtendedString aMessageString =
66 TCollection_ExtendedString("Cannot retrieve the first index"
67 " for BooleanList attribute as \"")
69 WriteMessage (aMessageString);
70 return Standard_False;
73 // Read the LastIndex; the attribute should be present
74 if (!anElement.getAttribute(::LastIndexString()).GetInteger(aLastInd))
76 TCollection_ExtendedString aMessageString =
77 TCollection_ExtendedString("Cannot retrieve the last index"
78 " for BooleanList attribute as \"")
80 WriteMessage (aMessageString);
81 return Standard_False;
84 Handle(TDataStd_BooleanList) aBooleanList = Handle(TDataStd_BooleanList)::DownCast(theTarget);
85 if (aFirstInd == aLastInd)
87 Standard_Integer anInteger;
88 if (!XmlObjMgt::GetStringValue(anElement).GetInteger(anInteger))
90 TCollection_ExtendedString aMessageString =
91 TCollection_ExtendedString("Cannot retrieve integer member"
92 " for BooleanList attribute as \"");
93 WriteMessage (aMessageString);
94 return Standard_False;
96 aBooleanList->Append(anInteger ? Standard_True : Standard_False);
100 Standard_CString aValueStr = Standard_CString(XmlObjMgt::GetStringValue(anElement).GetString());
101 for (ind = aFirstInd; ind <= aLastInd; ind++)
103 if (!XmlObjMgt::GetInteger(aValueStr, aValue))
105 TCollection_ExtendedString aMessageString =
106 TCollection_ExtendedString("Cannot retrieve integer member"
107 " for BooleanList attribute as \"")
109 WriteMessage (aMessageString);
110 return Standard_False;
112 aBooleanList->Append(aValue ? Standard_True : Standard_False);
116 return Standard_True;
119 //=======================================================================
121 //purpose : transient -> persistent (store)
122 //=======================================================================
123 void XmlMDataStd_BooleanListDriver::Paste(const Handle(TDF_Attribute)& theSource,
124 XmlObjMgt_Persistent& theTarget,
125 XmlObjMgt_SRelocationTable& ) const
127 Handle(TDataStd_BooleanList) aBooleanList = Handle(TDataStd_BooleanList)::DownCast(theSource);
129 Standard_Integer anU = aBooleanList->Extent();
130 TCollection_AsciiString aValueStr;
132 theTarget.Element().setAttribute(::LastIndexString(), anU);
135 TDataStd_ListIteratorOfListOfByte itr(aBooleanList->List());
136 for (; itr.More(); itr.Next())
138 aValueStr += TCollection_AsciiString(itr.Value());
142 // No occurrence of '&', '<' and other irregular XML characters
143 XmlObjMgt::SetStringValue (theTarget, aValueStr.ToCString(), Standard_True);