Coin Logo Coin3D is Free Software,
published under the BSD 3-clause license.
https://bitbucket.org/Coin3D/
http://www.kongsberg.com/kogt/
SoElement.h
1 #ifndef COIN_SOELEMENT_H
2 #define COIN_SOELEMENT_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/SbBasic.h>
37 #include <Inventor/SoType.h>
38 #include <Inventor/misc/SoState.h>
39 #include <cstdio>
40 
41 class SoNode;
42 
43 class COIN_DLL_API SoElement {
44 public:
45  static void initClass(void);
46 
47  static SoType getClassTypeId(void);
48  static int getClassStackIndex(void);
49  const SoType getTypeId(void) const;
50  int getStackIndex(void) const;
51 
52  virtual void init(SoState * state);
53 
54  virtual void push(SoState * state);
55  virtual void pop(SoState * state, const SoElement * prevTopElement);
56 
57  virtual SbBool matches(const SoElement * element) const = 0;
58  virtual SoElement * copyMatchInfo(void) const = 0;
59 
60  static void initElements(void); // only for base class (SoElement)
61 
62  static int getNumStackIndices(void);
63  static SoType getIdFromStackIndex(const int stackIndex);
64 
65  void setDepth(const int depth);
66 
67  int getDepth(void) const;
68 
69  virtual void print(FILE * file = stdout) const;
70  virtual ~SoElement();
71 
72 protected:
73  SoElement(void);
74  static int classStackIndex;
75 
76  static SoElement * getElement(SoState * const state, const int stackIndex);
77  static const SoElement * getConstElement(SoState * const state, const int stackIndex);
78 
79  void capture(SoState * const state) const;
80 
81  virtual void captureThis(SoState * state) const;
82 
83  void setTypeId(const SoType typeId);
84  void setStackIndex(const int index);
85 
88 
89  static int createStackIndex(const SoType id);
91 
92  int depth;
93 
94  SoElement * getNextInStack(void) const;
95  SoElement * getNextFree(void) const;
96 
97 private:
98 
99  static SoType classTypeId;
100 
101  friend class SoState; // FIXME: bad design. 19990629 mortene.
102  static void cleanup(void);
103  SoElement * nextup;
104  SoElement * nextdown;
105 };
106 
107 // inlined methods
108 
109 inline SoElement *
111  const int stackIndex)
112 {
113  return state->getElement(stackIndex);
114 }
115 
116 inline void
117 SoElement::capture(SoState * const state) const
118 {
119  if (state->isCacheOpen()) this->captureThis(state);
120 }
121 
122 inline const SoElement *
124  const int stackIndex)
125 {
126  const SoElement * element = state->getConstElement(stackIndex);
127  element->capture(state);
128  return element;
129 }
130 
131 #endif // !COIN_SOELEMENT_H
static const SoElement * getConstElement(SoState *const state, const int stackIndex)
Definition: SoElement.h:123
static SoElement * getElement(SoState *const state, const int stackIndex)
Definition: SoElement.h:110
The SoNode class is the base class for nodes used in scene graphs.
Definition: SoNode.h:56
SoElement is the abstract base class for all elements.
Definition: SoElement.h:43
SoType typeId
Definition: SoElement.h:86
The SoState class manages the Coin scenegraph traversal state data.
Definition: SoState.h:44
The SoTypeList class is a container class for arrays of SoType objects.
Definition: SoTypeList.h:39
int stackIndex
Definition: SoElement.h:87
virtual void captureThis(SoState *state) const
Definition: SoElement.cpp:687
SbBool isCacheOpen(void) const
Definition: SoState.h:92
void capture(SoState *const state) const
Definition: SoElement.h:117
SoElement * getElement(const int stackindex)
Definition: SoState.cpp:228
static SoTypeList * stackToType
Definition: SoElement.h:90
const SoElement * getConstElement(const int stackindex) const
Definition: SoState.h:85
int depth
Definition: SoElement.h:92
static int classStackIndex
Definition: SoElement.h:74
The SoType class is the basis for the run-time type system in Coin.
Definition: SoType.h:59