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 
31 #ifndef vtkTypeTemplate_h
32 #define vtkTypeTemplate_h
33 
34 #include "vtkObject.h"
35 #include <string>
36 #include <typeinfo>
37 
38 // This class is legacy. See vtkTemplateTypeMacro in vtkSetGet.h for the
39 // replacement.
40 #ifndef VTK_LEGACY_REMOVE
41 
42 template<class ThisT, class BaseT>
43 class vtkTypeTemplate : public BaseT
44 {
45 public:
46  typedef BaseT Superclass;
47 
48  ThisT* NewInstance() const
49  {
50  return ThisT::SafeDownCast(this->NewInstanceInternal());
51  }
52 
53  static ThisT* SafeDownCast(vtkObjectBase* o)
54  {
55  if(o &&
57  {
58  return static_cast<ThisT*>(o);
59  }
60 
61  return 0;
62  }
63 
64 protected:
66  {
67  return ThisT::New();
68  }
69 
70  // We don't expose this publicly, because the typename we generate
71  // for our template instantiations isn't human-readable, unlike
72  // "normal" VTK classes.
73  static vtkTypeBool IsTypeOf(const char* type)
74  {
76  type) == 0)
77  {
78  return 1;
79  }
80  return BaseT::IsTypeOf(type);
81  }
82 
83  // We don't expose this publicly, because the typename we generate
84  // for our template instantiations isn't human-readable, unlike
85  // "normal" VTK classes.
86  vtkTypeBool IsA(const char *type) VTK_OVERRIDE
87  {
88  return this->IsTypeOf(type);
89  }
90 
92  {
93  VTK_LEGACY_REPLACED_BODY(vtkTypeTemplate, "VTK 7.1",
94  vtkTemplateTypeMacro (vtkSetGet.h));
95  }
96 
97 private:
98  vtkTypeTemplate(const vtkTypeTemplate<ThisT, BaseT>&) VTK_DELETE_FUNCTION;
99  void operator=(const vtkTypeTemplate<ThisT, BaseT>&) VTK_DELETE_FUNCTION;
100 
101  static const char* GetClassNameInternalCachedName()
102  {
103  static std::string thisType(typeid(ThisT).name());
104  return thisType.c_str();
105  }
106 
107  const char* GetClassNameInternal() const VTK_OVERRIDE
108  {
109  return this->GetClassNameInternalCachedName();
110  }
111 };
112 
113 #endif // VTK_LEGACY_REMOVE
114 #endif // header guard
115 
116 // VTK-HeaderTest-Exclude: vtkTypeTemplate.h
Provides the equivalent of vtkTypeMacro for use with template classes.
ThisT * NewInstance() const
vtkTypeBool IsA(const char *type) override
static vtkTypeBool IsTypeOf(const char *type)
static ThisT * SafeDownCast(vtkObjectBase *o)
int vtkTypeBool
Definition: vtkABI.h:69
virtual vtkObjectBase * NewInstanceInternal() const
abstract base class for most VTK objects
Definition: vtkObjectBase.h:65
virtual vtkTypeBool IsA(const char *name)
Return 1 if this class is the same type of (or a subclass of) the named class.