00001 // Filename: typedObject.h 00002 // Created by: drose (11May01) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 #ifndef TYPEDOBJECT_H 00020 #define TYPEDOBJECT_H 00021 00022 #include "pandabase.h" 00023 00024 #include "typeHandle.h" 00025 #include "register_type.h" 00026 00027 00028 //////////////////////////////////////////////////////////////////// 00029 // Class : TypedObject 00030 // Description : This is an abstract class that all classes which 00031 // use TypeHandle, and also provide virtual functions to 00032 // support polymorphism, should inherit from. Each 00033 // derived class should define get_type(), which should 00034 // return the specific type of the derived class. 00035 // Inheriting from this automatically provides support 00036 // for is_of_type() and is_exact_type(). 00037 //////////////////////////////////////////////////////////////////// 00038 class EXPCL_PANDAEXPRESS TypedObject { 00039 public: 00040 INLINE TypedObject(); 00041 INLINE TypedObject(const TypedObject ©); 00042 INLINE void operator = (const TypedObject ©); 00043 00044 PUBLISHED: 00045 // A virtual destructor is just a good idea. 00046 virtual ~TypedObject(); 00047 00048 // Derived classes should override this function to return 00049 // get_class_type(). 00050 virtual TypeHandle get_type() const=0; 00051 00052 INLINE int get_type_index() const; 00053 INLINE bool is_of_type(TypeHandle handle) const; 00054 INLINE bool is_exact_type(TypeHandle handle) const; 00055 00056 public: 00057 // Derived classes should override this function to call 00058 // init_type(). It will only be called in error situations when the 00059 // type was for some reason not properly initialized. 00060 virtual TypeHandle force_init_type()=0; 00061 00062 public: 00063 static TypeHandle get_class_type() { 00064 return _type_handle; 00065 } 00066 static void init_type(); 00067 00068 private: 00069 static TypeHandle _type_handle; 00070 }; 00071 00072 #include "typedObject.I" 00073 00074 #endif