SoWin  1.6.2
Coin3D GUI toolkit binding
Loading...
Searching...
No Matches
SoWinObject.h
1#ifndef SOWINOBJECT_H
2#define SOWINOBJECT_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 <cassert>
39
40#include <Inventor/SbBasic.h>
41#include <Inventor/SbString.h>
42#include <Inventor/SoType.h>
43
44#include <Inventor/Win/SoWinBasic.h>
45
46// *************************************************************************
47
48class SOWIN_DLL_API SoWinObject {
49 static SoType classTypeId;
50
51public:
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 (SOWIN_MAJOR_VERSION > 1)
65#error Resolve missing virtual destructor issue for the new major release!
66#endif
67
68}; // SoWinObject
69
70// *************************************************************************
71
72// For a discussion about this #define, see Coin's SbBasic.h.
73
74#define SOWIN_SUN_CC_4_0_SOTYPE_INIT_BUG 0 /* assume compiler is ok for now */
75
76#if SOWIN_SUN_CC_4_0_SOTYPE_INIT_BUG
77#define SOWIN_STATIC_SOTYPE_INIT
78#else
79#define SOWIN_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 SOWIN_OBJECT_ABSTRACT_HEADER(classname, parentname) \
91public: \
92 static void initClass(void); \
93 static SoType getClassTypeId(void); \
94 virtual SoType getTypeId(void) const /* = 0 (see comment above) */; \
95private: \
96 typedef parentname inherited; \
97 static SoType classTypeId
98
99#define SOWIN_OBJECT_HEADER(classname, parentname) \
100public: \
101 static void initClass(void); \
102 static SoType getClassTypeId(void); \
103 virtual SoType getTypeId(void) const; \
104 static void * createInstance(void); \
105private: \
106 typedef parentname inherited; \
107 static SoType classTypeId
108
109#define SOWIN_OBJECT_ABSTRACT_SOURCE(classname) \
110void classname::initClass(void) { \
111 assert(classname::classTypeId == SoType::badType()); \
112 classname::classTypeId = \
113 SoType::createType(inherited::getClassTypeId(), \
114 SO__QUOTE(classname)); \
115} \
116SoType classname::getClassTypeId(void) { \
117 return classname::classTypeId; \
118} \
119SoType classname::getTypeId(void) const { \
120 return classname::classTypeId; \
121} \
122SoType classname::classTypeId SOWIN_STATIC_SOTYPE_INIT
123
124#define SOWIN_OBJECT_SOURCE(classname) \
125void 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} \
132SoType classname::getClassTypeId(void) { \
133 return classname::classTypeId; \
134} \
135SoType classname::getTypeId(void) const { \
136 return classname::classTypeId; \
137} \
138void * classname::createInstance(void) { \
139 assert(classname::classTypeId != SoType::badType()); \
140 return (void *) new classname; \
141} \
142SoType classname::classTypeId SOWIN_STATIC_SOTYPE_INIT
143
144// *************************************************************************
145
146#endif // ! SOWINOBJECT_H
The SoWinObject class is the common superclass for all SoWin component classes.
Definition SoWinObject.h:48
virtual SoType getTypeId(void) const =0