ff205346 |
1 | // Copyright (c) 2015 OPEN CASCADE SAS |
2 | // |
3 | // This file is part of Open CASCADE Technology software library. |
4 | // |
5 | // This library is free software; you can redistribute it and/or modify it under |
6 | // the terms of the GNU Lesser General Public License version 2.1 as published |
7 | // by the Free Software Foundation, with special exception defined in the file |
8 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
9 | // distribution for complete text of the license and disclaimer of any warranty. |
10 | // |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
13 | |
14 | #include <StdLPersistent_NamedData.hxx> |
15 | |
ff205346 |
16 | #include <TColStd_DataMapOfStringInteger.hxx> |
17 | #include <TDataStd_DataMapOfStringReal.hxx> |
18 | #include <TDataStd_DataMapOfStringString.hxx> |
19 | #include <TDataStd_DataMapOfStringByte.hxx> |
20 | #include <TDataStd_DataMapOfStringHArray1OfInteger.hxx> |
21 | #include <TDataStd_DataMapOfStringHArray1OfReal.hxx> |
22 | |
23 | |
45d8465e |
24 | static const TCollection_ExtendedString& |
25 | String (Handle(StdObjMgt_Persistent) theValue) |
26 | { |
27 | if (theValue) |
28 | return theValue->ExtString()->String(); |
29 | |
30 | static TCollection_ExtendedString anEmptyString; |
31 | return anEmptyString; |
32 | } |
33 | |
34 | template <class HArray> |
35 | static typename HArray::ArrayHandle |
36 | Array (Handle(StdObjMgt_Persistent) theValue) |
37 | { |
38 | Handle(HArray) anArray = Handle(HArray)::DownCast (theValue); |
39 | return anArray ? anArray->Array() : NULL; |
40 | } |
41 | |
ff205346 |
42 | //======================================================================= |
43 | //function : Import |
44 | //purpose : Import transient attribuite from the persistent data |
45 | //======================================================================= |
46 | void StdLPersistent_NamedData::Import |
47 | (const Handle(TDataStd_NamedData)& theAttribute) const |
48 | { |
49 | if (myDimensions.IsNull()) |
50 | return; |
51 | |
52 | if (myInts) |
53 | { |
54 | TColStd_DataMapOfStringInteger aMap; |
55 | for (Standard_Integer i = lower(0); i <= upper(0); i++) |
45d8465e |
56 | aMap.Bind (myInts.Key(i), myInts.Value(i)); |
57 | |
ff205346 |
58 | theAttribute->ChangeIntegers (aMap); |
59 | } |
60 | |
61 | if (myReals) |
62 | { |
63 | TDataStd_DataMapOfStringReal aMap; |
64 | for (Standard_Integer i = lower(1); i <= upper(1); i++) |
45d8465e |
65 | aMap.Bind (myReals.Key(i), myReals.Value(i)); |
66 | |
ff205346 |
67 | theAttribute->ChangeReals (aMap); |
68 | } |
69 | |
70 | if (myStrings) |
71 | { |
72 | TDataStd_DataMapOfStringString aMap; |
73 | for (Standard_Integer i = lower(2); i <= upper(2); i++) |
45d8465e |
74 | aMap.Bind (myStrings.Key(i), String (myStrings.Value(i))); |
75 | |
ff205346 |
76 | theAttribute->ChangeStrings (aMap); |
77 | } |
78 | |
79 | if (myBytes) |
80 | { |
81 | TDataStd_DataMapOfStringByte aMap; |
82 | for (Standard_Integer i = lower(3); i <= upper(3); i++) |
45d8465e |
83 | aMap.Bind (myBytes.Key(i), myBytes.Value(i)); |
84 | |
ff205346 |
85 | theAttribute->ChangeBytes (aMap); |
86 | } |
87 | |
88 | if (myIntArrays) |
89 | { |
90 | TDataStd_DataMapOfStringHArray1OfInteger aMap; |
91 | for (Standard_Integer i = lower(4); i <= upper(4); i++) |
45d8465e |
92 | aMap.Bind (myIntArrays.Key(i), |
93 | Array<StdLPersistent_HArray1::Integer> (myIntArrays.Value(i))); |
ff205346 |
94 | |
ff205346 |
95 | theAttribute->ChangeArraysOfIntegers (aMap); |
96 | } |
97 | |
98 | if (myRealArrays) |
99 | { |
100 | TDataStd_DataMapOfStringHArray1OfReal aMap; |
101 | for (Standard_Integer i = lower(5); i <= upper(5); i++) |
45d8465e |
102 | aMap.Bind (myRealArrays.Key(i), |
103 | Array<StdLPersistent_HArray1::Real> (myRealArrays.Value(i))); |
ff205346 |
104 | |
ff205346 |
105 | theAttribute->ChangeArraysOfReals (aMap); |
106 | } |
107 | } |
108 | |
109 | Standard_Integer |
110 | StdLPersistent_NamedData::lower (Standard_Integer theIndex) const |
111 | { |
112 | const Handle(TColStd_HArray2OfInteger)& aDimensions = myDimensions->Array(); |
113 | return aDimensions->Value (aDimensions->LowerRow() + theIndex, |
114 | aDimensions->LowerCol()); |
115 | } |
116 | |
117 | Standard_Integer |
118 | StdLPersistent_NamedData::upper (Standard_Integer theIndex) const |
119 | { |
120 | const Handle(TColStd_HArray2OfInteger)& aDimensions = myDimensions->Array(); |
121 | return aDimensions->Value (aDimensions->LowerRow() + theIndex, |
122 | aDimensions->UpperCol()); |
123 | } |