Coin  4.0.3
Coin3D core library
Loading...
Searching...
No Matches
SoSubAction.h
1#ifndef COIN_SOSUBACTION_H
2#define COIN_SOSUBACTION_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#ifndef COIN_INTERNAL
37// Added to be Inventor compliant.
38#include <Inventor/SbString.h>
39#include <Inventor/actions/SoAction.h>
40#endif // COIN_INTERNAL
41#include <Inventor/C/tidbits.h>
42
43// *************************************************************************
44
45#define SO_ACTION_ADD_METHOD(_nodeclass_, _method_) \
46 do { \
47 addMethod(_nodeclass_::getClassTypeId(), (SoActionMethod)_method_); \
48 } WHILE_0
49
50// *************************************************************************
51
52#define SO_ACTION_CONSTRUCTOR(_classname_) \
53 do { \
54 _classname_::traversalMethods = this->methods; \
55 } WHILE_0
56
57// *************************************************************************
58
59#define SO_ACTION_HEADER(_classname_) \
60public: \
61 virtual SoType getTypeId(void) const; \
62 static SoType getClassTypeId(void); \
63 \
64 static void addMethod(const SoType type, SoActionMethod method); \
65 \
66 static void enableElement(const SoType type, const int stackindex); \
67 \
68protected: \
69 virtual const SoEnabledElementsList & getEnabledElements(void) const; \
70 /* These two methods are not available in the original OIV API. */ \
71 /* They have been added as a work-around for Win32 DLL headaches. */ \
72 /* See further explanation below. 20000808 mortene. */ \
73 static SoEnabledElementsList * getClassEnabledElements(void); \
74 static SoActionMethodList * getClassActionMethods(void); \
75 \
76private: \
77 /* The enabledElements and methods variables are protected in */ \
78 /* the original OIV API. This is not such a good idea, since */ \
79 /* exposed static class member variables is a major grievance */ \
80 /* with regard to Win32 DLLs. */ \
81 static void atexit_cleanup(void); \
82 static SoEnabledElementsList * enabledElements; \
83 static SoActionMethodList * methods; \
84 static SoType classTypeId
85
86// *************************************************************************
87
88#define SO_ACTION_SOURCE(_classname_) \
89SoEnabledElementsList * _classname_::enabledElements = NULL; \
90SoActionMethodList * _classname_::methods = NULL; \
91
99 \
100SoEnabledElementsList * _classname_::getClassEnabledElements(void) { return _classname_::enabledElements; } \
101
109 \
110SoActionMethodList * _classname_::getClassActionMethods(void) { return _classname_::methods; } \
111SoType _classname_::classTypeId STATIC_SOTYPE_INIT; \
112 \
113
116 \
117SoType _classname_::getClassTypeId(void) { return _classname_::classTypeId; } \
118 \
119
123 \
124SoType _classname_::getTypeId(void) const { return _classname_::classTypeId; } \
125
127 \
128const SoEnabledElementsList & _classname_::getEnabledElements(void) const \
129{ \
130 assert(_classname_::enabledElements); \
131 return *_classname_::enabledElements; \
132} \
133void \
134_classname_::addMethod(const SoType type, SoActionMethod method) \
135{ \
136 assert(_classname_::methods); \
137 _classname_::methods->addMethod(type, method); \
138} \
139void \
140_classname_::enableElement(const SoType type, const int stackindex) \
141{ \
142 assert(_classname_::enabledElements); \
143 _classname_::enabledElements->enable(type, stackindex); \
144} \
145void \
146_classname_::atexit_cleanup(void) \
147{ \
148 delete _classname_::enabledElements; \
149 _classname_::enabledElements = NULL; \
150 delete _classname_::methods; \
151 _classname_::methods = NULL; \
152 _classname_::classTypeId STATIC_SOTYPE_INIT; \
153}
154
155// *************************************************************************
156
157#define SO_ACTION_INIT_CLASS(_classname_, _parentclassname_) \
158 do { \
159 assert(_classname_::getClassTypeId() == SoType::badType()); \
160 assert(_parentclassname_::getClassTypeId() != SoType::badType()); \
161 _classname_::classTypeId = SoType::createType(_parentclassname_::getClassTypeId(), SO__QUOTE(_classname_)); \
162 _classname_::enabledElements = new SoEnabledElementsList(_parentclassname_::getClassEnabledElements()); \
163 _classname_::methods = new SoActionMethodList(_parentclassname_::getClassActionMethods()); \
164 cc_coin_atexit_static_internal(reinterpret_cast<coin_atexit_f *>(_classname_::atexit_cleanup)); \
165 } WHILE_0
166
167// *************************************************************************
168
169#endif // !COIN_SOSUBACTION_H