summaryrefslogtreecommitdiff
path: root/src/BinMDataStd/BinMDataStd_NamedDataDriver.cxx
blob: 8a4320abf4004411040767d6cf801989e3fecb2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
// File:        BinMDataStd_NamedDataDriver.cxx
// Created:     Mon Jul  2 10:19:20 2007
// Author:      Sergey ZARITCHNY
//              <szy@popox.nnov.matra-dtv.fr>
// Copyright:   Open CasCade SA 2007

#include <BinMDataStd_NamedDataDriver.ixx>
#include <TCollection_ExtendedString.hxx>
#include <CDM_MessageDriver.hxx>
#include <TDataStd_NamedData.hxx>
#include <TColStd_HArray1OfReal.hxx>
#include <TColStd_HArray1OfInteger.hxx>
#include <TColStd_HArray1OfReal.hxx>
#include <TColStd_DataMapOfStringInteger.hxx>
#include <TDataStd_DataMapOfStringReal.hxx>
#include <TDataStd_DataMapOfStringString.hxx>
#include <TDataStd_DataMapOfStringByte.hxx>
#include <TDataStd_DataMapOfStringHArray1OfInteger.hxx>
#include <TDataStd_DataMapOfStringHArray1OfReal.hxx>
#include <TColStd_DataMapIteratorOfDataMapOfStringInteger.hxx>
#include <TDataStd_DataMapIteratorOfDataMapOfStringReal.hxx>
#include <TDataStd_DataMapIteratorOfDataMapOfStringString.hxx>
#include <TDataStd_DataMapIteratorOfDataMapOfStringByte.hxx>
#include <TDataStd_DataMapIteratorOfDataMapOfStringHArray1OfInteger.hxx>
#include <TDataStd_DataMapIteratorOfDataMapOfStringHArray1OfReal.hxx>


//=======================================================================
//function : BinMDataStd_NamedDataDriver
//purpose  : Constructor
//=======================================================================
BinMDataStd_NamedDataDriver::BinMDataStd_NamedDataDriver(const Handle(CDM_MessageDriver)& theMsgDriver)
     : BinMDF_ADriver (theMsgDriver, STANDARD_TYPE(TDataStd_NamedData)->Name())
{

}

//=======================================================================
//function : NewEmpty
//purpose  : 
//=======================================================================
Handle(TDF_Attribute) BinMDataStd_NamedDataDriver::NewEmpty() const
{
  return new TDataStd_NamedData();
}

//=======================================================================
//function : Paste
//purpose  : persistent -> transient (retrieve)
//=======================================================================
Standard_Boolean BinMDataStd_NamedDataDriver::Paste(const BinObjMgt_Persistent&  theSource,
						      const Handle(TDF_Attribute)& theTarget,
						      BinObjMgt_RRelocationTable&  ) const
{

  Handle(TDataStd_NamedData) T = Handle(TDataStd_NamedData)::DownCast(theTarget);
  if(T.IsNull()) return Standard_False;
  Standard_Integer aLower, anUpper,i;
  if (! (theSource >> aLower >> anUpper))
    return Standard_False;
//  const Standard_Integer aLength = anUpper - aLower + 1;
  if (anUpper < aLower)  return Standard_False;
  if(anUpper | aLower) {
    TColStd_DataMapOfStringInteger anIntegers;
    for (i=aLower; i<=anUpper; i++) {
      TCollection_ExtendedString aKey;
      Standard_Integer aValue;
      if (! (theSource >> aKey >> aValue))
        return Standard_False;
      anIntegers.Bind(aKey, aValue);
    }
    T->ChangeIntegers(anIntegers);
  }

  if (! (theSource >> aLower >> anUpper))
    return Standard_False;
  if (anUpper < aLower)  return Standard_False;
  if(anUpper | aLower) {
    TDataStd_DataMapOfStringReal aReals;
    for (i=aLower; i<=anUpper; i++) {
      TCollection_ExtendedString aKey;
      Standard_Real aValue;
      if (! (theSource >> aKey >> aValue))
        return Standard_False;
      aReals.Bind(aKey, aValue);
    }
    T->ChangeReals(aReals);
  }

// strings
  if (! (theSource >> aLower >> anUpper))
    return Standard_False;
  if (anUpper < aLower)  return Standard_False;
  if(anUpper | aLower) {
    TDataStd_DataMapOfStringString aStrings;
    for (i=aLower; i<=anUpper; i++) {
      TCollection_ExtendedString aKey;
      TCollection_ExtendedString aValue;
      if (! (theSource >> aKey >> aValue))
        return Standard_False;
      aStrings.Bind(aKey, aValue);
    }
    T->ChangeStrings(aStrings);
  }

//Bytes
  if (! (theSource >> aLower >> anUpper))
    return Standard_False;
  if (anUpper < aLower)  return Standard_False;
  if(anUpper | aLower) {
    TDataStd_DataMapOfStringByte aBytes;
    for (i=aLower; i<=anUpper; i++) {
      TCollection_ExtendedString aKey;
      Standard_Byte aValue;
      if (! (theSource >> aKey >> aValue))
        return Standard_False;
      aBytes.Bind(aKey, (Standard_Byte)aValue);
    }
    T->ChangeBytes(aBytes);
  }

// arrays of integers
  if (! (theSource >> aLower >> anUpper))
    return Standard_False;
  if (anUpper < aLower)  return Standard_False;
  Standard_Boolean aResult = Standard_False;
  if(anUpper | aLower) {
    TDataStd_DataMapOfStringHArray1OfInteger anIntArrays;
    for (i=aLower; i<=anUpper; i++) {
      TCollection_ExtendedString aKey;
      if (! (theSource >> aKey))
        return Standard_False;
      Standard_Integer low, up;
      if (! (theSource >> low >> up))
        return Standard_False;
      if(up < low)
        return Standard_False;
      if(up | low) {
	Handle(TColStd_HArray1OfInteger) aTargetArray = new TColStd_HArray1OfInteger (low, up);
	if(!theSource.GetIntArray (&(aTargetArray->ChangeArray1())(low), up-low+1))
	  return Standard_False;
	
	Standard_Boolean Ok = anIntArrays.Bind(aKey, aTargetArray);
	aResult |= Ok;
      }
    }
    if (aResult) 
      T->ChangeArraysOfIntegers(anIntArrays);
  }

// arrays of reals
  if (! (theSource >> aLower >> anUpper))
    return Standard_False;
  if (anUpper < aLower)  return Standard_False;
  aResult = Standard_False;
  if(anUpper | aLower) {
    TDataStd_DataMapOfStringHArray1OfReal aRealArrays;
    for (i=aLower; i<=anUpper; i++) {
      TCollection_ExtendedString aKey;
      if (! (theSource >> aKey))
        return Standard_False;
      Standard_Integer low, up;
      if (! (theSource >> low >> up))
        return Standard_False;
      if(up < low)
        return Standard_False;
      if(low | up) {
        Handle(TColStd_HArray1OfReal) aTargetArray =
          new TColStd_HArray1OfReal(low, up);
        if(!theSource.GetRealArray (&(aTargetArray->ChangeArray1())(low), up-low+1))
          return Standard_False;
        Standard_Boolean Ok = aRealArrays.Bind(aKey, aTargetArray);
        aResult |= Ok;
      }
    }
    if(aResult)
      T->ChangeArraysOfReals(aRealArrays);
  }
  return Standard_True;
}

//=======================================================================
//function : Paste
//purpose  : transient -> persistent (store)
//=======================================================================
void BinMDataStd_NamedDataDriver::Paste(const Handle(TDF_Attribute)& theSource,
                                        BinObjMgt_Persistent&        theTarget,
                                        BinObjMgt_SRelocationTable&  ) const
{
  Handle(TDataStd_NamedData) S = Handle(TDataStd_NamedData)::DownCast (theSource);
  if(S.IsNull()) return;
//  Standard_Integer i=0;
  
  if(S->HasIntegers() && !S->GetIntegersContainer().IsEmpty()) {
    theTarget.PutInteger(1) << S->GetIntegersContainer().Extent(); //dim
    TColStd_DataMapIteratorOfDataMapOfStringInteger itr(S->GetIntegersContainer());
    for (; itr.More(); itr.Next()) {
      theTarget << itr.Key() << itr.Value(); // key - value;
    }
  } else {
    theTarget.PutInteger(0).PutInteger(0);
  }
    
  if(S->HasReals() && !S->GetRealsContainer().IsEmpty()) {
    theTarget.PutInteger(1) << S->GetRealsContainer().Extent();
    TDataStd_DataMapIteratorOfDataMapOfStringReal itr(S->GetRealsContainer());
    for (; itr.More(); itr.Next()) {
      theTarget << itr.Key() << itr.Value();
    }
  } else {
    theTarget.PutInteger(0).PutInteger(0);
  }

  if(S->HasStrings() && !S->GetStringsContainer().IsEmpty()) {
    theTarget.PutInteger(1) << S->GetStringsContainer().Extent();
    TDataStd_DataMapIteratorOfDataMapOfStringString itr(S->GetStringsContainer());
    for (; itr.More(); itr.Next()) {
      theTarget << itr.Key() << itr.Value();
    }
  } else {
    theTarget.PutInteger(0).PutInteger(0);
  }

  if(S->HasBytes() && !S->GetBytesContainer().IsEmpty()) {
    theTarget.PutInteger(1) << S->GetBytesContainer().Extent();
    TDataStd_DataMapIteratorOfDataMapOfStringByte itr(S->GetBytesContainer());
    for (; itr.More(); itr.Next()) {
      theTarget << itr.Key() << (Standard_Byte) itr.Value();
    }
  } else {
    theTarget.PutInteger(0).PutInteger(0);
  }

  if(S->HasArraysOfIntegers() && !S->GetArraysOfIntegersContainer().IsEmpty()) {
    theTarget.PutInteger(1) << S->GetArraysOfIntegersContainer().Extent();
    TDataStd_DataMapIteratorOfDataMapOfStringHArray1OfInteger
      itr(S->GetArraysOfIntegersContainer());
    for (; itr.More(); itr.Next()) {
      theTarget << itr.Key(); //key
      const TColStd_Array1OfInteger& anArr1 = itr.Value()->Array1();
      theTarget << anArr1.Lower() <<anArr1.Upper(); // value Arr1 dimensions
      Standard_Integer *aPtr = (Standard_Integer *) &anArr1(anArr1.Lower());
      theTarget.PutIntArray(aPtr, anArr1.Length());
    }
  } else {
    theTarget.PutInteger(0).PutInteger(0);
  }

  if(S->HasArraysOfReals() && !S->GetArraysOfRealsContainer().IsEmpty()) {
    theTarget.PutInteger(1) << S->GetArraysOfRealsContainer().Extent(); //dim
    TDataStd_DataMapIteratorOfDataMapOfStringHArray1OfReal
      itr(S->GetArraysOfRealsContainer());
    for (; itr.More(); itr.Next()) {
      theTarget << itr.Key();//key
      const TColStd_Array1OfReal& anArr1 = itr.Value()->Array1();
      theTarget << anArr1.Lower() <<anArr1.Upper(); // value Arr1 dimensions
      Standard_Real *aPtr = (Standard_Real *) &anArr1(anArr1.Lower());
      theTarget.PutRealArray(aPtr, anArr1.Length());
    }
  } else {
    theTarget.PutInteger(0).PutInteger(0);
  }
}