1 // Created on: 2007-07-02
2 // Created by: Sergey ZARITCHNY
3 // Copyright (c) 2007-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
17 #include <BinMDataStd_NamedDataDriver.hxx>
18 #include <BinObjMgt_Persistent.hxx>
19 #include <CDM_MessageDriver.hxx>
20 #include <Standard_Type.hxx>
21 #include <TCollection_ExtendedString.hxx>
22 #include <TColStd_DataMapIteratorOfDataMapOfStringInteger.hxx>
23 #include <TColStd_DataMapOfStringInteger.hxx>
24 #include <TColStd_HArray1OfInteger.hxx>
25 #include <TColStd_HArray1OfReal.hxx>
26 #include <TDataStd_DataMapIteratorOfDataMapOfStringByte.hxx>
27 #include <TDataStd_DataMapIteratorOfDataMapOfStringHArray1OfInteger.hxx>
28 #include <TDataStd_DataMapIteratorOfDataMapOfStringHArray1OfReal.hxx>
29 #include <TDataStd_DataMapIteratorOfDataMapOfStringReal.hxx>
30 #include <TDataStd_DataMapIteratorOfDataMapOfStringString.hxx>
31 #include <TDataStd_DataMapOfStringByte.hxx>
32 #include <TDataStd_DataMapOfStringHArray1OfInteger.hxx>
33 #include <TDataStd_DataMapOfStringHArray1OfReal.hxx>
34 #include <TDataStd_DataMapOfStringReal.hxx>
35 #include <TDataStd_DataMapOfStringString.hxx>
36 #include <TDataStd_NamedData.hxx>
37 #include <TDF_Attribute.hxx>
39 IMPLEMENT_STANDARD_RTTIEXT(BinMDataStd_NamedDataDriver,BinMDF_ADriver)
41 //=======================================================================
42 //function : BinMDataStd_NamedDataDriver
43 //purpose : Constructor
44 //=======================================================================
45 BinMDataStd_NamedDataDriver::BinMDataStd_NamedDataDriver(const Handle(CDM_MessageDriver)& theMsgDriver)
46 : BinMDF_ADriver (theMsgDriver, STANDARD_TYPE(TDataStd_NamedData)->Name())
51 //=======================================================================
54 //=======================================================================
55 Handle(TDF_Attribute) BinMDataStd_NamedDataDriver::NewEmpty() const
57 return new TDataStd_NamedData();
60 //=======================================================================
62 //purpose : persistent -> transient (retrieve)
63 //=======================================================================
64 Standard_Boolean BinMDataStd_NamedDataDriver::Paste(const BinObjMgt_Persistent& theSource,
65 const Handle(TDF_Attribute)& theTarget,
66 BinObjMgt_RRelocationTable& ) const
69 Handle(TDataStd_NamedData) T = Handle(TDataStd_NamedData)::DownCast(theTarget);
70 if(T.IsNull()) return Standard_False;
71 Standard_Integer aLower, anUpper,i;
72 if (! (theSource >> aLower >> anUpper))
73 return Standard_False;
74 // const Standard_Integer aLength = anUpper - aLower + 1;
75 if (anUpper < aLower) return Standard_False;
76 if(anUpper | aLower) {
77 TColStd_DataMapOfStringInteger anIntegers;
78 for (i=aLower; i<=anUpper; i++) {
79 TCollection_ExtendedString aKey;
80 Standard_Integer aValue;
81 if (! (theSource >> aKey >> aValue))
82 return Standard_False;
83 anIntegers.Bind(aKey, aValue);
85 T->ChangeIntegers(anIntegers);
88 if (! (theSource >> aLower >> anUpper))
89 return Standard_False;
90 if (anUpper < aLower) return Standard_False;
91 if(anUpper | aLower) {
92 TDataStd_DataMapOfStringReal aReals;
93 for (i=aLower; i<=anUpper; i++) {
94 TCollection_ExtendedString aKey;
96 if (! (theSource >> aKey >> aValue))
97 return Standard_False;
98 aReals.Bind(aKey, aValue);
100 T->ChangeReals(aReals);
104 if (! (theSource >> aLower >> anUpper))
105 return Standard_False;
106 if (anUpper < aLower) return Standard_False;
107 if(anUpper | aLower) {
108 TDataStd_DataMapOfStringString aStrings;
109 for (i=aLower; i<=anUpper; i++) {
110 TCollection_ExtendedString aKey;
111 TCollection_ExtendedString aValue;
112 if (! (theSource >> aKey >> aValue))
113 return Standard_False;
114 aStrings.Bind(aKey, aValue);
116 T->ChangeStrings(aStrings);
120 if (! (theSource >> aLower >> anUpper))
121 return Standard_False;
122 if (anUpper < aLower) return Standard_False;
123 if(anUpper | aLower) {
124 TDataStd_DataMapOfStringByte aBytes;
125 for (i=aLower; i<=anUpper; i++) {
126 TCollection_ExtendedString aKey;
127 Standard_Byte aValue;
128 if (! (theSource >> aKey >> aValue))
129 return Standard_False;
130 aBytes.Bind(aKey, (Standard_Byte)aValue);
132 T->ChangeBytes(aBytes);
135 // arrays of integers
136 if (! (theSource >> aLower >> anUpper))
137 return Standard_False;
138 if (anUpper < aLower) return Standard_False;
139 Standard_Boolean aResult = Standard_False;
140 if(anUpper | aLower) {
141 TDataStd_DataMapOfStringHArray1OfInteger anIntArrays;
142 for (i=aLower; i<=anUpper; i++) {
143 TCollection_ExtendedString aKey;
144 if (! (theSource >> aKey))
145 return Standard_False;
146 Standard_Integer low, up;
147 if (! (theSource >> low >> up))
148 return Standard_False;
150 return Standard_False;
152 Handle(TColStd_HArray1OfInteger) aTargetArray = new TColStd_HArray1OfInteger (low, up);
153 if(!theSource.GetIntArray (&(aTargetArray->ChangeArray1())(low), up-low+1))
154 return Standard_False;
156 Standard_Boolean Ok = anIntArrays.Bind(aKey, aTargetArray);
161 T->ChangeArraysOfIntegers(anIntArrays);
165 if (! (theSource >> aLower >> anUpper))
166 return Standard_False;
167 if (anUpper < aLower) return Standard_False;
168 aResult = Standard_False;
169 if(anUpper | aLower) {
170 TDataStd_DataMapOfStringHArray1OfReal aRealArrays;
171 for (i=aLower; i<=anUpper; i++) {
172 TCollection_ExtendedString aKey;
173 if (! (theSource >> aKey))
174 return Standard_False;
175 Standard_Integer low, up;
176 if (! (theSource >> low >> up))
177 return Standard_False;
179 return Standard_False;
181 Handle(TColStd_HArray1OfReal) aTargetArray =
182 new TColStd_HArray1OfReal(low, up);
183 if(!theSource.GetRealArray (&(aTargetArray->ChangeArray1())(low), up-low+1))
184 return Standard_False;
185 Standard_Boolean Ok = aRealArrays.Bind(aKey, aTargetArray);
190 T->ChangeArraysOfReals(aRealArrays);
192 return Standard_True;
195 //=======================================================================
197 //purpose : transient -> persistent (store)
198 //=======================================================================
199 void BinMDataStd_NamedDataDriver::Paste(const Handle(TDF_Attribute)& theSource,
200 BinObjMgt_Persistent& theTarget,
201 BinObjMgt_SRelocationTable& ) const
203 Handle(TDataStd_NamedData) S = Handle(TDataStd_NamedData)::DownCast (theSource);
204 if(S.IsNull()) return;
205 // Standard_Integer i=0;
207 if(S->HasIntegers() && !S->GetIntegersContainer().IsEmpty()) {
208 theTarget.PutInteger(1) << S->GetIntegersContainer().Extent(); //dim
209 TColStd_DataMapIteratorOfDataMapOfStringInteger itr(S->GetIntegersContainer());
210 for (; itr.More(); itr.Next()) {
211 theTarget << itr.Key() << itr.Value(); // key - value;
214 theTarget.PutInteger(0).PutInteger(0);
217 if(S->HasReals() && !S->GetRealsContainer().IsEmpty()) {
218 theTarget.PutInteger(1) << S->GetRealsContainer().Extent();
219 TDataStd_DataMapIteratorOfDataMapOfStringReal itr(S->GetRealsContainer());
220 for (; itr.More(); itr.Next()) {
221 theTarget << itr.Key() << itr.Value();
224 theTarget.PutInteger(0).PutInteger(0);
227 if(S->HasStrings() && !S->GetStringsContainer().IsEmpty()) {
228 theTarget.PutInteger(1) << S->GetStringsContainer().Extent();
229 TDataStd_DataMapIteratorOfDataMapOfStringString itr(S->GetStringsContainer());
230 for (; itr.More(); itr.Next()) {
231 theTarget << itr.Key() << itr.Value();
234 theTarget.PutInteger(0).PutInteger(0);
237 if(S->HasBytes() && !S->GetBytesContainer().IsEmpty()) {
238 theTarget.PutInteger(1) << S->GetBytesContainer().Extent();
239 TDataStd_DataMapIteratorOfDataMapOfStringByte itr(S->GetBytesContainer());
240 for (; itr.More(); itr.Next()) {
241 theTarget << itr.Key() << (Standard_Byte) itr.Value();
244 theTarget.PutInteger(0).PutInteger(0);
247 if(S->HasArraysOfIntegers() && !S->GetArraysOfIntegersContainer().IsEmpty()) {
248 theTarget.PutInteger(1) << S->GetArraysOfIntegersContainer().Extent();
249 TDataStd_DataMapIteratorOfDataMapOfStringHArray1OfInteger
250 itr(S->GetArraysOfIntegersContainer());
251 for (; itr.More(); itr.Next()) {
252 theTarget << itr.Key(); //key
253 const TColStd_Array1OfInteger& anArr1 = itr.Value()->Array1();
254 theTarget << anArr1.Lower() <<anArr1.Upper(); // value Arr1 dimensions
255 Standard_Integer *aPtr = (Standard_Integer *) &anArr1(anArr1.Lower());
256 theTarget.PutIntArray(aPtr, anArr1.Length());
259 theTarget.PutInteger(0).PutInteger(0);
262 if(S->HasArraysOfReals() && !S->GetArraysOfRealsContainer().IsEmpty()) {
263 theTarget.PutInteger(1) << S->GetArraysOfRealsContainer().Extent(); //dim
264 TDataStd_DataMapIteratorOfDataMapOfStringHArray1OfReal
265 itr(S->GetArraysOfRealsContainer());
266 for (; itr.More(); itr.Next()) {
267 theTarget << itr.Key();//key
268 const TColStd_Array1OfReal& anArr1 = itr.Value()->Array1();
269 theTarget << anArr1.Lower() <<anArr1.Upper(); // value Arr1 dimensions
270 Standard_Real *aPtr = (Standard_Real *) &anArr1(anArr1.Lower());
271 theTarget.PutRealArray(aPtr, anArr1.Length());
274 theTarget.PutInteger(0).PutInteger(0);