From 0824e8031c5ad6b86c1ce9968ac12557672a06d9 Mon Sep 17 00:00:00 2001 From: David Rose Date: Sat, 12 May 2001 15:57:34 +0000 Subject: [PATCH] *** empty log message *** --- panda/src/audio/audio_sound.h | 2 +- panda/src/char/dynamicVertices.h | 2 +- panda/src/display/textureContext.h | 2 +- panda/src/doc/sampleClass.h | 2 +- panda/src/egg/eggAttributes.h | 2 +- panda/src/egg/eggGroupNode.h | 2 +- panda/src/egg/eggNode.h | 2 +- panda/src/egg/eggRenderMode.h | 2 +- panda/src/egg2sg/test_loader.cxx | 2 +- panda/src/event/eventParameter.h | 2 +- panda/src/event/eventReceiver.h | 2 +- panda/src/express/Sources.pp | 5 +- panda/src/express/config_express.cxx | 2 +- panda/src/express/datagram.h | 2 +- panda/src/express/memoryUsage.h | 2 +- panda/src/express/memoryUsagePointers.h | 2 +- panda/src/express/namable.h | 2 +- panda/src/express/pointerTo.h | 2 +- panda/src/express/referenceCount.h | 4 +- panda/src/express/typeHandle.I | 54 -------- panda/src/express/typeHandle.cxx | 28 +---- panda/src/express/typeHandle.h | 103 --------------- panda/src/express/typedObject.I | 71 +++++++++++ panda/src/express/typedObject.cxx | 35 ++++++ panda/src/express/typedObject.h | 119 ++++++++++++++++++ panda/src/express/typedReferenceCount.h | 2 +- panda/src/glgsg/glGraphicsStateGuardian.cxx | 4 +- panda/src/glxdisplay/glxDisplay.h | 2 +- panda/src/graph/arcChain.h | 2 +- panda/src/graph/boundedObject.h | 2 +- panda/src/graph/dftraverser.h | 2 +- panda/src/graph/graphReducer.h | 2 +- panda/src/graph/wrt.h | 2 +- panda/src/light/light.h | 2 +- panda/src/linmath/lmatrix3.h | 2 +- panda/src/linmath/lmatrix4.h | 2 +- panda/src/linmath/lvecBase2.h | 2 +- panda/src/linmath/lvecBase3.h | 2 +- panda/src/linmath/lvecBase4.h | 2 +- panda/src/loader/loaderFileType.h | 2 +- panda/src/mathutil/boundingVolume.h | 2 +- panda/src/parametrics/parametricCurveDrawer.h | 2 +- panda/src/pnmimage/pnmFileType.h | 2 +- panda/src/pnmimage/pnmFileTypeRegistry.h | 2 +- panda/src/pnmimage/pnmImageHeader.h | 2 +- panda/src/putil/bitMask.h | 2 +- panda/src/putil/config_util.cxx | 2 +- panda/src/putil/configurable.h | 2 +- panda/src/putil/factoryBase.h | 2 +- panda/src/putil/factoryParams.h | 2 +- panda/src/putil/globalPointerRegistry.h | 2 +- panda/src/putil/test_types.cxx | 2 +- panda/src/putil/typedWritable.h | 2 +- panda/src/putil/writable.h | 2 +- panda/src/sgattrib/attribTraverser.cxx | 2 +- panda/src/sgmanip/findApproxPath.h | 2 +- panda/src/sgraph/renderTraverser.h | 2 +- panda/src/sgraphutil/frustumCullTraverser.h | 2 +- panda/src/sgraphutil/sceneGraphAnalyzer.h | 2 +- panda/src/sgraphutil/sceneGraphReducer.h | 2 +- pandatool/src/eggcharbase/eggBackPointer.h | 2 +- pandatool/src/flt/fltRecord.h | 2 +- pandatool/src/lwo/iffChunk.h | 2 +- pandatool/src/lwo/iffInputFile.h | 2 +- 64 files changed, 290 insertions(+), 243 deletions(-) create mode 100644 panda/src/express/typedObject.I create mode 100644 panda/src/express/typedObject.cxx create mode 100644 panda/src/express/typedObject.h diff --git a/panda/src/audio/audio_sound.h b/panda/src/audio/audio_sound.h index 9f65c1eb80..2c22ee01e3 100644 --- a/panda/src/audio/audio_sound.h +++ b/panda/src/audio/audio_sound.h @@ -8,7 +8,7 @@ #include "audio_trait.h" #include -#include +#include #include #include diff --git a/panda/src/char/dynamicVertices.h b/panda/src/char/dynamicVertices.h index cc05f79652..6bb0f41404 100644 --- a/panda/src/char/dynamicVertices.h +++ b/panda/src/char/dynamicVertices.h @@ -9,7 +9,7 @@ #include #include -#include +#include #include #include #include diff --git a/panda/src/display/textureContext.h b/panda/src/display/textureContext.h index 840211c9a1..9d8850c8a3 100644 --- a/panda/src/display/textureContext.h +++ b/panda/src/display/textureContext.h @@ -8,7 +8,7 @@ #include -#include +#include class Texture; diff --git a/panda/src/doc/sampleClass.h b/panda/src/doc/sampleClass.h index cb66c9c1a4..70af19379a 100644 --- a/panda/src/doc/sampleClass.h +++ b/panda/src/doc/sampleClass.h @@ -16,7 +16,7 @@ #include "localHeaderFile.h" #include "anotherLocalHeaderFile.h" -#include +#include #include #include diff --git a/panda/src/egg/eggAttributes.h b/panda/src/egg/eggAttributes.h index ddf0cee81d..15744695b8 100644 --- a/panda/src/egg/eggAttributes.h +++ b/panda/src/egg/eggAttributes.h @@ -10,7 +10,7 @@ #include "eggMorphList.h" -#include +#include #include //////////////////////////////////////////////////////////////////// diff --git a/panda/src/egg/eggGroupNode.h b/panda/src/egg/eggGroupNode.h index e77f57f232..d25218619c 100644 --- a/panda/src/egg/eggGroupNode.h +++ b/panda/src/egg/eggGroupNode.h @@ -11,7 +11,7 @@ #include "eggNode.h" #include -#include +#include #include #include diff --git a/panda/src/egg/eggNode.h b/panda/src/egg/eggNode.h index ac820ae1f5..9c93cd2866 100644 --- a/panda/src/egg/eggNode.h +++ b/panda/src/egg/eggNode.h @@ -10,7 +10,7 @@ #include "eggNamedObject.h" -#include +#include #include #include #include diff --git a/panda/src/egg/eggRenderMode.h b/panda/src/egg/eggRenderMode.h index 3bd81039ff..f9c2e4c471 100644 --- a/panda/src/egg/eggRenderMode.h +++ b/panda/src/egg/eggRenderMode.h @@ -8,7 +8,7 @@ #include -#include +#include #include diff --git a/panda/src/egg2sg/test_loader.cxx b/panda/src/egg2sg/test_loader.cxx index 40a1ef4a74..f8d5c93204 100644 --- a/panda/src/egg2sg/test_loader.cxx +++ b/panda/src/egg2sg/test_loader.cxx @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include #include diff --git a/panda/src/event/eventParameter.h b/panda/src/event/eventParameter.h index 918ac20bec..5b44f43098 100644 --- a/panda/src/event/eventParameter.h +++ b/panda/src/event/eventParameter.h @@ -9,7 +9,7 @@ #include #include -#include +#include #include #include //#include diff --git a/panda/src/event/eventReceiver.h b/panda/src/event/eventReceiver.h index 97b639ffe9..7ddc6a662e 100644 --- a/panda/src/event/eventReceiver.h +++ b/panda/src/event/eventReceiver.h @@ -8,7 +8,7 @@ #include -#include +#include //////////////////////////////////////////////////////////////////// // Class : EventReceiver diff --git a/panda/src/express/Sources.pp b/panda/src/express/Sources.pp index 59a30d69aa..cb83140c8b 100644 --- a/panda/src/express/Sources.pp +++ b/panda/src/express/Sources.pp @@ -32,7 +32,9 @@ reversedNumericData.I reversedNumericData.cxx reversedNumericData.h \ tokenBoard.I tokenBoard.h \ trueClock.I trueClock.cxx trueClock.h typeHandle.I typeHandle.cxx \ - typeHandle.h typedReferenceCount.I typedReferenceCount.cxx \ + typeHandle.h \ + typedObject.I typedObject.cxx typedObject.h \ + typedReferenceCount.I typedReferenceCount.cxx \ typedReferenceCount.h typedef.h error_utils.cxx error_utils.h #define IF_CRYPTO_SOURCES \ @@ -56,6 +58,7 @@ pointerTo.I pointerTo.h referenceCount.I referenceCount.h \ reversedNumericData.I reversedNumericData.h \ tokenBoard.h trueClock.I trueClock.h typeHandle.I typeHandle.h \ + typedObject.h typedObject.I \ typedReferenceCount.I typedReferenceCount.h typedef.h \ namable.I namable.h tokenBoard.I patchfile.h patchfile.I \ error_utils.h diff --git a/panda/src/express/config_express.cxx b/panda/src/express/config_express.cxx index 2b6aa2e9be..5307fd3287 100644 --- a/panda/src/express/config_express.cxx +++ b/panda/src/express/config_express.cxx @@ -5,7 +5,7 @@ #include "config_express.h" #include "clockObject.h" -#include "typeHandle.h" +#include "typedObject.h" #include "referenceCount.h" #include "typedReferenceCount.h" #include "datagram.h" diff --git a/panda/src/express/datagram.h b/panda/src/express/datagram.h index cb70d6d845..75cac9360f 100644 --- a/panda/src/express/datagram.h +++ b/panda/src/express/datagram.h @@ -9,7 +9,7 @@ #include #include "numeric_types.h" -#include "typeHandle.h" +#include "typedObject.h" #include "littleEndian.h" #include "bigEndian.h" diff --git a/panda/src/express/memoryUsage.h b/panda/src/express/memoryUsage.h index 67fcfde2ea..ff1dbf1895 100644 --- a/panda/src/express/memoryUsage.h +++ b/panda/src/express/memoryUsage.h @@ -8,7 +8,7 @@ #include -#include "typeHandle.h" +#include "typedObject.h" #include diff --git a/panda/src/express/memoryUsagePointers.h b/panda/src/express/memoryUsagePointers.h index 89798c3a4c..b76689f90d 100644 --- a/panda/src/express/memoryUsagePointers.h +++ b/panda/src/express/memoryUsagePointers.h @@ -8,7 +8,7 @@ #include -#include "typeHandle.h" +#include "typedObject.h" #include "pointerTo.h" #include "referenceCount.h" diff --git a/panda/src/express/namable.h b/panda/src/express/namable.h index 60011eb773..8095fac017 100644 --- a/panda/src/express/namable.h +++ b/panda/src/express/namable.h @@ -7,7 +7,7 @@ #include -#include "typeHandle.h" +#include "typedObject.h" #include /////////////////////////////////////////////////////////////////// diff --git a/panda/src/express/pointerTo.h b/panda/src/express/pointerTo.h index 28bfc6ab4e..b548735cdc 100644 --- a/panda/src/express/pointerTo.h +++ b/panda/src/express/pointerTo.h @@ -151,7 +151,7 @@ PUBLISHED: // e.g. instead of (MyType *)(BaseClass *)ptr, use (MyType *)ptr.p() // If your base class is a derivative of TypedObject, you might want - // to use the DCAST macro defined in typeHandle.h instead, + // to use the DCAST macro defined in typedObject.h instead, // e.g. DCAST(MyType, ptr). This provides a clean downcast that // doesn't require .p() or any double-casting, and it can be // run-time checked for correctness. diff --git a/panda/src/express/referenceCount.h b/panda/src/express/referenceCount.h index 3aef81e268..9263f1f8eb 100644 --- a/panda/src/express/referenceCount.h +++ b/panda/src/express/referenceCount.h @@ -17,7 +17,7 @@ #include -#include "typeHandle.h" +#include "typedObject.h" #include "memoryUsage.h" #include "config_express.h" @@ -83,7 +83,7 @@ INLINE void unref_delete(RefCountType *ptr); // that does not have get_class_type(), you will have to // define a template specialization on // _get_type_handle() and _do_init_type(), as in -// typeHandle.h. +// typedObject.h. //////////////////////////////////////////////////////////////////// template class EXPCL_PANDAEXPRESS RefCountProxy : public ReferenceCount { diff --git a/panda/src/express/typeHandle.I b/panda/src/express/typeHandle.I index f60e636193..3ea5156f11 100644 --- a/panda/src/express/typeHandle.I +++ b/panda/src/express/typeHandle.I @@ -317,60 +317,6 @@ register_dynamic_type(const string &name, } -//////////////////////////////////////////////////////////////////// -// Function: TypedObject::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE TypedObject:: -TypedObject() { -} - -//////////////////////////////////////////////////////////////////// -// Function: TypedObject::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE TypedObject:: -TypedObject(const TypedObject &) { -} - -//////////////////////////////////////////////////////////////////// -// Function: TypedObject::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void TypedObject:: -operator = (const TypedObject &) { -} - -//////////////////////////////////////////////////////////////////// -// Function: TypedObject::is_of_type -// Access: Public -// Description: Returns true if the current object is or derives from -// the indicated type. -//////////////////////////////////////////////////////////////////// -INLINE bool TypedObject:: -is_of_type(TypeHandle handle) const { - return get_type().is_derived_from(handle, (TypedObject *)this); -} - -//////////////////////////////////////////////////////////////////// -// Function: TypedObject::is_exact_type -// Access: Public -// Description: Returns true if the current object is the indicated -// type exactly. -//////////////////////////////////////////////////////////////////// -INLINE bool TypedObject:: -is_exact_type(TypeHandle handle) const { -#ifndef NDEBUG - // Call get_name() to force the type to look itself up if necessary. - get_type().get_name((TypedObject *)this); -#endif - return get_type() == handle; -} - - //////////////////////////////////////////////////////////////////// // Function: _dcast_get_typehandle // Description: Returns the TypeHandle associated with the type of diff --git a/panda/src/express/typeHandle.cxx b/panda/src/express/typeHandle.cxx index 441332c543..43649ac2c3 100644 --- a/panda/src/express/typeHandle.cxx +++ b/panda/src/express/typeHandle.cxx @@ -4,6 +4,7 @@ //////////////////////////////////////////////////////////////////// #include "typeHandle.h" +#include "typedObject.h" #include "indent.h" #include "config_express.h" @@ -16,8 +17,6 @@ TypeRegistry *TypeRegistry::_global_pointer = NULL; -TypeHandle TypedObject::_type_handle; - // This is initialized to zero by static initialization. TypeHandle TypeHandle::_none; @@ -681,28 +680,3 @@ get_parent_towards(TypeHandle type) const { return TypeHandle::none(); } - -//////////////////////////////////////////////////////////////////// -// Function: TypedObject::Destructor -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -TypedObject:: -~TypedObject() { -} - - -//////////////////////////////////////////////////////////////////// -// Function: TypedObject::get_type -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -TypeHandle TypedObject:: -get_type() const { - // Normally, this function should never be called, because it is a - // pure virtual function. If it is called, you probably called - // get_type() on a recently-destructed object. - express_cat.warning() - << "TypedObject::get_type() called!\n"; - return _type_handle; -} diff --git a/panda/src/express/typeHandle.h b/panda/src/express/typeHandle.h index c7791e262b..5ca4b36657 100644 --- a/panda/src/express/typeHandle.h +++ b/panda/src/express/typeHandle.h @@ -270,109 +270,6 @@ register_dynamic_type(const string &name, TypeHandle parent3, TypeHandle parent4); - -//////////////////////////////////////////////////////////////////// -// Class : TypedObject -// Description : This is an abstract class that all classes which -// use TypeHandle, and also provide virtual functions to -// support polymorphism, should inherit from. Each -// derived class should define get_type(), which should -// return the specific type of the derived class. -// Inheriting from this automatically provides support -// for is_of_type() and is_exact_type(). -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDAEXPRESS TypedObject { -public: - INLINE TypedObject(); - INLINE TypedObject(const TypedObject ©); - INLINE void operator = (const TypedObject ©); - -PUBLISHED: - // A virtual destructor is just a good idea. - virtual ~TypedObject(); - - // Derived classes should override this function to return - // get_class_type(). - virtual TypeHandle get_type() const=0; - - INLINE bool is_of_type(TypeHandle handle) const; - INLINE bool is_exact_type(TypeHandle handle) const; - -public: - // Derived classes should override this function to call - // init_type(). It will only be called in error situations when the - // type was for some reason not properly initialized. - virtual TypeHandle force_init_type()=0; - -public: - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - register_type(_type_handle, "TypedObject"); - } - -private: - static TypeHandle _type_handle; -}; - -// The DCAST (downcast) macro is defined as a convenience for -// downcasting from some TypedObject pointer (or a PointerTo). It's -// just a normal C++-style downcast, except it first checks get_type() -// to make sure the downcasting is safe. If you compile with NDEBUG, -// this check is removed. - -// DCAST will return NULL if the downcasting is unsafe. If you'd -// rather it abort out of the function (ala nassertv/nassertr), then -// see DCAST_INTO_V and DCAST_INTO_R, below. - -template -INLINE WantType *_dcast(WantType *, TypedObject *ptr); -template -INLINE const WantType *_dcast(WantType *, const TypedObject *ptr); - -// Note: it is important that DCAST not repeat the pointer parameter, -// since many users of DCAST may want to use the result of a function -// as the pointer parameter, and it could be terribly confusing and -// difficult to trace if the function was executed twice. This -// happened! -#define DCAST(want_type, pointer) _dcast((want_type*)0, pointer) - -// DCAST_INTO_V and DCAST_INTO_R are similar in purpose to DCAST, -// except they: (a) automatically assign a variable instead of -// returning the downcasted pointer, and (b) they immediately return -// out of the function if the downcasting fails. DCAST_INTO_V is for -// use in a void function and returns nothing; DCAST_INTO_R is for use -// in a non-void function and returns the indicated value. - -// Both DCAST_INTO_V and DCAST_INTO_R accept as the first parameter a -// variable of type (want_type *) or (const want_type *), instead of -// the name of the type. This variable will be filled with the new -// pointer. - - -// _dcast_ref is used to implement DCAST_INTO_V and DCAST_INTO_R. Its -// difference from _dcast is that it takes a reference to a pointer as -// a first parameter. The main point of this is to shut up the -// compiler about pointers used before their value is assigned. -template -INLINE WantType *_dcast_ref(WantType *&, TypedObject *ptr); -template -INLINE const WantType *_dcast_ref(WantType *&, const TypedObject *ptr); - - -#define DCAST_INTO_V(to_pointer, from_pointer) \ - { \ - (to_pointer) = _dcast_ref(to_pointer, from_pointer); \ - nassertv((void *)(to_pointer) != (void *)NULL); \ - } - -#define DCAST_INTO_R(to_pointer, from_pointer, return_value) \ - { \ - (to_pointer) = _dcast_ref(to_pointer, from_pointer); \ - nassertr((void *)(to_pointer) != (void *)NULL, return_value); \ - } - // A few system-wide TypeHandles are defined for some basic types. extern TypeHandle EXPCL_PANDAEXPRESS long_type_handle; extern TypeHandle EXPCL_PANDAEXPRESS int_type_handle; diff --git a/panda/src/express/typedObject.I b/panda/src/express/typedObject.I new file mode 100644 index 0000000000..5cabcfd4db --- /dev/null +++ b/panda/src/express/typedObject.I @@ -0,0 +1,71 @@ +// Filename: typedObject.I +// Created by: drose (11May01) +// +//////////////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////////////// +// Function: TypedObject::Constructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE TypedObject:: +TypedObject() { +} + +//////////////////////////////////////////////////////////////////// +// Function: TypedObject::Copy Constructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE TypedObject:: +TypedObject(const TypedObject &) { +} + +//////////////////////////////////////////////////////////////////// +// Function: TypedObject::Copy Assignment Operator +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void TypedObject:: +operator = (const TypedObject &) { +} + +//////////////////////////////////////////////////////////////////// +// Function: TypedObject::get_type_index +// Access: Public +// Description: Returns the internal index number associated with +// this object's TypeHandle, a unique number for each +// different type. This is equivalent to +// get_type().get_index(). +//////////////////////////////////////////////////////////////////// +INLINE int TypedObject:: +get_type_index() const { + return get_type().get_index(); +} + +//////////////////////////////////////////////////////////////////// +// Function: TypedObject::is_of_type +// Access: Public +// Description: Returns true if the current object is or derives from +// the indicated type. +//////////////////////////////////////////////////////////////////// +INLINE bool TypedObject:: +is_of_type(TypeHandle handle) const { + return get_type().is_derived_from(handle, (TypedObject *)this); +} + +//////////////////////////////////////////////////////////////////// +// Function: TypedObject::is_exact_type +// Access: Public +// Description: Returns true if the current object is the indicated +// type exactly. +//////////////////////////////////////////////////////////////////// +INLINE bool TypedObject:: +is_exact_type(TypeHandle handle) const { +#ifndef NDEBUG + // Call get_name() to force the type to look itself up if necessary. + get_type().get_name((TypedObject *)this); +#endif + return get_type() == handle; +} diff --git a/panda/src/express/typedObject.cxx b/panda/src/express/typedObject.cxx new file mode 100644 index 0000000000..55c45a50ca --- /dev/null +++ b/panda/src/express/typedObject.cxx @@ -0,0 +1,35 @@ +// Filename: typedObject.cxx +// Created by: drose (11May01) +// +//////////////////////////////////////////////////////////////////// + +#include "typedObject.h" +#include "config_express.h" + + +TypeHandle TypedObject::_type_handle; + +//////////////////////////////////////////////////////////////////// +// Function: TypedObject::Destructor +// Access: Public, Virtual +// Description: +//////////////////////////////////////////////////////////////////// +TypedObject:: +~TypedObject() { +} + + +//////////////////////////////////////////////////////////////////// +// Function: TypedObject::get_type +// Access: Public, Virtual +// Description: +//////////////////////////////////////////////////////////////////// +TypeHandle TypedObject:: +get_type() const { + // Normally, this function should never be called, because it is a + // pure virtual function. If it is called, you probably called + // get_type() on a recently-destructed object. + express_cat.warning() + << "TypedObject::get_type() called!\n"; + return _type_handle; +} diff --git a/panda/src/express/typedObject.h b/panda/src/express/typedObject.h new file mode 100644 index 0000000000..8714dc9620 --- /dev/null +++ b/panda/src/express/typedObject.h @@ -0,0 +1,119 @@ +// Filename: typedObject.h +// Created by: drose (11May01) +// +//////////////////////////////////////////////////////////////////// + +#ifndef TYPEDOBJECT_H +#define TYPEDOBJECT_H + +#include + +#include "typeHandle.h" + + +//////////////////////////////////////////////////////////////////// +// Class : TypedObject +// Description : This is an abstract class that all classes which +// use TypeHandle, and also provide virtual functions to +// support polymorphism, should inherit from. Each +// derived class should define get_type(), which should +// return the specific type of the derived class. +// Inheriting from this automatically provides support +// for is_of_type() and is_exact_type(). +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDAEXPRESS TypedObject { +public: + INLINE TypedObject(); + INLINE TypedObject(const TypedObject ©); + INLINE void operator = (const TypedObject ©); + +PUBLISHED: + // A virtual destructor is just a good idea. + virtual ~TypedObject(); + + // Derived classes should override this function to return + // get_class_type(). + virtual TypeHandle get_type() const=0; + + INLINE int get_type_index() const; + INLINE bool is_of_type(TypeHandle handle) const; + INLINE bool is_exact_type(TypeHandle handle) const; + +public: + // Derived classes should override this function to call + // init_type(). It will only be called in error situations when the + // type was for some reason not properly initialized. + virtual TypeHandle force_init_type()=0; + +public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + register_type(_type_handle, "TypedObject"); + } + +private: + static TypeHandle _type_handle; +}; + +// The DCAST (downcast) macro is defined as a convenience for +// downcasting from some TypedObject pointer (or a PointerTo). It's +// just a normal C++-style downcast, except it first checks get_type() +// to make sure the downcasting is safe. If you compile with NDEBUG, +// this check is removed. + +// DCAST will return NULL if the downcasting is unsafe. If you'd +// rather it abort out of the function (ala nassertv/nassertr), then +// see DCAST_INTO_V and DCAST_INTO_R, below. + +template +INLINE WantType *_dcast(WantType *, TypedObject *ptr); +template +INLINE const WantType *_dcast(WantType *, const TypedObject *ptr); + +// Note: it is important that DCAST not repeat the pointer parameter, +// since many users of DCAST may want to use the result of a function +// as the pointer parameter, and it could be terribly confusing and +// difficult to trace if the function was executed twice. This +// happened! +#define DCAST(want_type, pointer) _dcast((want_type*)0, pointer) + +// DCAST_INTO_V and DCAST_INTO_R are similar in purpose to DCAST, +// except they: (a) automatically assign a variable instead of +// returning the downcasted pointer, and (b) they immediately return +// out of the function if the downcasting fails. DCAST_INTO_V is for +// use in a void function and returns nothing; DCAST_INTO_R is for use +// in a non-void function and returns the indicated value. + +// Both DCAST_INTO_V and DCAST_INTO_R accept as the first parameter a +// variable of type (want_type *) or (const want_type *), instead of +// the name of the type. This variable will be filled with the new +// pointer. + + +// _dcast_ref is used to implement DCAST_INTO_V and DCAST_INTO_R. Its +// difference from _dcast is that it takes a reference to a pointer as +// a first parameter. The main point of this is to shut up the +// compiler about pointers used before their value is assigned. +template +INLINE WantType *_dcast_ref(WantType *&, TypedObject *ptr); +template +INLINE const WantType *_dcast_ref(WantType *&, const TypedObject *ptr); + + +#define DCAST_INTO_V(to_pointer, from_pointer) \ + { \ + (to_pointer) = _dcast_ref(to_pointer, from_pointer); \ + nassertv((void *)(to_pointer) != (void *)NULL); \ + } + +#define DCAST_INTO_R(to_pointer, from_pointer, return_value) \ + { \ + (to_pointer) = _dcast_ref(to_pointer, from_pointer); \ + nassertr((void *)(to_pointer) != (void *)NULL, return_value); \ + } + +#include "typedObject.I" + +#endif diff --git a/panda/src/express/typedReferenceCount.h b/panda/src/express/typedReferenceCount.h index ef50e7281e..bc6f9dd36d 100644 --- a/panda/src/express/typedReferenceCount.h +++ b/panda/src/express/typedReferenceCount.h @@ -7,7 +7,7 @@ #include -#include "typeHandle.h" +#include "typedObject.h" #include "referenceCount.h" //////////////////////////////////////////////////////////////////// diff --git a/panda/src/glgsg/glGraphicsStateGuardian.cxx b/panda/src/glgsg/glGraphicsStateGuardian.cxx index b2f397f1a7..81d70956c5 100644 --- a/panda/src/glgsg/glGraphicsStateGuardian.cxx +++ b/panda/src/glgsg/glGraphicsStateGuardian.cxx @@ -286,7 +286,9 @@ reset() { _light_info = new LightInfo[_max_lights]; // Set up the clip plane id map - glGetIntegerv(GL_MAX_CLIP_PLANES, &_max_clip_planes); + GLint max_clip_planes; + glGetIntegerv(GL_MAX_CLIP_PLANES, &max_clip_planes); + _max_clip_planes = max_clip_planes; _available_clip_plane_ids = PTA(PlaneNode*)(_max_clip_planes); _clip_plane_enabled = new bool[_max_clip_planes]; _cur_clip_plane_enabled = new bool[_max_clip_planes]; diff --git a/panda/src/glxdisplay/glxDisplay.h b/panda/src/glxdisplay/glxDisplay.h index 6378bdde5e..c16cf213a4 100644 --- a/panda/src/glxdisplay/glxDisplay.h +++ b/panda/src/glxdisplay/glxDisplay.h @@ -7,7 +7,7 @@ #define GLXDISPLAY_H #include -#include +#include #include diff --git a/panda/src/graph/arcChain.h b/panda/src/graph/arcChain.h index 717608c400..282420d2d6 100644 --- a/panda/src/graph/arcChain.h +++ b/panda/src/graph/arcChain.h @@ -14,7 +14,7 @@ #include #include #include -#include +#include //////////////////////////////////////////////////////////////////// // Class : ArcChain diff --git a/panda/src/graph/boundedObject.h b/panda/src/graph/boundedObject.h index e9e331534f..33a47f3e5d 100644 --- a/panda/src/graph/boundedObject.h +++ b/panda/src/graph/boundedObject.h @@ -10,7 +10,7 @@ #include "boundingVolume.h" -#include +#include #include //////////////////////////////////////////////////////////////////// diff --git a/panda/src/graph/dftraverser.h b/panda/src/graph/dftraverser.h index 694ed3c136..cf1fa3fa3f 100644 --- a/panda/src/graph/dftraverser.h +++ b/panda/src/graph/dftraverser.h @@ -11,7 +11,7 @@ #include "node.h" #include "nodeRelation.h" -#include +#include /////////////////////////////////////////////////////////////////// // Class : DFTraverser diff --git a/panda/src/graph/graphReducer.h b/panda/src/graph/graphReducer.h index 734929706a..a1a38b9f5a 100644 --- a/panda/src/graph/graphReducer.h +++ b/panda/src/graph/graphReducer.h @@ -10,7 +10,7 @@ #include "nodeRelation.h" -#include +#include /////////////////////////////////////////////////////////////////// // Class : GraphReducer diff --git a/panda/src/graph/wrt.h b/panda/src/graph/wrt.h index 93a2ff824d..34f454e726 100644 --- a/panda/src/graph/wrt.h +++ b/panda/src/graph/wrt.h @@ -12,7 +12,7 @@ #include "node.h" #include "config_graph.h" -#include +#include class Node; diff --git a/panda/src/light/light.h b/panda/src/light/light.h index 5adfc7f7e2..417d69993d 100644 --- a/panda/src/light/light.h +++ b/panda/src/light/light.h @@ -11,7 +11,7 @@ //////////////////////////////////////////////////////////////////// #include -#include +#include #include #include diff --git a/panda/src/linmath/lmatrix3.h b/panda/src/linmath/lmatrix3.h index 8599261db6..dda3bf7bc6 100644 --- a/panda/src/linmath/lmatrix3.h +++ b/panda/src/linmath/lmatrix3.h @@ -8,7 +8,7 @@ #include #include -#include +#include #include #include #include diff --git a/panda/src/linmath/lmatrix4.h b/panda/src/linmath/lmatrix4.h index e1d8bb1dca..a61df24d30 100644 --- a/panda/src/linmath/lmatrix4.h +++ b/panda/src/linmath/lmatrix4.h @@ -8,7 +8,7 @@ #include #include -#include +#include #include #include #include diff --git a/panda/src/linmath/lvecBase2.h b/panda/src/linmath/lvecBase2.h index 7856d737fe..c7d4d60628 100644 --- a/panda/src/linmath/lvecBase2.h +++ b/panda/src/linmath/lvecBase2.h @@ -7,7 +7,7 @@ #define LVECBASE2_H #include -#include +#include #include #include #include diff --git a/panda/src/linmath/lvecBase3.h b/panda/src/linmath/lvecBase3.h index 1031fbf19a..3e10a2587d 100644 --- a/panda/src/linmath/lvecBase3.h +++ b/panda/src/linmath/lvecBase3.h @@ -7,7 +7,7 @@ #define LVECBASE3_H #include -#include +#include #include #include #include diff --git a/panda/src/linmath/lvecBase4.h b/panda/src/linmath/lvecBase4.h index eacee569bf..71cdda7c12 100644 --- a/panda/src/linmath/lvecBase4.h +++ b/panda/src/linmath/lvecBase4.h @@ -7,7 +7,7 @@ #define LVECBASE4_H #include -#include +#include #include #include #include diff --git a/panda/src/loader/loaderFileType.h b/panda/src/loader/loaderFileType.h index e3734d1fcc..7811764e6c 100644 --- a/panda/src/loader/loaderFileType.h +++ b/panda/src/loader/loaderFileType.h @@ -8,7 +8,7 @@ #include -#include +#include #include #include #include diff --git a/panda/src/mathutil/boundingVolume.h b/panda/src/mathutil/boundingVolume.h index 22700542cb..a79719055f 100644 --- a/panda/src/mathutil/boundingVolume.h +++ b/panda/src/mathutil/boundingVolume.h @@ -8,7 +8,7 @@ #include -#include +#include #include class BoundingSphere; diff --git a/panda/src/parametrics/parametricCurveDrawer.h b/panda/src/parametrics/parametricCurveDrawer.h index 88b0d012ac..6b4a9633b0 100644 --- a/panda/src/parametrics/parametricCurveDrawer.h +++ b/panda/src/parametrics/parametricCurveDrawer.h @@ -12,7 +12,7 @@ #include #include -#include +#include //////////////////////////////////////////////////////////////////// // Class : ParametricCurveDrawer diff --git a/panda/src/pnmimage/pnmFileType.h b/panda/src/pnmimage/pnmFileType.h index 77305a907a..9566020808 100644 --- a/panda/src/pnmimage/pnmFileType.h +++ b/panda/src/pnmimage/pnmFileType.h @@ -10,7 +10,7 @@ #include "pnmimage_base.h" -#include +#include #include class PNMReader; diff --git a/panda/src/pnmimage/pnmFileTypeRegistry.h b/panda/src/pnmimage/pnmFileTypeRegistry.h index 33755161a2..b45cd76f9b 100644 --- a/panda/src/pnmimage/pnmFileTypeRegistry.h +++ b/panda/src/pnmimage/pnmFileTypeRegistry.h @@ -8,7 +8,7 @@ #include -#include +#include class PNMFileType; diff --git a/panda/src/pnmimage/pnmImageHeader.h b/panda/src/pnmimage/pnmImageHeader.h index 96d871c209..3b65458bb1 100644 --- a/panda/src/pnmimage/pnmImageHeader.h +++ b/panda/src/pnmimage/pnmImageHeader.h @@ -10,7 +10,7 @@ #include "pnmimage_base.h" -#include +#include #include class PNMFileType; diff --git a/panda/src/putil/bitMask.h b/panda/src/putil/bitMask.h index 49704cc9d5..1fa33da7f7 100644 --- a/panda/src/putil/bitMask.h +++ b/panda/src/putil/bitMask.h @@ -9,7 +9,7 @@ #include #include "numeric_types.h" -#include "typeHandle.h" +#include "typedObject.h" #include "indent.h" diff --git a/panda/src/putil/config_util.cxx b/panda/src/putil/config_util.cxx index 6c19026282..a51fdd8e9e 100644 --- a/panda/src/putil/config_util.cxx +++ b/panda/src/putil/config_util.cxx @@ -5,7 +5,7 @@ #include "config_util.h" #include "clockObject.h" -#include "typeHandle.h" +#include "typedObject.h" #include "configurable.h" #include "namable.h" #include "referenceCount.h" diff --git a/panda/src/putil/configurable.h b/panda/src/putil/configurable.h index 5264cbdeea..e007cf7e3e 100644 --- a/panda/src/putil/configurable.h +++ b/panda/src/putil/configurable.h @@ -12,7 +12,7 @@ #include -#include "typeHandle.h" +#include "typedObject.h" //////////////////////////////////////////////////////////////////// // Defines diff --git a/panda/src/putil/factoryBase.h b/panda/src/putil/factoryBase.h index b3fc49397f..6e05941f6c 100644 --- a/panda/src/putil/factoryBase.h +++ b/panda/src/putil/factoryBase.h @@ -8,7 +8,7 @@ #include -#include "typeHandle.h" +#include "typedObject.h" #include "typedReferenceCount.h" #include "factoryParams.h" diff --git a/panda/src/putil/factoryParams.h b/panda/src/putil/factoryParams.h index 5bc628221d..a0bdb464e1 100644 --- a/panda/src/putil/factoryParams.h +++ b/panda/src/putil/factoryParams.h @@ -8,7 +8,7 @@ #include -#include "typeHandle.h" +#include "typedObject.h" #include "typedReferenceCount.h" #include "pointerTo.h" #include "factoryParam.h" diff --git a/panda/src/putil/globalPointerRegistry.h b/panda/src/putil/globalPointerRegistry.h index 718a4fc09a..a8208f58cb 100644 --- a/panda/src/putil/globalPointerRegistry.h +++ b/panda/src/putil/globalPointerRegistry.h @@ -8,7 +8,7 @@ #include -#include "typeHandle.h" +#include "typedObject.h" #include diff --git a/panda/src/putil/test_types.cxx b/panda/src/putil/test_types.cxx index f3d80a13ea..45b79088d8 100644 --- a/panda/src/putil/test_types.cxx +++ b/panda/src/putil/test_types.cxx @@ -3,7 +3,7 @@ // //////////////////////////////////////////////////////////////////// -#include "typeHandle.h" +#include "typedObject.h" #include "pointerTo.h" #include "pointerToArray.h" #include "referenceCount.h" diff --git a/panda/src/putil/typedWritable.h b/panda/src/putil/typedWritable.h index f611e63836..60a4c4adee 100644 --- a/panda/src/putil/typedWritable.h +++ b/panda/src/putil/typedWritable.h @@ -5,7 +5,7 @@ #ifndef __TYPED_WRITABLE_ #define __TYPED_WRITABLE_ -#include "typeHandle.h" +#include "typedObject.h" #include "writable.h" #include "vector_typedWritable.h" diff --git a/panda/src/putil/writable.h b/panda/src/putil/writable.h index f5037e8dae..307dfab2eb 100644 --- a/panda/src/putil/writable.h +++ b/panda/src/putil/writable.h @@ -6,7 +6,7 @@ #define __WRITABLE_ #include "vector_writable.h" -#include "typeHandle.h" +#include "typedObject.h" class BamWriter; class Datagram; diff --git a/panda/src/sgattrib/attribTraverser.cxx b/panda/src/sgattrib/attribTraverser.cxx index edc84bfd5c..a728a60d6b 100644 --- a/panda/src/sgattrib/attribTraverser.cxx +++ b/panda/src/sgattrib/attribTraverser.cxx @@ -15,7 +15,7 @@ #include #include #include -#include +#include //////////////////////////////////////////////////////////////////// // Function: AttribTraverser::constructor diff --git a/panda/src/sgmanip/findApproxPath.h b/panda/src/sgmanip/findApproxPath.h index 83895bebfd..2b5fdb13ad 100644 --- a/panda/src/sgmanip/findApproxPath.h +++ b/panda/src/sgmanip/findApproxPath.h @@ -8,7 +8,7 @@ #include -#include +#include #include #include diff --git a/panda/src/sgraph/renderTraverser.h b/panda/src/sgraph/renderTraverser.h index 08978c58cd..45ad5d66d2 100644 --- a/panda/src/sgraph/renderTraverser.h +++ b/panda/src/sgraph/renderTraverser.h @@ -9,7 +9,7 @@ #include #include -#include +#include #include #include diff --git a/panda/src/sgraphutil/frustumCullTraverser.h b/panda/src/sgraphutil/frustumCullTraverser.h index a121f66327..ede726185a 100644 --- a/panda/src/sgraphutil/frustumCullTraverser.h +++ b/panda/src/sgraphutil/frustumCullTraverser.h @@ -10,7 +10,7 @@ #include #include -#include +#include #include #include #include diff --git a/panda/src/sgraphutil/sceneGraphAnalyzer.h b/panda/src/sgraphutil/sceneGraphAnalyzer.h index 155a7a056c..6923a98427 100644 --- a/panda/src/sgraphutil/sceneGraphAnalyzer.h +++ b/panda/src/sgraphutil/sceneGraphAnalyzer.h @@ -8,7 +8,7 @@ #include -#include +#include #include #include diff --git a/panda/src/sgraphutil/sceneGraphReducer.h b/panda/src/sgraphutil/sceneGraphReducer.h index 3c12bba0f5..977f15b4b3 100644 --- a/panda/src/sgraphutil/sceneGraphReducer.h +++ b/panda/src/sgraphutil/sceneGraphReducer.h @@ -9,7 +9,7 @@ #include #include -#include +#include #include #include #include diff --git a/pandatool/src/eggcharbase/eggBackPointer.h b/pandatool/src/eggcharbase/eggBackPointer.h index 1e9d244181..2cc76a93f0 100644 --- a/pandatool/src/eggcharbase/eggBackPointer.h +++ b/pandatool/src/eggcharbase/eggBackPointer.h @@ -8,7 +8,7 @@ #include -#include +#include //////////////////////////////////////////////////////////////////// // Class : EggBackPointer diff --git a/pandatool/src/flt/fltRecord.h b/pandatool/src/flt/fltRecord.h index c15981ffc2..cb8c555738 100644 --- a/pandatool/src/flt/fltRecord.h +++ b/pandatool/src/flt/fltRecord.h @@ -11,7 +11,7 @@ #include "fltOpcode.h" #include "fltError.h" -#include +#include #include #include diff --git a/pandatool/src/lwo/iffChunk.h b/pandatool/src/lwo/iffChunk.h index 600ab42f90..be48d04b9e 100644 --- a/pandatool/src/lwo/iffChunk.h +++ b/pandatool/src/lwo/iffChunk.h @@ -10,7 +10,7 @@ #include "iffId.h" -#include +#include #include class IffInputFile; diff --git a/pandatool/src/lwo/iffInputFile.h b/pandatool/src/lwo/iffInputFile.h index 0bf694d980..068c06d6f5 100644 --- a/pandatool/src/lwo/iffInputFile.h +++ b/pandatool/src/lwo/iffInputFile.h @@ -11,7 +11,7 @@ #include "iffId.h" #include "iffChunk.h" -#include +#include #include class Datagram;