0029220: Application Framework - replace CDM_MessageDriver interface by Message_Messe...
[occt.git] / src / BinMDataStd / BinMDataStd_NamedDataDriver.cxx
CommitLineData
b311480e 1// Created on: 2007-07-02
2// Created by: Sergey ZARITCHNY
973c2be1 3// Copyright (c) 2007-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 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
973c2be1 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.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
7fd59977 15
42cf5bc1 16
17#include <BinMDataStd_NamedDataDriver.hxx>
18#include <BinObjMgt_Persistent.hxx>
83ae3591 19#include <Message_Messenger.hxx>
42cf5bc1 20#include <Standard_Type.hxx>
21#include <TCollection_ExtendedString.hxx>
22#include <TColStd_DataMapIteratorOfDataMapOfStringInteger.hxx>
23#include <TColStd_DataMapOfStringInteger.hxx>
7fd59977 24#include <TColStd_HArray1OfInteger.hxx>
25#include <TColStd_HArray1OfReal.hxx>
7fd59977 26#include <TDataStd_DataMapIteratorOfDataMapOfStringByte.hxx>
27#include <TDataStd_DataMapIteratorOfDataMapOfStringHArray1OfInteger.hxx>
28#include <TDataStd_DataMapIteratorOfDataMapOfStringHArray1OfReal.hxx>
42cf5bc1 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>
7fd59977 38
92efcf78 39IMPLEMENT_STANDARD_RTTIEXT(BinMDataStd_NamedDataDriver,BinMDF_ADriver)
40
7fd59977 41//=======================================================================
42//function : BinMDataStd_NamedDataDriver
43//purpose : Constructor
44//=======================================================================
83ae3591 45BinMDataStd_NamedDataDriver::BinMDataStd_NamedDataDriver(const Handle(Message_Messenger)& theMsgDriver)
7fd59977 46 : BinMDF_ADriver (theMsgDriver, STANDARD_TYPE(TDataStd_NamedData)->Name())
47{
48
49}
50
51//=======================================================================
52//function : NewEmpty
3616fc06 53//purpose :
7fd59977 54//=======================================================================
55Handle(TDF_Attribute) BinMDataStd_NamedDataDriver::NewEmpty() const
56{
57 return new TDataStd_NamedData();
58}
59
60//=======================================================================
61//function : Paste
62//purpose : persistent -> transient (retrieve)
63//=======================================================================
64Standard_Boolean BinMDataStd_NamedDataDriver::Paste(const BinObjMgt_Persistent& theSource,
65 const Handle(TDF_Attribute)& theTarget,
66 BinObjMgt_RRelocationTable& ) const
67{
68
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);
84 }
85 T->ChangeIntegers(anIntegers);
86 }
87
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;
95 Standard_Real aValue;
96 if (! (theSource >> aKey >> aValue))
97 return Standard_False;
98 aReals.Bind(aKey, aValue);
99 }
100 T->ChangeReals(aReals);
101 }
102
103// strings
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);
115 }
116 T->ChangeStrings(aStrings);
117 }
118
119//Bytes
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);
131 }
132 T->ChangeBytes(aBytes);
133 }
134
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;
149 if(up < low)
150 return Standard_False;
151 if(up | low) {
152 Handle(TColStd_HArray1OfInteger) aTargetArray = new TColStd_HArray1OfInteger (low, up);
153 if(!theSource.GetIntArray (&(aTargetArray->ChangeArray1())(low), up-low+1))
154 return Standard_False;
3616fc06 155
7fd59977 156 Standard_Boolean Ok = anIntArrays.Bind(aKey, aTargetArray);
157 aResult |= Ok;
158 }
159 }
3616fc06 160 if (aResult)
7fd59977 161 T->ChangeArraysOfIntegers(anIntArrays);
162 }
163
164// arrays of reals
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;
3616fc06 178 if (up < low)
179 return Standard_False;
7fd59977 180 if(low | up) {
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);
186 aResult |= Ok;
187 }
188 }
189 if(aResult)
190 T->ChangeArraysOfReals(aRealArrays);
191 }
192 return Standard_True;
193}
194
195//=======================================================================
196//function : Paste
197//purpose : transient -> persistent (store)
198//=======================================================================
199void BinMDataStd_NamedDataDriver::Paste(const Handle(TDF_Attribute)& theSource,
200 BinObjMgt_Persistent& theTarget,
201 BinObjMgt_SRelocationTable& ) const
202{
203 Handle(TDataStd_NamedData) S = Handle(TDataStd_NamedData)::DownCast (theSource);
204 if(S.IsNull()) return;
205// Standard_Integer i=0;
3616fc06 206
7fd59977 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;
212 }
213 } else {
214 theTarget.PutInteger(0).PutInteger(0);
215 }
3616fc06 216
7fd59977 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();
222 }
223 } else {
224 theTarget.PutInteger(0).PutInteger(0);
225 }
226
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();
232 }
233 } else {
234 theTarget.PutInteger(0).PutInteger(0);
235 }
236
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();
242 }
243 } else {
244 theTarget.PutInteger(0).PutInteger(0);
245 }
246
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());
257 }
258 } else {
259 theTarget.PutInteger(0).PutInteger(0);
260 }
261
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());
272 }
273 } else {
274 theTarget.PutInteger(0).PutInteger(0);
275 }
276}