Open Inventor Reference
SoSubElement.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 some macros that implement things common to
48  | many subclasses of SoElement. They may be used to make SoElement
49  | subclassing easier. In all of the macros, the "className"
50  | parameter refers to the name of the element subclass.
51  |
52  | Defined macros:
53  |
54  | Within class header:
55  |
56  | SO_ELEMENT_ABSTRACT_HEADER(className)
57  | SO_ELEMENT_HEADER(className)
58  |
59  | Within class source:
60  |
61  | At file scope:
62  |
63  | SO_ELEMENT_ABSTRACT_SOURCE(className)
64  | SO_ELEMENT_SOURCE(className)
65  |
66  | Class initialization (in initClass):
67  |
68  | SO_ELEMENT_INIT_ABSTRACT_CLASS()
69  | SO_ELEMENT_INIT_CLASS()
70  |
71  |
72  | Author(s) : Paul S. Strauss
73  |
74  ______________ S I L I C O N G R A P H I C S I N C . ____________
75  _______________________________________________________________________
76  */
77 
78 #ifndef _SO_SUB_ELEMENT_
79 #define _SO_SUB_ELEMENT_
80 
82 
83 
89 
95 
99 #define SO_ELEMENT_ABSTRACT_HEADER(className) \
100  public: \
101  static SoType getClassTypeId() { return classTypeId; } \
102  static int getClassStackIndex() { return classStackIndex; } \
103  protected: \
104  static int classStackIndex; \
105  className(); \
106  private: \
107  static SoType classTypeId
108 
112 #define SO_ELEMENT_HEADER(className) \
113  SO_ELEMENT_ABSTRACT_HEADER(className); \
114  private: \
115  static void *createInstance()
116 
121 
127 
128 #define SO__ELEMENT_ABSTRACT_VARS(className) \
129 SoType className::classTypeId; \
130 int className::classStackIndex
131 
132 #define SO__ELEMENT_VARS(className) \
133 SO__ELEMENT_ABSTRACT_VARS(className)
134 
138 #define SO__ELEMENT_ABSTRACT_METHODS(className) \
139  \
140 className::className() \
141 { \
142 }
143 
147 #define SO__ELEMENT_METHODS(className) \
148  \
149 className::className() \
150 { \
151  setTypeId(classTypeId); \
152  setStackIndex(classStackIndex); \
153 } \
154  \
155 void * \
156 className::createInstance() \
157 { \
158  return new className; \
159 }
160 
166 
167 #define SO_ELEMENT_ABSTRACT_SOURCE(className) \
168  SO__ELEMENT_ABSTRACT_VARS(className); \
169  SO__ELEMENT_ABSTRACT_METHODS(className)
170 
171 #define SO_ELEMENT_SOURCE(className) \
172  SO__ELEMENT_VARS(className); \
173  SO__ELEMENT_METHODS(className)
174 
182 
183 #define SO_ELEMENT_INIT_ABSTRACT_CLASS(className,parentClass) { \
184  int _value_false= 0; \
185  do { \
186  classTypeId = SoType::createType(parentClass::getClassTypeId(), \
187  SO__QUOTE(className), \
188  NULL); \
189  if (parentClass::classStackIndex < 0) \
190  classStackIndex = createStackIndex(classTypeId); \
191  else \
192  classStackIndex = parentClass::classStackIndex; \
193  } while (_value_false); \
194  }
195 
196 #define SO_ELEMENT_INIT_CLASS(className,parentClass) { \
197  int _value_false= 0; \
198  do { \
199  classTypeId = SoType::createType(parentClass::getClassTypeId(), \
200  SO__QUOTE(className), \
201  &className::createInstance); \
202  if (parentClass::classStackIndex < 0) \
203  classStackIndex = createStackIndex(classTypeId); \
204  else \
205  classStackIndex = parentClass::classStackIndex; \
206  } while (_value_false); \
207  }
208 
209 
210 #endif /* _SO_SUB_ELEMENT_ */