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 | |
15 | #ifndef _StdLPersistent_Collection_HeaderFile |
16 | #define _StdLPersistent_Collection_HeaderFile |
17 | |
18 | #include <StdObjMgt_Attribute.hxx> |
19 | #include <StdLPersistent_HArray1.hxx> |
20 | |
21 | #include <TDataStd_IntegerArray.hxx> |
22 | #include <TDataStd_RealArray.hxx> |
23 | #include <TDataStd_ByteArray.hxx> |
24 | #include <TDataStd_ExtStringArray.hxx> |
25 | #include <TDataStd_BooleanArray.hxx> |
26 | #include <TDataStd_ReferenceArray.hxx> |
27 | #include <TDataStd_IntegerList.hxx> |
28 | #include <TDataStd_RealList.hxx> |
29 | #include <TDataStd_ExtStringList.hxx> |
30 | #include <TDataStd_BooleanList.hxx> |
31 | #include <TDataStd_ReferenceList.hxx> |
32 | #include <TDataStd_IntPackedMap.hxx> |
33 | |
34 | |
45d8465e |
35 | class StdLPersistent_Collection |
ff205346 |
36 | { |
37 | // Converters |
38 | struct noConversion; |
39 | struct byteConverter; |
dde68833 |
40 | struct boolConverter; |
ff205346 |
41 | struct stringConverter; |
42 | struct referenceConverter; |
43 | |
44 | // Base templates |
45 | template <class Base> |
46 | class booleanArrayBase : public Base |
47 | { |
48 | public: |
d533dafb |
49 | //! Empty constructor. |
50 | booleanArrayBase() |
51 | : myLower(0), |
52 | myUpper(0) |
53 | { |
54 | } |
55 | |
ff205346 |
56 | //! Read persistent data from a file. |
68df8478 |
57 | virtual void Read (StdObjMgt_ReadData& theReadData) |
58 | { |
59 | Base::Read (theReadData); |
60 | theReadData >> myLower >> myUpper; |
61 | } |
ff205346 |
62 | |
63 | protected: |
64 | template <class ArrayHandle, class Converter> |
65 | inline void import (const ArrayHandle& theArray, Converter theConverter) |
66 | const; |
67 | |
68 | protected: |
45d8465e |
69 | Standard_Integer myLower; |
70 | Standard_Integer myUpper; |
ff205346 |
71 | }; |
72 | |
73 | template <class Base> |
74 | class directArrayBase : public Base |
75 | { |
76 | protected: |
77 | template <class ArrayHandle, class Converter> |
78 | inline void import (const ArrayHandle& theArray, Converter theConverter) |
79 | const; |
80 | }; |
81 | |
82 | template <class Base> |
83 | class arrayBase : public Base |
84 | { |
85 | protected: |
86 | template <class ArrayHandle, class Converter> |
87 | inline void import (const ArrayHandle& theArray, Converter theConverter) |
88 | const; |
89 | }; |
90 | |
91 | template <class Base> |
92 | class listBase : public Base |
93 | { |
94 | protected: |
95 | template <class ArrayHandle, class Converter> |
96 | inline void import (const ArrayHandle& theArray, Converter theConverter) |
97 | const; |
98 | }; |
99 | |
100 | template <class Base> |
101 | class mapBase : public Base |
102 | { |
103 | protected: |
104 | template <class ArrayHandle, class Converter> |
105 | inline void import (const ArrayHandle& theArray, Converter theConverter) |
106 | const; |
107 | }; |
108 | |
109 | // Instance templates |
110 | template <template<class> class BaseT, |
111 | class HArrayClass, |
112 | class AttribClass, |
113 | class Converter> |
114 | class instance |
115 | : public BaseT <typename StdObjMgt_Attribute<AttribClass>::SingleRef> |
116 | { |
117 | public: |
316ea293 |
118 | //! Import transient attribute from the persistent data. |
ff205346 |
119 | Standard_EXPORT virtual void ImportAttribute(); |
120 | }; |
121 | |
122 | template <class Instance> |
123 | class instance_1 : public Instance |
124 | { |
125 | public: |
d533dafb |
126 | //! Empty constructor. |
127 | instance_1() |
128 | : myDelta(Standard_False) |
129 | { |
130 | } |
131 | |
ff205346 |
132 | //! Read persistent data from a file. |
133 | Standard_EXPORT virtual void Read (StdObjMgt_ReadData& theReadData); |
134 | |
316ea293 |
135 | //! Import transient attribute from the persistent data. |
ff205346 |
136 | Standard_EXPORT virtual void ImportAttribute(); |
137 | |
138 | private: |
45d8465e |
139 | Standard_Boolean myDelta; |
ff205346 |
140 | }; |
141 | |
142 | |
143 | // Collection type specialization |
144 | template<class HArrayClass, class AttribClass, class Converter = noConversion> |
145 | struct booleanArrayT |
146 | : instance<booleanArrayBase, HArrayClass, AttribClass, Converter> {}; |
147 | |
148 | template<class HArrayClass, class AttribClass, class Converter = noConversion> |
149 | struct directArrayT |
150 | : instance<directArrayBase, HArrayClass, AttribClass, Converter> {}; |
151 | |
152 | template<class HArrayClass, class AttribClass, class Converter = noConversion> |
153 | struct arrayT |
154 | : instance<arrayBase, HArrayClass, AttribClass, Converter> {}; |
155 | |
156 | template<class HArrayClass, class AttribClass, class Converter = noConversion> |
157 | struct listT |
158 | : instance<listBase, HArrayClass, AttribClass, Converter> {}; |
159 | |
160 | template<class HArrayClass, class AttribClass, class Converter = noConversion> |
161 | struct mapT |
162 | : instance<mapBase, HArrayClass, AttribClass, Converter> {}; |
163 | |
164 | |
165 | // Internal array types |
166 | typedef StdLPersistent_HArray1::Integer integer; |
167 | typedef StdLPersistent_HArray1::Real real; |
168 | typedef StdLPersistent_HArray1::Persistent persistent; |
169 | |
170 | public: |
171 | // Final specialization |
172 | typedef booleanArrayT <integer, TDataStd_BooleanArray, byteConverter> |
173 | BooleanArray; |
174 | |
175 | typedef directArrayT <integer, TDataStd_IntegerArray> |
176 | IntegerArray; |
177 | |
178 | typedef directArrayT <real, TDataStd_RealArray> |
179 | RealArray; |
180 | |
181 | typedef arrayT <integer, TDataStd_ByteArray, byteConverter> |
182 | ByteArray; |
183 | |
184 | typedef arrayT <persistent, TDataStd_ExtStringArray, stringConverter> |
185 | ExtStringArray; |
186 | |
187 | typedef arrayT <persistent, TDataStd_ReferenceArray, referenceConverter> |
188 | ReferenceArray; |
189 | |
190 | typedef listT <integer, TDataStd_IntegerList> |
191 | IntegerList; |
192 | |
193 | typedef listT <real, TDataStd_RealList> |
194 | RealList; |
195 | |
dde68833 |
196 | typedef listT <integer, TDataStd_BooleanList, boolConverter> |
ff205346 |
197 | BooleanList; |
198 | |
199 | typedef listT <persistent, TDataStd_ExtStringList, stringConverter> |
200 | ExtStringList; |
201 | |
202 | typedef listT <persistent, TDataStd_ReferenceList, referenceConverter> |
203 | ReferenceList; |
204 | |
205 | typedef mapT <integer, TDataStd_IntPackedMap> |
206 | IntPackedMap; |
207 | |
208 | typedef instance_1<IntegerArray> IntegerArray_1; |
209 | typedef instance_1<RealArray> RealArray_1; |
210 | typedef instance_1<ByteArray> ByteArray_1; |
211 | typedef instance_1<ExtStringArray> ExtStringArray_1; |
212 | typedef instance_1<IntPackedMap> IntPackedMap_1; |
213 | }; |
214 | |
215 | #endif |