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 | #ifndef _StdObjMgt_ContentTypes_HeaderFile |
15 | #define _StdObjMgt_ContentTypes_HeaderFile |
16 | |
17 | |
18 | #include <StdObjMgt_ReadData.hxx> |
19 | |
20 | class StdObjMgt_Persistent; |
21 | |
22 | |
23 | //! Root class for an object containing other obects. |
24 | class StdObjMgt_ContentTypes |
25 | { |
26 | template <typename Type> |
27 | class holder |
28 | { |
29 | public: |
30 | //! Return the value. |
31 | operator Type() const { return myValue; } |
32 | |
33 | protected: |
34 | Type myValue; |
35 | }; |
36 | |
37 | template <typename Type> |
38 | struct enum_ : holder<Type> |
39 | { |
40 | //! Read the value from a file. |
41 | void Read (StdObjMgt_ReadData& theReadData) |
42 | { theReadData.ReadEnum (this->myValue); } |
43 | }; |
44 | |
45 | template <typename Type> |
46 | struct value : holder<Type> |
47 | { |
48 | //! Read the value from a file. |
49 | void Read (StdObjMgt_ReadData& theReadData) |
50 | { theReadData.ReadValue (this->myValue); } |
51 | }; |
52 | |
53 | template <class Class> |
54 | struct object : Class |
55 | { |
56 | //! Read object data from a file. |
57 | void Read (StdObjMgt_ReadData& theReadData) |
58 | { theReadData.ReadObject ((Class&)*this); } |
59 | }; |
60 | |
61 | template <class Persistent> |
62 | struct referenceT : Handle(Persistent) |
63 | { |
64 | //! Read object data from a file. |
65 | void Read (StdObjMgt_ReadData& theReadData) |
66 | { theReadData.ReadReference (*this); } |
67 | }; |
68 | |
69 | struct reference : Handle(StdObjMgt_Persistent) |
70 | { |
71 | //! Read object data from a file. |
72 | void Read (StdObjMgt_ReadData& theReadData) |
73 | { Handle(StdObjMgt_Persistent)::operator= (theReadData.ReadReference()); } |
74 | |
75 | //! Cast the reference to a target type. |
76 | template <class Persistent> |
77 | bool Cast (Handle(Persistent)& theTarget) const |
78 | { |
79 | theTarget = Handle(Persistent)::DownCast(*this); |
80 | return ! theTarget.IsNull(); |
81 | } |
82 | }; |
83 | |
84 | public: |
85 | template <class Type> |
86 | struct Enum : StdObjMgt_ReadData::Content <enum_<Type> > {}; |
87 | |
88 | template <class Type> |
89 | struct Value : StdObjMgt_ReadData::Content <value<Type> > {}; |
90 | |
91 | template <class Class> |
92 | struct Object : StdObjMgt_ReadData::Content <object<Class> > {}; |
93 | |
94 | template <class Persistent = StdObjMgt_Persistent> |
95 | struct Reference : StdObjMgt_ReadData::Content <referenceT<Persistent> > {}; |
96 | }; |
97 | |
98 | template<> |
99 | struct StdObjMgt_ContentTypes::Reference<StdObjMgt_Persistent> |
100 | : StdObjMgt_ReadData::Content <reference> {}; |
101 | |
102 | #endif // _StdObjMgt_ContentTypes_HeaderFile |