62ecfb6c88f2f41a80ed4ca9c4deeee4994fd1d7
[occt.git] / src / Storage / Storage_Macros.hxx
1 // Copyright (c) 1998-1999 Matra Datavision
2 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 //
4 // The content of this file is subject to the Open CASCADE Technology Public
5 // License Version 6.5 (the "License"). You may not use the content of this file
6 // except in compliance with the License. Please obtain a copy of the License
7 // at http://www.opencascade.org and read it completely before using this file.
8 //
9 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 //
12 // The Original Code and all software distributed under the License is
13 // distributed on an "AS IS" basis, without warranty of any kind, and the
14 // Initial Developer hereby disclaims all such warranties, including without
15 // limitation, any warranties of merchantability, fitness for a particular
16 // purpose or non-infringement. Please see the License for the specific terms
17 // and conditions governing the rights and limitations under the License.
18
19 #ifndef _Storage_Macros_HeaderFile
20 #define _Storage_Macros_HeaderFile 1
21 #include <Storage_SolveMode.hxx>
22
23 // PROTOTYPES
24 #define Storage_DECLARE_SCHEMA_METHODS(schema)  public: \
25 Standard_EXPORT Handle(Storage_CallBack)  CallBackSelection(const TCollection_AsciiString&) const; \
26   Standard_EXPORT Handle(Storage_CallBack)  AddTypeSelection(const Handle(Standard_Persistent)&) const; \
27   Standard_EXPORT const TColStd_SequenceOfAsciiString& SchemaKnownTypes() const;
28
29 // Read_TypeSelection
30 //
31 #define Storage_BEGIN_READ_SELECTION(schema) \
32                   extern "C" { \
33                   Standard_EXPORT Handle(Storage_Schema) Create##schema() { return new schema; } \
34                              } \
35                   Handle(Storage_CallBack) schema::CallBackSelection(const TCollection_AsciiString& rt) const \
36                                              { \
37                                               Handle(Standard_Persistent) p; \
38                                               Handle(Storage_CallBack) cback;
39
40 #define Storage_READ_SELECTION(schema,classe,callback) if (strcmp(rt.ToCString(),#classe) == 0) { \
41                                                          cback = new  callback ; \
42                                                          return cback; \
43                                                        }
44
45 #define Storage_END_READ_SELECTION(schema)  cback = ResolveUnknownType(rt,p,Storage_WriteSolve); \
46                                             return cback; \
47                                           }
48
49 // SchemaKnownTypes
50 //
51 #define Storage_BEGIN_SCHEMA_TYPES(schema) const TColStd_SequenceOfAsciiString& schema::SchemaKnownTypes() const \
52                                            { \
53                                              static TColStd_SequenceOfAsciiString aSeq; \
54                                              static Standard_Boolean              jsuidjaalai = Standard_False; \
55                                              if (!jsuidjaalai) { \
56                                                  jsuidjaalai = Standard_True;
57
58 #define Storage_SCHEMA_TYPES(classe) aSeq.Append(#classe);
59 #define Storage_END_SCHEMA_TYPES(schema)   } return aSeq; \
60                                           }
61
62 // ADD_TypeSelection
63 //
64
65 #define Storage_BEGIN_ADD_TYPES(schema) Handle(Storage_CallBack) schema::AddTypeSelection(const Handle(Standard_Persistent)& p) const \
66                                          { \
67                                           Handle(Storage_CallBack) cback; \
68                                           if (!p.IsNull()) { \
69                                             const Handle(Standard_Type)& t = p->DynamicType(); \
70                                             static TCollection_AsciiString theTypeName;\
71                                             theTypeName = t->Name(); \
72                                             if (HasTypeBinding(theTypeName)) { \
73                                                 cback = TypeBinding(theTypeName); \
74                                                 cback->Add(p,this); \
75                                                 return cback; \
76                                             }
77
78 #define Storage_ADD_TYPES(schema,classe,callback) if (t == classe##_Type_()) { \
79                                                     cback = new callback ; \
80                                                     BindType(theTypeName,cback); \
81                                                     cback->Add(p,this); \
82                                                     return cback; \
83                                                   }
84
85 #define Storage_END_ADD_TYPES(schema)            cback = ResolveUnknownType(theTypeName,p,Storage_AddSolve); \
86                                                  if (!cback.IsNull()) { \
87                                                     cback->Add(p,this); \
88                                                  } \
89                                                  return cback; \
90                                           }  \
91                                         return cback; \
92                                       }
93 #endif