00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00030 #ifndef __vtkTypeTemplate_h
00031 #define __vtkTypeTemplate_h
00032
00033 #include "vtkObjectBase.h"
00034 #include <typeinfo>
00035
00036 template<class ThisT, class BaseT>
00037 class vtkTypeTemplate :
00038 public BaseT
00039 {
00040 public:
00041 typedef BaseT Superclass;
00042
00043 private:
00044 virtual const char* GetClassNameInternal() const
00045 {
00046 return typeid(ThisT).name();
00047 }
00048
00049 public:
00050 static int IsTypeOf(const char* type)
00051 {
00052 if(!strcmp(typeid(ThisT).name(), type))
00053 {
00054 return 1;
00055 }
00056 return BaseT::IsTypeOf(type);
00057 }
00058
00059 virtual int IsA(const char *type)
00060 {
00061 return this->IsTypeOf(type);
00062 }
00063
00064 static ThisT* SafeDownCast(vtkObjectBase* o)
00065 {
00066 if(o && o->IsA(typeid(ThisT).name()))
00067 {
00068 return static_cast<ThisT*>(o);
00069 }
00070
00071 return 0;
00072 }
00073
00074 protected:
00075 virtual vtkObjectBase* NewInstanceInternal() const
00076 {
00077 return ThisT::New();
00078 }
00079
00080 public:
00081 ThisT* NewInstance() const
00082 {
00083 return ThisT::SafeDownCast(this->NewInstanceInternal());
00084 }
00085 };
00086
00087 #endif
00088