Coin: SoElement.h Source File

| Coin3D is Free Software, published under the BSD 3-clause license. | https://coin3d.github.io https://www.kongsberg.com/en/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
41class SoNode;
42
43 class COIN_DLL_API SoElement {
44public:
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
72protected:
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
86 SoType typeId;
87 int stackIndex;
88
89 static int createStackIndex(const SoType id);
90 static SoTypeList * stackToType;
91
92 int depth;
93
94 SoElement * getNextInStack(void) const;
95 SoElement * getNextFree(void) const;
96
97private:
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
109inline SoElement *
110SoElement::getElement(SoState * const state,
111 const int stackIndex)
112{
113 return state->getElement(stackIndex);
114}
115
116inline void
117SoElement::capture(SoState * const state) const
118{
119 if (state->isCacheOpen()) this->captureThis(state);
120}
121
122inline const SoElement *
123SoElement::getConstElement(SoState * const state,
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
SoElement
SoElement is the abstract base class for all elements.
Definition SoElement.h:43
SoElement::capture
void capture(SoState *const state) const
Definition SoElement.h:117
SoElement::getElement
static SoElement * getElement(SoState *const state, const int stackIndex)
Definition SoElement.h:110
SoElement::classStackIndex
static int classStackIndex
Definition SoElement.h:74
SoElement::typeId
SoType typeId
Definition SoElement.h:86
SoElement::stackIndex
int stackIndex
Definition SoElement.h:87
SoElement::getConstElement
static const SoElement * getConstElement(SoState *const state, const int stackIndex)
Definition SoElement.h:123
SoElement::copyMatchInfo
virtual SoElement * copyMatchInfo(void) const =0
SoElement::depth
int depth
Definition SoElement.h:92
SoElement::stackToType
static SoTypeList * stackToType
Definition SoElement.h:90
SoElement::captureThis
virtual void captureThis(SoState *state) const
Definition SoElement.cpp:688
SoNode
The SoNode class is the base class for nodes used in scene graphs.
Definition SoNode.h:56
SoState
The SoState class manages the Coin scene graph traversal state data.
Definition SoState.h:44
SoState::isCacheOpen
SbBool isCacheOpen(void) const
Definition SoState.h:92
SoState::getConstElement
const SoElement * getConstElement(const int stackindex) const
Definition SoState.h:85
SoState::getElement
SoElement * getElement(const int stackindex)
Definition SoState.cpp:228
SoTypeList
The SoTypeList class is a container class for arrays of SoType objects.
Definition SoTypeList.h:39
SoType
The SoType class is the basis for the runtime type system in Coin.
Definition SoType.h:59