Coin Logo http://www.sim.no/
http://www.coin3d.org/

SoSubAction.h
1 #ifndef COIN_SOSUBACTION_H
2 #define COIN_SOSUBACTION_H
3 
4 /**************************************************************************\
5  *
6  * This file is part of the Coin 3D visualization library.
7  * Copyright (C) by Kongsberg Oil & Gas Technologies.
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * ("GPL") version 2 as published by the Free Software Foundation.
12  * See the file LICENSE.GPL at the root directory of this source
13  * distribution for additional information about the GNU GPL.
14  *
15  * For using Coin with software that can not be combined with the GNU
16  * GPL, and for taking advantage of the additional benefits of our
17  * support services, please contact Kongsberg Oil & Gas Technologies
18  * about acquiring a Coin Professional Edition License.
19  *
20  * See http://www.coin3d.org/ for more information.
21  *
22  * Kongsberg Oil & Gas Technologies, Bygdoy Alle 5, 0257 Oslo, NORWAY.
23  * http://www.sim.no/ sales@sim.no coin-support@coin3d.org
24  *
25 \**************************************************************************/
26 
27 #ifndef COIN_INTERNAL
28 // Added to be Inventor compliant.
29 #include <Inventor/SbString.h>
30 #include <Inventor/actions/SoAction.h>
31 #endif // COIN_INTERNAL
32 #include <Inventor/C/tidbits.h>
33 
34 // *************************************************************************
35 
36 #define SO_ACTION_ADD_METHOD(_nodeclass_, _method_) \
37  do { \
38  addMethod(_nodeclass_::getClassTypeId(), (SoActionMethod)_method_); \
39  } while (0)
40 
41 // *************************************************************************
42 
43 #define SO_ACTION_CONSTRUCTOR(_classname_) \
44  do { \
45  _classname_::traversalMethods = this->methods; \
46  } while (0)
47 
48 // *************************************************************************
49 
50 #define SO_ACTION_HEADER(_classname_) \
51 public: \
52  virtual SoType getTypeId(void) const; \
53  static SoType getClassTypeId(void); \
54  \
55  static void addMethod(const SoType type, SoActionMethod method); \
56  \
57  static void enableElement(const SoType type, const int stackindex); \
58  \
59 protected: \
60  virtual const SoEnabledElementsList & getEnabledElements(void) const; \
61  /* These two methods are not available in the original OIV API. */ \
62  /* They have been added as a work-around for Win32 DLL headaches. */ \
63  /* See further explanation below. 20000808 mortene. */ \
64  static SoEnabledElementsList * getClassEnabledElements(void); \
65  static SoActionMethodList * getClassActionMethods(void); \
66  \
67 private: \
68  /* The enabledElements and methods variables are protected in */ \
69  /* the original OIV API. This is not such a good idea, since */ \
70  /* exposed static class member variables is a major grievance */ \
71  /* with regard to Win32 DLLs. */ \
72  static void atexit_cleanup(void); \
73  static SoEnabledElementsList * enabledElements; \
74  static SoActionMethodList * methods; \
75  static SoType classTypeId
76 
77 // *************************************************************************
78 
79 #define SO_ACTION_SOURCE(_classname_) \
80 SoEnabledElementsList * _classname_::enabledElements = NULL; \
81 SoActionMethodList * _classname_::methods = NULL; \
82 SoEnabledElementsList * _classname_::getClassEnabledElements(void) { return _classname_::enabledElements; } \
83 SoActionMethodList * _classname_::getClassActionMethods(void) { return _classname_::methods; } \
84 SoType _classname_::classTypeId STATIC_SOTYPE_INIT; \
85 SoType _classname_::getClassTypeId(void) { return _classname_::classTypeId; } \
86 SoType _classname_::getTypeId(void) const { return _classname_::classTypeId; } \
87 const SoEnabledElementsList & _classname_::getEnabledElements(void) const \
88 { \
89  assert(_classname_::enabledElements); \
90  return *_classname_::enabledElements; \
91 } \
92 void \
93 _classname_::addMethod(const SoType type, SoActionMethod method) \
94 { \
95  assert(_classname_::methods); \
96  _classname_::methods->addMethod(type, method); \
97 } \
98 void \
99 _classname_::enableElement(const SoType type, const int stackindex) \
100 { \
101  assert(_classname_::enabledElements); \
102  _classname_::enabledElements->enable(type, stackindex); \
103 } \
104 void \
105 _classname_::atexit_cleanup(void) \
106 { \
107  delete _classname_::enabledElements; \
108  _classname_::enabledElements = NULL; \
109  delete _classname_::methods; \
110  _classname_::methods = NULL; \
111  _classname_::classTypeId STATIC_SOTYPE_INIT; \
112 }
113 
114 // *************************************************************************
115 
116 #define SO_ACTION_INIT_CLASS(_classname_, _parentclassname_) \
117  do { \
118  assert(_classname_::getClassTypeId() == SoType::badType()); \
119  assert(_parentclassname_::getClassTypeId() != SoType::badType()); \
120  _classname_::classTypeId = SoType::createType(_parentclassname_::getClassTypeId(), SO__QUOTE(_classname_)); \
121  _classname_::enabledElements = new SoEnabledElementsList(_parentclassname_::getClassEnabledElements()); \
122  _classname_::methods = new SoActionMethodList(_parentclassname_::getClassActionMethods()); \
123  cc_coin_atexit_static_internal(reinterpret_cast<coin_atexit_f *>(_classname_::atexit_cleanup)); \
124  } while (0)
125 
126 // *************************************************************************
127 
128 #endif // !COIN_SOSUBACTION_H

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

Generated on Wed Feb 7 2018 for Coin by Doxygen 1.8.14.