Open Inventor Release 2024.2.1
 
Loading...
Searching...
No Matches
SoSubAction.h
1/*=======================================================================
2 * Copyright 1991-1996, Silicon Graphics, Inc.
3 * ALL RIGHTS RESERVED
4 *
5 * UNPUBLISHED -- Rights reserved under the copyright laws of the United
6 * States. Use of a copyright notice is precautionary only and does not
7 * imply publication or disclosure.
8 *
9 * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND:
10 * Use, duplication or disclosure by the Government is subject to restrictions
11 * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights
12 * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or
13 * in similar or successor clauses in the FAR, or the DOD or NASA FAR
14 * Supplement. Contractor/manufacturer is Silicon Graphics, Inc.,
15 * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311.
16 *
17 * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY
18 * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION,
19 * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY
20 * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON
21 * GRAPHICS, INC.
22**=======================================================================*/
23/*=======================================================================
24** Author : Paul S. Strauss (MMM yyyy)
25**=======================================================================*/
26/*=======================================================================
27 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
28 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
29 *** ***
30 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
31 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
32 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
33 *** ***
34 *** RESTRICTED RIGHTS LEGEND ***
35 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
36 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
37 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
38 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
39 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
40 *** ***
41 *** COPYRIGHT (C) 1996-2023 BY FEI S.A.S, ***
42 *** BORDEAUX, FRANCE ***
43 *** ALL RIGHTS RESERVED ***
44**=======================================================================*/
45/*=======================================================================
46** Modified by : VSG (MMM YYYY)
47**=======================================================================*/
48
49
50#ifndef _SO_SUB_ACTION_
51#define _SO_SUB_ACTION_
52
53#include <Inventor/actions/SoAction.h>
54#include <Inventor/SbString.h>
55#include <Inventor/errors/SoDebugError.h>
56
58//
59// Macros to be called within the class definition header for an action
60// subclass:
61//
62
64//
65// This defines type-identifier variables and methods that all
66// subclasses must support.
67//
68
69#define SO_ACTION_HEADER(className) \
70public: \
71 \
72 virtual SoType getTypeId() const; \
73 \
74 static SoType getClassTypeId(); \
75 private:\
76 static void addMethod(SoType t, SoActionMethod* method); \
77 \
78 static void enableElement(SoType t, int stkIndex); \
79\
80
81 virtual const SoEnabledElementsList & getEnabledElements() const; \
82private: \
83 \
84 static SoEnabledElementsList *enabledElements; \
85 static SoActionMethodList *methods; \
86 \
87private: \
88 virtual SoActionMethodList * getActionMethods(); \
89 \
90private: \
91 static SoType classTypeId; \
92 static SbBool classTypeIdIsSet
93
94// Deprecated: use SO_ACTION_HEADER
95#define SO_ACTION_HEADER_WITH_DEF(className) \
96 SO_ACTION_HEADER(className)
97
99//
100// Macros to be called within the source file for a action subclass:
101//
102
104//
105// This declares the static variables defined in SO_ACTION_HEADER.
106//
107
108#define SO__ACTION_VARS(className) \
109 SoEnabledElementsList *className::enabledElements = NULL; \
110 SoActionMethodList *className::methods = NULL; \
111 SoType className::classTypeId; \
112 SbBool className::classTypeIdIsSet = FALSE
113
115//
116// This contains the definitions necessary at file scope
117//
118#define SO_ACTION_SOURCE(className) \
119 SO__ACTION_VARS(className); \
120 SO__ACTION_METHODS(className)
121
122#define SO_ACTION_AUTOINIT_SOURCE(className, parentClass) \
123 SO__ACTION_VARS(className); \
124 SO__ACTION_AUTOINIT_METHODS(className, parentClass)
125
127//
128// This initializes the type identifer variables defined in
129// SO_ACTION_HEADER. This macro should be called from within
130// initClass().
131//
132#if defined(_DEBUG)
133#define SO_ACTION_INIT_CLASS_CHECK_PARENT(className, parentClass) \
134 if (parentClass::getClassTypeId().isBad()) { \
135 SoDebugError::post( SO__QUOTE(className)"::initClass", \
136 SO__QUOTE(className)" initialized before parent class " \
137 SO__QUOTE(parentClass)"\n"); \
138 parentClass::initClass(); \
139 }
140#else
141#define SO_ACTION_INIT_CLASS_CHECK_PARENT(className, parentClass) \
142 if (parentClass::getClassTypeId().isBad()) \
143 parentClass::initClass()
144#endif
145
146#define SO_ACTION_INIT_CLASS_INTERNAL(className, parentClass) \
147 enabledElements = new SoEnabledElementsList(parentClass::enabledElements); \
148 methods = new ::SoActionMethodList(parentClass::methods); \
149 SO_ACTION_INIT_CLASS_CHECK_PARENT(className, parentClass); \
150 classTypeId = SoType::createType(parentClass::getClassTypeId(), \
151 SO__QUOTE(className), NULL); \
152 classTypeIdIsSet = TRUE;
153
154#define SO_ACTION_INIT_CLASS(className, parentClass) \
155 SO_ACTION_INIT_CLASS_INTERNAL(className, parentClass)
156
157#if defined(_DEBUG)
158#define SO_ACTION_EXIT_CLASS(className) \
159 if (! SoType::removeType(classTypeId.getName())) { \
160 SoDebugError::post(SO__QUOTE(className)"::exitClass", \
161 "Unable to remove type (%s) for this class. Check exitClass() " \
162 "method is implemented and is called only once.\n", \
163 classTypeId.getName().getString() ); \
164 } \
165 else { \
166 classTypeId = SoType::badType(); \
167 if (enabledElements) \
168 { \
169 delete enabledElements; \
170 enabledElements = NULL; \
171 } \
172 if (methods) \
173 { \
174 delete methods; \
175 methods = NULL; \
176 } \
177 classTypeIdIsSet = FALSE; \
178 }
179#else
180#define SO_ACTION_EXIT_CLASS(className) \
181 SoType::removeType(classTypeId.getName()); \
182 classTypeId = SoType::badType(); \
183 if (enabledElements) \
184 { \
185 delete enabledElements; \
186 enabledElements = NULL; \
187 } \
188 if (methods) \
189 { \
190 delete methods; \
191 methods = NULL; \
192 } \
193 classTypeIdIsSet = FALSE
194#endif
195
196#if defined(_DEBUG)
197#define SO__ACTION_CHECK_INIT(className) { \
198 if (classTypeId.isBad()) { \
199 SoDebugError::post("SO_ACTION_CONSTRUCTOR", \
200 "Can't construct an action of type " \
201 SO__QUOTE(className) \
202 " until initClass() has been called." \
203 " Check SoDB::init() has been called."); \
204 className::initClass(); \
205 } \
206 SoTypedObject::checkDatabase(SO__QUOTE(className), this, className::getClassTypeId(), classTypeId); \
207}
208#else
209#define SO__ACTION_CHECK_INIT(className) { \
210 if (classTypeId.isBad()) { \
211 className::initClass(); \
212 } \
213}
214#endif
215
217//
218// This is included at the beginning of
219// a constructor, to do required initializations
220//
221
222#define SO_ACTION_CONSTRUCTOR(className) \
223 SO__ACTION_CHECK_INIT(className);
224
226//
227// This macro can be used by action subclasses within initClass() to
228// register a method to call for a specific node class. It is passed
229// the name of the node class and the method to call.
230//
231
232#define SO_ACTION_ADD_METHOD(nodeClass, method) \
233 addMethod(nodeClass::getClassTypeId(), method)
234
236//
237// This implements the methods defined in SO_ACTION_HEADER.
238//
239
240#define SO__ACTION_ELEMENTS_METHODS(className) \
241const SoEnabledElementsList & \
242className::getEnabledElements() const \
243{ \
244 return *enabledElements; \
245} \
246\
247SoActionMethodList * \
248className::getActionMethods() \
249{ \
250 return methods; \
251} \
252\
253void \
254className::addMethod(SoType t, SoActionMethod* method) \
255{ \
256 methods->addMethod(t, method); \
257} \
258\
259void \
260className::enableElement(SoType t, int stkIndex) \
261{ \
262 if ( t.isBad()) \
263 { \
264 SoDebugError::post("SO_ENABLE_ELEMENT", \
265 "Can't enable element for " \
266 SO__QUOTE(className) \
267 " until the element initClass function has been called"); \
268 return; \
269 } \
270 enabledElements->enable(t, stkIndex); \
271}
272
273#define SO__ACTION_METHODS(className) \
274SoType \
275className::getClassTypeId() \
276{ \
277 return classTypeId; \
278} \
279 \
280SoType \
281className::getTypeId() const \
282{ \
283 return classTypeId; \
284} \
285\
286SO__ACTION_ELEMENTS_METHODS(className)
287
289//
290// This implements the methods defined in SO_ACTION_HEADER.
291// If class type id is not initialized, jus do it.
292//
293
294#define SO__ACTION_AUTOINIT_METHODS(className, parentClass) \
295SoType \
296className::getClassTypeId() \
297{ \
298 if (!classTypeIdIsSet) { \
299 SO_ACTION_INIT_CLASS(className, parentClass); \
300 } \
301 return classTypeId; \
302} \
303\
304SoType \
305className::getTypeId() const \
306{ \
307 if (classTypeIdIsSet == FALSE) { \
308 SO_ACTION_INIT_CLASS(className, parentClass); \
309 } \
310 return classTypeId; \
311} \
312\
313SO__ACTION_ELEMENTS_METHODS(className)
314
315#endif /* _SO_SUB_ACTION_ */
316
317
Stores runtime type information.
Definition SoType.h:98
int SbBool
Boolean type.
Definition SbBase.h:87