VTK
vtkTypeTemplate.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkTypeTemplate.h
5 
6 -------------------------------------------------------------------------
7  Copyright 2008 Sandia Corporation.
8  Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9  the U.S. Government retains certain rights in this software.
10 -------------------------------------------------------------------------
11 
12  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
13  All rights reserved.
14  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
15 
16  This software is distributed WITHOUT ANY WARRANTY; without even
17  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
18  PURPOSE. See the above copyright notice for more information.
19 
20 =========================================================================*/
21 
30 #ifndef vtkTypeTemplate_h
31 #define vtkTypeTemplate_h
32 
33 #include "vtkObjectBase.h"
34 #include <string>
35 #include <typeinfo>
36 
37 template<class ThisT, class BaseT>
39  public BaseT
40 {
41 public:
42  typedef BaseT Superclass;
43 
44  ThisT* NewInstance() const
45  {
46  return ThisT::SafeDownCast(this->NewInstanceInternal());
47  }
48 
49  static ThisT* SafeDownCast(vtkObjectBase* o)
50  {
51  if(o &&
53  {
54  return static_cast<ThisT*>(o);
55  }
56 
57  return 0;
58  }
59 
60 protected:
62  {
63  return ThisT::New();
64  }
65 
66  // We don't expose this publicly, because the typename we generate
67  // for our template instantiations isn't human-readable, unlike
68  // "normal" VTK classes.
69  static int IsTypeOf(const char* type)
70  {
72  type) == 0)
73  {
74  return 1;
75  }
76  return BaseT::IsTypeOf(type);
77  }
78 
79  // We don't expose this publicly, because the typename we generate
80  // for our template instantiations isn't human-readable, unlike
81  // "normal" VTK classes.
82  virtual int IsA(const char *type)
83  {
84  return this->IsTypeOf(type);
85  }
86 
88 
89 private:
90  // not implemented:
92  void operator=(const vtkTypeTemplate<ThisT, BaseT>&);
93 
94  static const char* GetClassNameInternalCachedName()
95  {
96  static std::string thisType(typeid(ThisT).name());
97  return thisType.c_str();
98  }
99 
100  virtual const char* GetClassNameInternal() const
101  {
102  return this->GetClassNameInternalCachedName();
103  }
104 };
105 
106 #endif
107 
108 // VTK-HeaderTest-Exclude: vtkTypeTemplate.h
Provides the equivalent of vtkTypeMacro for use with template classes.
ThisT * NewInstance() const
static int IsTypeOf(const char *type)
static ThisT * SafeDownCast(vtkObjectBase *o)
virtual vtkObjectBase * NewInstanceInternal() const
virtual int IsA(const char *type)
abstract base class for most VTK objects
Definition: vtkObjectBase.h:59
virtual int IsA(const char *name)