00001 #ifndef COIN_SOELEMENT_H
00002 #define COIN_SOELEMENT_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <Inventor/SbBasic.h>
00028 #include <Inventor/SoType.h>
00029 #include <Inventor/misc/SoState.h>
00030 #include <stdio.h>
00031
00032 class SoNode;
00033
00034 class COIN_DLL_API SoElement {
00035 public:
00036 static void initClass(void);
00037
00038 static SoType getClassTypeId(void);
00039 static int getClassStackIndex(void);
00040 const SoType getTypeId(void) const;
00041 int getStackIndex(void) const;
00042
00043 virtual void init(SoState * state);
00044
00045 virtual void push(SoState * state);
00046 virtual void pop(SoState * state, const SoElement * prevTopElement);
00047
00048 virtual SbBool matches(const SoElement * element) const = 0;
00049 virtual SoElement * copyMatchInfo(void) const = 0;
00050
00051 static void initElements(void);
00052
00053 static int getNumStackIndices(void);
00054 static SoType getIdFromStackIndex(const int stackIndex);
00055
00056 void setDepth(const int depth);
00057
00058 int getDepth(void) const;
00059
00060 virtual void print(FILE * file = stdout) const;
00061 virtual ~SoElement();
00062
00063 protected:
00064 SoElement(void);
00065 static int classStackIndex;
00066
00067 static SoElement * getElement(SoState * const state, const int stackIndex);
00068 static const SoElement * getConstElement(SoState * const state, const int stackIndex);
00069
00070 void capture(SoState * const state) const;
00071
00072 virtual void captureThis(SoState * state) const;
00073
00074 void setTypeId(const SoType typeId);
00075 void setStackIndex(const int index);
00076
00077 SoType typeId;
00078 int stackIndex;
00079
00080 static int createStackIndex(const SoType id);
00081 static SoTypeList * stackToType;
00082
00083 int depth;
00084
00085 SoElement * getNextInStack(void) const;
00086 SoElement * getNextFree(void) const;
00087
00088 private:
00089
00090 static SoType classTypeId;
00091
00092 friend class SoState;
00093 static void cleanup(void);
00094 SoElement * nextup;
00095 SoElement * nextdown;
00096 };
00097
00098
00099
00100 inline SoElement *
00101 SoElement::getElement(SoState * const state,
00102 const int stackIndex)
00103 {
00104 return state->getElement(stackIndex);
00105 }
00106
00107 inline void
00108 SoElement::capture(SoState * const state) const
00109 {
00110 if (state->isCacheOpen()) this->captureThis(state);
00111 }
00112
00113 inline const SoElement *
00114 SoElement::getConstElement(SoState * const state,
00115 const int stackIndex)
00116 {
00117 const SoElement * element = state->getConstElement(stackIndex);
00118 element->capture(state);
00119 return element;
00120 }
00121
00122 #endif // !COIN_SOELEMENT_H