1 #ifndef COIN_SCXMLSUBOBJECT_H
2 #define COIN_SCXMLSUBOBJECT_H
3 
4 /**************************************************************************\
5  * Copyright (c) Kongsberg Oil & Gas Technologies AS
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are
10  * met:
11  *
12  * Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in the
17  * documentation and/or other materials provided with the distribution.
18  *
19  * Neither the name of the copyright holder nor the names of its
20  * contributors may be used to endorse or promote products derived from
21  * this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 \**************************************************************************/
35 
36 #include <Inventor/SbName.h>
37 
38 /*
39  * This file contains macros for setting up the classes in the ScXML
40  * subsystem (Statechart XML) in Coin. They loosely follow the macros
41  * design for nodes and nodekits and engines, etc.
42  */
43 
44 // *************************************************************************
45 
46 #define SCXML_OBJECT_HEADER(classname)                          \
47 public:                                                         \
48   static SoType getClassTypeId(void);                           \
49   virtual SoType getTypeId(void) const;                         \
50   static void * createInstance(void);                           \
51 private:                                                        \
52   static SoType classTypeId;
53 
54 // *************************************************************************
55 
56 #define SCXML_OBJECT_ABSTRACT_HEADER(classname)                 \
57 public:                                                         \
58   static SoType getClassTypeId(void);                           \
59   virtual SoType getTypeId(void) const = 0;                     \
60 private:                                                        \
61   static SoType classTypeId;
62 
63 // *************************************************************************
64 
65 #define SCXML_ELEMENT_ABSTRACT_HEADER(classname)                \
66   SCXML_OBJECT_ABSTRACT_HEADER(classname)
67 
68 // *************************************************************************
69 
70 // FIXME: element-reader must be reenatrant/threadsafe
71 #define SCXML_ELEMENT_HEADER(classname)                         \
72 public:                                                         \
73   static ScXMLEltReader * getElementReader(void);               \
74 private:                                                        \
75   static ScXMLEltReader * elementReader;                        \
76   SCXML_OBJECT_HEADER(classname)
77 
78 // *************************************************************************
79 
80 #define SCXML_OBJECT_SOURCE(classname)                          \
81                                                                 \
82 SoType classname::classTypeId = SoType::badType();              \
83                                                                 \
84 SoType                                                          \
85 classname::getClassTypeId(void)                                 \
86 {                                                               \
87   return classname::classTypeId;                                \
88 }                                                               \
89                                                                 \
90 SoType                                                          \
91 classname::getTypeId(void) const                                \
92 {                                                               \
93   return classname::classTypeId;                                \
94 }                                                               \
95                                                                 \
96 void *                                                          \
97 classname::createInstance(void)                                 \
98 {                                                               \
99   return static_cast<void *>(new classname);                    \
100 }
101 
102 // *************************************************************************
103 
104 #define SCXML_OBJECT_ABSTRACT_SOURCE(classname)                 \
105                                                                 \
106 SoType classname::classTypeId = SoType::badType();              \
107                                                                 \
108 SoType                                                          \
109 classname::getClassTypeId(void)                                 \
110 {                                                               \
111   return classname::classTypeId;                                \
112 }
113 
114 #define SCXML_ELEMENT_ABSTRACT_SOURCE(classname)                \
115   SCXML_OBJECT_ABSTRACT_SOURCE(classname)
116 
117 #define SCXML_ELEMENT_SOURCE(classname)                         \
118 ScXMLEltReader * classname::elementReader = NULL;               \
119                                                                 \
120 ScXMLEltReader *                                                \
121 classname::getElementReader(void)                               \
122 {                                                               \
123   return classname::elementReader;                              \
124 }                                                               \
125                                                                 \
126   SCXML_OBJECT_SOURCE(classname)
127 
128 // *************************************************************************
129 
130 #define SCXML_OBJECT_INIT_CLASS(thisclass, parentclass, parentname)     \
131   do {                                                                  \
132     SoType parenttype = SoType::fromName(SO__QUOTE(parentclass));       \
133     assert(parenttype != SoType::badType());                            \
134     thisclass::classTypeId =                                            \
135       SoType::createType(parenttype,                                    \
136                          SbName(SO__QUOTE(thisclass)),                  \
137                          thisclass::createInstance);                    \
138  /* ScXMLObject::registerClassType(xmlns, xmlclass,                     \
139                                    thisclass::classTypeId); */          \
140   } while ( FALSE )
141 
142 
143 #define SCXML_ELEMENT_REGISTER_READER(thisclass, xmlelement, classname) \
144   do {                                                                  \
145     thisclass::elementReader = new classname;                           \
146   } while ( FALSE )
147 
148 #define SCXML_ELEMENT_UNREGISTER_READER(thisclass) \
149   do {                                                                  \
150     delete thisclass::elementReader;                                    \
151     thisclass::elementReader = NULL;                                    \
152   } while ( FALSE )
153 
154 // *************************************************************************
155 
156 #define SCXML_OBJECT_INIT_ABSTRACT_CLASS(thisclass, parentclass, parentname) \
157   do {                                                                  \
158     SoType parenttype = SoType::fromName(SO__QUOTE(parentclass));       \
159     assert(parenttype != SoType::badType());                            \
160     thisclass::classTypeId =                                            \
161       SoType::createType(parenttype, SbName(SO__QUOTE(thisclass)));     \
162   } while ( FALSE )
163 
164 // *************************************************************************
165 
166 #define SCXML_INVOKE_INIT_CLASS(thisclass, parentclass, xmlns, targettype, source) \
167   do {                                                                  \
168     SoType parenttype = SoType::fromName(SO__QUOTE(parentclass));       \
169     assert(parenttype != SoType::badType());                            \
170     thisclass::classTypeId =                                            \
171       SoType::createType(parenttype,                                    \
172                          SbName(SO__QUOTE(thisclass)),                  \
173                          thisclass::createInstance);                    \
174     ScXMLObject::registerInvokeClassType(xmlns, targettype, source,     \
175                                          thisclass::classTypeId);       \
176   } while ( FALSE )
177 
178 // *************************************************************************
179 
180 
181 #endif // !COIN_SCXMLSUBOBJECT_H
182