Coin Logo http://www.sim.no
http://www.coin3d.org

SoQtObject.h

00001 /**************************************************************************\
00002  *
00003  *  This file is part of the Coin 3D visualization library.
00004  *  Copyright (C) 1998-2005 by Systems in Motion.  All rights reserved.
00005  *
00006  *  This library is free software; you can redistribute it and/or
00007  *  modify it under the terms of the GNU General Public License
00008  *  ("GPL") version 2 as published by the Free Software Foundation.
00009  *  See the file LICENSE.GPL at the root directory of this source
00010  *  distribution for additional information about the GNU GPL.
00011  *
00012  *  For using Coin with software that can not be combined with the GNU
00013  *  GPL, and for taking advantage of the additional benefits of our
00014  *  support services, please contact Systems in Motion about acquiring
00015  *  a Coin Professional Edition License.
00016  *
00017  *  See <URL:http://www.coin3d.org/> for more information.
00018  *
00019  *  Systems in Motion, Postboks 1283, Pirsenteret, 7462 Trondheim, NORWAY.
00020  *  <URL:http://www.sim.no/>.
00021  *
00022 \**************************************************************************/
00023 
00024 #ifndef SOQTOBJECT_H
00025 #define SOQTOBJECT_H
00026 
00027 #include <assert.h>
00028 
00029 #include <Inventor/SbBasic.h>
00030 #include <Inventor/SbString.h>
00031 #include <Inventor/SoType.h>
00032 
00033 #include <Inventor/Qt/SoQtBasic.h>
00034 
00035 // *************************************************************************
00036 
00037 class SOQT_DLL_API SoQtObject {
00038   static SoType classTypeId;
00039 
00040 public:
00041   static void initClass(void);
00042   static SoType getClassTypeId(void);
00043   virtual SoType getTypeId(void) const = 0;
00044   SbBool isOfType(SoType type) const;
00045 
00046   static void init(void);
00047 
00048   // FIXME: gcc-4 generates a warning when a class has virtual functions 
00049   // but no virtual destructor. Currently this warning is suppressed using 
00050   // the -Wno-non-virtual-dtor option, but this should be addressed for the
00051   // next major version... 20060404 kyrah
00052 
00053 #if (SOQT_MAJOR_VERSION > 1)
00054 #error Resolve missing virtual destructor issue for the new major release!
00055 #endif
00056 
00057 }; // SoQtObject
00058 
00059 // *************************************************************************
00060 
00061 // For a discussion about this #define, see Coin's SbBasic.h.
00062 
00063 #define SOQT_SUN_CC_4_0_SOTYPE_INIT_BUG 0 /* assume compiler is ok for now */
00064 
00065 #if SOQT_SUN_CC_4_0_SOTYPE_INIT_BUG
00066 #define SOQT_STATIC_SOTYPE_INIT
00067 #else
00068 #define SOQT_STATIC_SOTYPE_INIT = SoType::badType()
00069 #endif
00070 
00071 // *************************************************************************
00072 
00073 // The getTypeId() method should be abstract for abstract objects, but doing
00074 // that would cause custom components derived from abstract components to
00075 // have to include the typed object header / source, which could be a
00076 // problem if the custom component wasn't written for Coin in the first
00077 // place.
00078 
00079 #define SOQT_OBJECT_ABSTRACT_HEADER(classname, parentname) \
00080 public: \
00081   static void initClass(void); \
00082   static SoType getClassTypeId(void); \
00083   virtual SoType getTypeId(void) const /* = 0 (see comment above) */; \
00084 private: \
00085   typedef parentname inherited; \
00086   static SoType classTypeId
00087 
00088 #define SOQT_OBJECT_HEADER(classname, parentname) \
00089 public: \
00090   static void initClass(void); \
00091   static SoType getClassTypeId(void); \
00092   virtual SoType getTypeId(void) const; \
00093   static void * createInstance(void); \
00094 private: \
00095   typedef parentname inherited; \
00096   static SoType classTypeId
00097 
00098 #define SOQT_OBJECT_ABSTRACT_SOURCE(classname) \
00099 void classname::initClass(void) { \
00100   assert(classname::classTypeId == SoType::badType()); \
00101   classname::classTypeId = \
00102     SoType::createType(inherited::getClassTypeId(), \
00103                         SO__QUOTE(classname)); \
00104 } \
00105 SoType classname::getClassTypeId(void) { \
00106   return classname::classTypeId; \
00107 } \
00108 SoType classname::getTypeId(void) const { \
00109   return classname::classTypeId; \
00110 } \
00111 SoType classname::classTypeId SOQT_STATIC_SOTYPE_INIT
00112 
00113 #define SOQT_OBJECT_SOURCE(classname) \
00114 void classname::initClass(void) { \
00115   assert(classname::classTypeId == SoType::badType()); \
00116   classname::classTypeId = \
00117     SoType::createType(inherited::getClassTypeId(), \
00118                         SO__QUOTE(classname), \
00119                         classname::createInstance); \
00120 } \
00121 SoType classname::getClassTypeId(void) { \
00122   return classname::classTypeId; \
00123 } \
00124 SoType classname::getTypeId(void) const { \
00125   return classname::classTypeId; \
00126 } \
00127 void * classname::createInstance(void) { \
00128   assert(classname::classTypeId != SoType::badType()); \
00129   return (void *) new classname; \
00130 } \
00131 SoType classname::classTypeId SOQT_STATIC_SOTYPE_INIT
00132 
00133 // *************************************************************************
00134 
00135 #endif // ! SOQTOBJECT_H

Copyright © 1998-2005 by Systems in Motion AS. All rights reserved.

Generated on Wed May 9 11:46:57 2007 for SoQt by Doxygen. 1.5.1