VTK
/Users/kitware/Dashboards/MyTests/VTK_BLD_Release_docs/Utilities/Doxygen/dox/Common/Core/vtkTypeTemplate.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkTypeTemplate.h
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 <string>
00035 #include <typeinfo>
00036 
00037 template<class ThisT, class BaseT>
00038 class vtkTypeTemplate :
00039   public BaseT
00040 {
00041 public:
00042   typedef BaseT Superclass;
00043 
00044   ThisT* NewInstance() const
00045   {
00046     return ThisT::SafeDownCast(this->NewInstanceInternal());
00047   }
00048 
00049   static ThisT* SafeDownCast(vtkObjectBase* o)
00050   {
00051     if(o &&
00052        o->IsA(vtkTypeTemplate<ThisT, BaseT>::GetClassNameInternalCachedName()))
00053       {
00054       return static_cast<ThisT*>(o);
00055       }
00056 
00057     return 0;
00058   }
00059 
00060 protected:
00061   virtual vtkObjectBase* NewInstanceInternal() const
00062   {
00063     return ThisT::New();
00064   }
00065 
00066   // We don't expose this publicly, because the typename we generate
00067   // for our template instantiations isn't human-readable, unlike
00068   // "normal" VTK classes.
00069   static int IsTypeOf(const char* type)
00070   {
00071     if (strcmp(vtkTypeTemplate<ThisT, BaseT>::GetClassNameInternalCachedName(),
00072                type) == 0)
00073       {
00074       return 1;
00075       }
00076     return BaseT::IsTypeOf(type);
00077   }
00078 
00079   // We don't expose this publicly, because the typename we generate
00080   // for our template instantiations isn't human-readable, unlike
00081   // "normal" VTK classes.
00082   virtual int IsA(const char *type)
00083   {
00084     return this->IsTypeOf(type);
00085   }
00086 
00087   vtkTypeTemplate() {}
00088 
00089 private:
00090   // not implemented:
00091   vtkTypeTemplate(const vtkTypeTemplate<ThisT, BaseT>&);
00092   void operator=(const vtkTypeTemplate<ThisT, BaseT>&);
00093 
00094   static const char* GetClassNameInternalCachedName()
00095   {
00096     static std::string thisType(typeid(ThisT).name());
00097     return thisType.c_str();
00098   }
00099 
00100   virtual const char* GetClassNameInternal() const
00101   {
00102     return this->GetClassNameInternalCachedName();
00103   }
00104 };
00105 
00106 #endif
00107 
00108 // VTK-HeaderTest-Exclude: vtkTypeTemplate.h