1 // Created on: 2007-08-22
2 // Created by: Sergey ZARITCHNY
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_IntPackedMapDriver.ixx>
22 #include <XmlObjMgt.hxx>
23 #include <XmlObjMgt_RRelocationTable.hxx>
24 #include <XmlObjMgt_SRelocationTable.hxx>
25 #include <CDM_MessageDriver.hxx>
26 #include <TColStd_PackedMapOfInteger.hxx>
27 #include <TColStd_HPackedMapOfInteger.hxx>
28 #include <TColStd_MapIteratorOfPackedMapOfInteger.hxx>
29 #include <XmlMDF_ADriver.hxx>
30 #include <TDF_Attribute.hxx>
31 #include <TDataStd_IntPackedMap.hxx>
32 #include <XmlMDataStd.hxx>
34 IMPLEMENT_DOMSTRING (IntPackedMapSize, "mapsize")
35 IMPLEMENT_DOMSTRING (IsDeltaOn, "delta")
36 //=======================================================================
37 //function : XmlMDataStd_IntPackedMapDriver
38 //purpose : Constructor
39 //=======================================================================
41 XmlMDataStd_IntPackedMapDriver::XmlMDataStd_IntPackedMapDriver
42 (const Handle(CDM_MessageDriver)& theMsgDriver)
43 : XmlMDF_ADriver (theMsgDriver, STANDARD_TYPE(TDataStd_IntPackedMap)->Name())
46 //=======================================================================
47 //function : NewEmpty()
49 //=======================================================================
50 Handle(TDF_Attribute) XmlMDataStd_IntPackedMapDriver::NewEmpty () const
52 return (new TDataStd_IntPackedMap());
55 //=======================================================================
57 //purpose : persistent -> transient (retrieve)
58 //=======================================================================
59 Standard_Boolean XmlMDataStd_IntPackedMapDriver::Paste
60 (const XmlObjMgt_Persistent& theSource,
61 const Handle(TDF_Attribute)& theTarget,
62 XmlObjMgt_RRelocationTable& ) const
64 Handle(TDataStd_IntPackedMap) aPackedMap =
65 Handle(TDataStd_IntPackedMap)::DownCast(theTarget);
66 if(!aPackedMap.IsNull()) {
67 Standard_Integer aSize;
68 const XmlObjMgt_Element& anElement = theSource;
69 XmlObjMgt_DOMString aSizeDStr = anElement.getAttribute(::IntPackedMapSize());
72 else if (!aSizeDStr.GetInteger(aSize)) {
73 TCollection_ExtendedString aMessageString =
74 TCollection_ExtendedString("Cannot retrieve the Map size"
75 " for IntPackedMap attribute as \"")
77 WriteMessage (aMessageString);
78 return Standard_False;
80 Handle(TColStd_HPackedMapOfInteger) aHMap = new TColStd_HPackedMapOfInteger ();
81 Standard_Boolean Ok = Standard_True;
83 Standard_CString aValueString =
84 Standard_CString(XmlObjMgt::GetStringValue(anElement).GetString());
85 // Handle(TColStd_HPackedMapOfInteger) aHMap = new TColStd_HPackedMapOfInteger ();
86 for (Standard_Integer i = 1; i <= aSize; i++) {
87 Standard_Integer aValue;
88 if (!XmlObjMgt::GetInteger(aValueString, aValue)) {
89 Ok = Standard_False; break;
91 if(!aHMap->ChangeMap().Add( aValue )) {
92 Ok = Standard_False; break;
96 TCollection_ExtendedString aMessageString =
97 TCollection_ExtendedString("Cannot retrieve integer member"
98 " for IntPackedMap attribute as \"")
99 + aValueString + "\"";
100 WriteMessage (aMessageString);
101 return Standard_False;
103 if(aPackedMap->ChangeMap(aHMap))
108 //cout << "CurDocVersion = " << XmlMDataStd::DocumentVersion() <<endl;
111 Standard_Boolean aDelta(Standard_False);
113 if(XmlMDataStd::DocumentVersion() > 2) {
114 Standard_Integer aDeltaValue;
115 if (!anElement.getAttribute(::IsDeltaOn()).GetInteger(aDeltaValue))
117 TCollection_ExtendedString aMessageString =
118 TCollection_ExtendedString("Cannot retrieve the isDelta value"
119 " for IntPackedMap attribute as \"")
120 + aDeltaValue + "\"";
121 WriteMessage (aMessageString);
122 return Standard_False;
125 aDelta = (Standard_Boolean)aDeltaValue;
128 else if(XmlMDataStd::DocumentVersion() == -1)
129 cout << "Current DocVersion field is not initialized. " <<endl;
131 aPackedMap->SetDelta(aDelta);
132 return Standard_True;
135 WriteMessage("error retrieving Map for type TDataStd_IntPackedMap");
136 return Standard_False;
139 //=======================================================================
141 //purpose : transient -> persistent (store)
142 //=======================================================================
143 void XmlMDataStd_IntPackedMapDriver::Paste (const Handle(TDF_Attribute)& theSource,
144 XmlObjMgt_Persistent& theTarget,
145 XmlObjMgt_SRelocationTable& ) const
147 Handle(TDataStd_IntPackedMap) aS = Handle(TDataStd_IntPackedMap)::DownCast(theSource);
149 WriteMessage ("IntPackedMapDriver:: The source attribute is Null.");
153 Standard_Integer aSize = (aS->IsEmpty()) ? 0 : aS->Extent();
154 theTarget.Element().setAttribute(::IntPackedMapSize(), aSize);
155 theTarget.Element().setAttribute(::IsDeltaOn(),aS->GetDelta());
157 TCollection_AsciiString aValueString;
159 TColStd_MapIteratorOfPackedMapOfInteger anIt(aS->GetMap());
160 for(;anIt.More();anIt.Next()) {
161 aValueString += TCollection_AsciiString(anIt.Key());
164 // No occurrence of '&', '<' and other irregular XML characters
165 XmlObjMgt::SetStringValue (theTarget, aValueString.ToCString(), Standard_True);