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