Coin Logo Coin3D is Free Software,
published under the BSD 3-clause license.
https://coin3d.github.io
https://www.kongsberg.com/en/kogt/
SoQtObject.h
1 #ifndef SOQTOBJECT_H
2 #define SOQTOBJECT_H
3 
4 //
5 
6 /**************************************************************************\
7  * Copyright (c) Kongsberg Oil & Gas Technologies AS
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions are
12  * met:
13  *
14  * Redistributions of source code must retain the above copyright notice,
15  * this list of conditions and the following disclaimer.
16  *
17  * Redistributions in binary form must reproduce the above copyright
18  * notice, this list of conditions and the following disclaimer in the
19  * documentation and/or other materials provided with the distribution.
20  *
21  * Neither the name of the copyright holder nor the names of its
22  * contributors may be used to endorse or promote products derived from
23  * this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 \**************************************************************************/
37 
38 #include <assert.h>
39 
40 #include <Inventor/SbBasic.h>
41 #include <Inventor/SbString.h>
42 #include <Inventor/SoType.h>
43 
44 #include <Inventor/Qt/SoQtBasic.h>
45 
46 // *************************************************************************
47 
48 class SOQT_DLL_API SoQtObject {
49  static SoType classTypeId;
50 
51 public:
52  static void initClass(void);
53  static SoType getClassTypeId(void);
54  virtual SoType getTypeId(void) const = 0;
55  SbBool isOfType(SoType type) const;
56 
57  static void init(void);
58 
59  // FIXME: gcc-4 generates a warning when a class has virtual functions
60  // but no virtual destructor. Currently this warning is suppressed using
61  // the -Wno-non-virtual-dtor option, but this should be addressed for the
62  // next major version... 20060404 kyrah
63 
64 #if (SOQT_MAJOR_VERSION > 1)
65 #error Resolve missing virtual destructor issue for the new major release!
66 #endif
67 
68 }; // SoQtObject
69 
70 // *************************************************************************
71 
72 // For a discussion about this #define, see Coin's SbBasic.h.
73 
74 #define SOQT_SUN_CC_4_0_SOTYPE_INIT_BUG 0 /* assume compiler is ok for now */
75 
76 #if SOQT_SUN_CC_4_0_SOTYPE_INIT_BUG
77 #define SOQT_STATIC_SOTYPE_INIT
78 #else
79 #define SOQT_STATIC_SOTYPE_INIT = SoType::badType()
80 #endif
81 
82 // *************************************************************************
83 
84 // The getTypeId() method should be abstract for abstract objects, but doing
85 // that would cause custom components derived from abstract components to
86 // have to include the typed object header / source, which could be a
87 // problem if the custom component wasn't written for Coin in the first
88 // place.
89 
90 #define SOQT_OBJECT_ABSTRACT_HEADER(classname, parentname) \
91 public: \
92  static void initClass(void); \
93  static SoType getClassTypeId(void); \
94  virtual SoType getTypeId(void) const /* = 0 (see comment above) */; \
95 private: \
96  typedef parentname inherited; \
97  static SoType classTypeId
98 
99 #define SOQT_OBJECT_HEADER(classname, parentname) \
100 public: \
101  static void initClass(void); \
102  static SoType getClassTypeId(void); \
103  virtual SoType getTypeId(void) const; \
104  static void * createInstance(void); \
105 private: \
106  typedef parentname inherited; \
107  static SoType classTypeId
108 
109 #define SOQT_OBJECT_ABSTRACT_SOURCE(classname) \
110 void classname::initClass(void) { \
111  assert(classname::classTypeId == SoType::badType()); \
112  classname::classTypeId = \
113  SoType::createType(inherited::getClassTypeId(), \
114  SO__QUOTE(classname)); \
115 } \
116 SoType classname::getClassTypeId(void) { \
117  return classname::classTypeId; \
118 } \
119 SoType classname::getTypeId(void) const { \
120  return classname::classTypeId; \
121 } \
122 SoType classname::classTypeId SOQT_STATIC_SOTYPE_INIT
123 
124 #define SOQT_OBJECT_SOURCE(classname) \
125 void classname::initClass(void) { \
126  assert(classname::classTypeId == SoType::badType()); \
127  classname::classTypeId = \
128  SoType::createType(inherited::getClassTypeId(), \
129  SO__QUOTE(classname), \
130  classname::createInstance); \
131 } \
132 SoType classname::getClassTypeId(void) { \
133  return classname::classTypeId; \
134 } \
135 SoType classname::getTypeId(void) const { \
136  return classname::classTypeId; \
137 } \
138 void * classname::createInstance(void) { \
139  assert(classname::classTypeId != SoType::badType()); \
140  return (void *) new classname; \
141 } \
142 SoType classname::classTypeId SOQT_STATIC_SOTYPE_INIT
143 
144 // *************************************************************************
145 
146 #endif // ! SOQTOBJECT_H
The SoQtObject class is the common superclass for all SoQt component classes.
Definition: SoQtObject.h:48
static SoType getClassTypeId(void)