Open Inventor Reference
SoElement.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * Further, this software is distributed without any warranty that it is
16  * free of the rightful claim of any third person regarding infringement
17  * or the like. Any license provided herein, whether implied or
18  * otherwise, applies only to this software file. Patent licenses, if
19  * any, provided herein do not apply to combinations of this program with
20  * other software, or any other product whatsoever.
21  *
22  * You should have received a copy of the GNU Lesser General Public
23  * License along with this library; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25  *
26  * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
27  * Mountain View, CA 94043, or:
28  *
29  * http://www.sgi.com
30  *
31  * For further information regarding this notice, see:
32  *
33  * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
34  *
35  */
36 
37 
38 /*
39  * Copyright (C) 1990,91 Silicon Graphics, Inc.
40  *
41  _______________________________________________________________________
42  ______________ S I L I C O N G R A P H I C S I N C . ____________
43  |
44  | $Revision: 1.1.1.1 $
45  |
46  | Description:
47  | This file defines the abstract base SoEXTENDER SoElement class.
48  |
49  | Classes:
50  | SoElement
51  |
52  | Author(s) : Paul S. Strauss
53  |
54  ______________ S I L I C O N G R A P H I C S I N C . ____________
55  _______________________________________________________________________
56  */
57 
58 #ifndef _SO_ELEMENT
59 #define _SO_ELEMENT
60 
89 
90 #include <Inventor/SoType.h>
91 #include <Inventor/misc/SoState.h>
92 #include <Inventor/nodes/SoNode.h>
93 
94 class SoTypeList;
95 
97 
98  public:
101  virtual void init(SoState *state);
102 
105  virtual void push(SoState *state);
106  virtual void pop(SoState *state, const SoElement *prevTopElement);
107 
109  virtual void print(FILE *fp) const;
110 
114  virtual bool matches(const SoElement *elt) const = 0;
115 
118  virtual SoElement *copyMatchInfo() const = 0;
119 
121  static SoType getClassTypeId() { return classTypeId; }
122 
124  SoType getTypeId() const { return typeId; }
125 
126  SoINTERNAL public:
128  static void initElements();
129 
131  static void initClass();
132 
134  static int getNumStackIndices() { return nextStackIndex; }
135 
137  static SoType getIdFromStackIndex(int stackIndex);
138 
140  int getStackIndex() const { return stackIndex; }
141 
143  void setDepth(int dpth) { depth = dpth; }
144  void setNext(SoElement *nxt) { next = nxt; }
145  void setNextInStack(SoElement *nxt) { nextInStack = nxt; }
146  void setNextFree(SoElement *nxt) { nextFree = nxt; }
147 
149  int getDepth() const { return depth; }
150  SoElement * getNext() const { return next; }
151 
153  virtual ~SoElement();
154 
155  protected:
158 
162  static SoElement * getElement(SoState *state, int stackIndex)
163  { return state->getElement(stackIndex); }
164 
167  static inline const SoElement * getConstElement(SoState *state,
168  int stackIndex);
169 
173  void capture(SoState *state) const
174  { if (state->isCacheOpen()) captureThis(state); }
175 
178  virtual void captureThis(SoState *state) const;
179 
181  void setTypeId(SoType id) { typeId = id; }
182 
184  void setStackIndex(int index) { stackIndex = index; }
185 
187  SoElement * getNextInStack() const { return nextInStack; }
188 
190  SoElement * getNextFree() const { return nextFree; }
191 
192  SoINTERNAL protected:
193  static int classStackIndex;
194 
196  static int createStackIndex(SoType id);
197 
198  private:
200  static SoType classTypeId;
201  SoType typeId;
202 
204  static int nextStackIndex;
205  static SoTypeList *stackToType;
206  int stackIndex;
207 
209 
216 
217  SoElement *nextInStack;
218  SoElement *nextFree;
219 
220  SoElement *next;
222  int depth;
223 friend class SoState;
224 };
225 
233 
235  int stackIndex)
238 {
239  const SoElement * elt = (state->getConstElement(stackIndex));
240  elt->capture(state);
241  return elt;
242 }
243 
244 #endif /* _SO_ELEMENT */
#define SoEXTENDER
Provide inline template functions for abs, swap, min, max, and clamp.
Definition: SbBasic.h:154
#define SoINTERNAL
Definition: SbBasic.h:155
#define INVENTOR_API
Disable some annoying warnings on MSVC 6.
Definition: SbSystem.h:81
This is the abstract base class for all state elements.
Definition: SoElement.h:96
void setTypeId(SoType id)
Sets typeId in instance.
Definition: SoElement.h:181
virtual void print(FILE *fp) const
Prints element (for debugging)
static const SoElement * getConstElement(SoState *state, int stackIndex)
Returns a read-only pointer to the top instance in the given element stack.
Definition: SoElement.h:234
static void initElements()
Initialize ALL Inventor element classes.
void setNextFree(SoElement *nxt)
Definition: SoElement.h:146
void setNext(SoElement *nxt)
Definition: SoElement.h:144
virtual bool matches(const SoElement *elt) const =0
Returns TRUE if the element matches another element (of the same class, presumably) with respect to c...
static int classStackIndex
Stack index for SoElement class.
Definition: SoElement.h:193
virtual ~SoElement()
Destructor.
SoElement * getNextFree() const
Returns next free element in a specific element stack.
Definition: SoElement.h:190
static SoType getClassTypeId()
Returns type identifier for SoElement class.
Definition: SoElement.h:121
static void initClass()
Initializes the SoElement class.
void capture(SoState *state) const
Does whatever is necessary in state to capture this element for caching purposes.
Definition: SoElement.h:173
int getDepth() const
Returns stuff from element instance.
Definition: SoElement.h:149
SoElement * getNext() const
Definition: SoElement.h:150
int getStackIndex() const
Returns the stack index for an element instance.
Definition: SoElement.h:140
static int getNumStackIndices()
Returns the number of stack indices allocated.
Definition: SoElement.h:134
static int createStackIndex(SoType id)
Creates and returns a new stack index.
void setNextInStack(SoElement *nxt)
Definition: SoElement.h:145
virtual SoElement * copyMatchInfo() const =0
Create a copy that we can put in a cache used list and call matches() on later.
virtual void init(SoState *state)
Initializes element.
SoType getTypeId() const
Returns type identifier for element instance.
Definition: SoElement.h:124
virtual void pop(SoState *state, const SoElement *prevTopElement)
SoElement()
Constructor; use typeId.createInstance to create elements.
void setStackIndex(int index)
Sets stackIndex in instance.
Definition: SoElement.h:184
static SoType getIdFromStackIndex(int stackIndex)
Returns the id for the element with the given stack index.
virtual void push(SoState *state)
Pushes/pops element.
SoElement * getNextInStack() const
Returns next instance in specific element stack.
Definition: SoElement.h:187
void setDepth(int dpth)
Sets stuff in an element instance.
Definition: SoElement.h:143
virtual void captureThis(SoState *state) const
Really captures this element, once it has been determined that a cache is open to capture it.
static SoElement * getElement(SoState *state, int stackIndex)
Returns an instance of an element from the stack with the given index in the given state.
Definition: SoElement.h:162
An SoState collects and holds state while traversing a scene graph.
Definition: SoState.h:82
const SoElement * getConstElement(int stackIndex) const
Returns the top (read-only) instance of the given element stack.
Definition: SoState.h:100
SoElement * getElement(int stackIndex)
Returns a writable instance of the element on the top of the stack with the given index.
bool isCacheOpen() const
Definition: SoState.h:129
Maintains a list of SoTypes.
Definition: SoLists.h:295
SoType has no virtual functions to keep it small...
Definition: SoType.h:103