• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

dox/Common/vtkTypeTemplate.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkTypeTemplate.h,v $
00005   
00006 -------------------------------------------------------------------------
00007   Copyright 2008 Sandia Corporation.
00008   Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00009   the U.S. Government retains certain rights in this software.
00010 -------------------------------------------------------------------------
00011 
00012   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00013   All rights reserved.
00014   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00015 
00016      This software is distributed WITHOUT ANY WARRANTY; without even
00017      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00018      PURPOSE.  See the above copyright notice for more information.
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 

Generated by  doxygen 1.7.1