Coin Logo http://www.coin3d.org/
http://www.kongsberg.com/kogt/

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_) \
60 public: \
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  \
68 protected: \
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  \
76 private: \
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_) \
89 SoEnabledElementsList * _classname_::enabledElements = NULL; \
90 SoActionMethodList * _classname_::methods = NULL; \
91 SoEnabledElementsList * _classname_::getClassEnabledElements(void) { return _classname_::enabledElements; } \
92 SoActionMethodList * _classname_::getClassActionMethods(void) { return _classname_::methods; } \
93 SoType _classname_::classTypeId STATIC_SOTYPE_INIT; \
94 SoType _classname_::getClassTypeId(void) { return _classname_::classTypeId; } \
95 SoType _classname_::getTypeId(void) const { return _classname_::classTypeId; } \
96 const SoEnabledElementsList & _classname_::getEnabledElements(void) const \
97 { \
98  assert(_classname_::enabledElements); \
99  return *_classname_::enabledElements; \
100 } \
101 void \
102 _classname_::addMethod(const SoType type, SoActionMethod method) \
103 { \
104  assert(_classname_::methods); \
105  _classname_::methods->addMethod(type, method); \
106 } \
107 void \
108 _classname_::enableElement(const SoType type, const int stackindex) \
109 { \
110  assert(_classname_::enabledElements); \
111  _classname_::enabledElements->enable(type, stackindex); \
112 } \
113 void \
114 _classname_::atexit_cleanup(void) \
115 { \
116  delete _classname_::enabledElements; \
117  _classname_::enabledElements = NULL; \
118  delete _classname_::methods; \
119  _classname_::methods = NULL; \
120  _classname_::classTypeId STATIC_SOTYPE_INIT; \
121 }
122 
123 // *************************************************************************
124 
125 #define SO_ACTION_INIT_CLASS(_classname_, _parentclassname_) \
126  do { \
127  assert(_classname_::getClassTypeId() == SoType::badType()); \
128  assert(_parentclassname_::getClassTypeId() != SoType::badType()); \
129  _classname_::classTypeId = SoType::createType(_parentclassname_::getClassTypeId(), SO__QUOTE(_classname_)); \
130  _classname_::enabledElements = new SoEnabledElementsList(_parentclassname_::getClassEnabledElements()); \
131  _classname_::methods = new SoActionMethodList(_parentclassname_::getClassActionMethods()); \
132  cc_coin_atexit_static_internal(reinterpret_cast<coin_atexit_f *>(_classname_::atexit_cleanup)); \
133  } while (0)
134 
135 // *************************************************************************
136 
137 #endif // !COIN_SOSUBACTION_H

Copyright © by Kongsberg Oil & Gas Technologies. All rights reserved.

Generated for Coin by Doxygen