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
vtkTypeTemplate::IsTypeOf
static vtkTypeBool IsTypeOf(const char *type)
Definition: vtkTypeTemplate.h:73
vtkTypeTemplate::Superclass
BaseT Superclass
Definition: vtkTypeTemplate.h:46
vtkX3D::type
Definition: vtkX3D.h:516
vtkTypeTemplate::vtkTypeTemplate
vtkTypeTemplate()
Definition: vtkTypeTemplate.h:91
vtkTypeTemplate::NewInstanceInternal
virtual vtkObjectBase * NewInstanceInternal() const
Definition: vtkTypeTemplate.h:65
vtkTypeTemplate::NewInstance
ThisT * NewInstance() const
Definition: vtkTypeTemplate.h:48
vtkTypeTemplate::SafeDownCast
static ThisT * SafeDownCast(vtkObjectBase *o)
Definition: vtkTypeTemplate.h:53
vtkObjectBase
abstract base class for most VTK objects
Definition: vtkObjectBase.h:65
vtkX3D::name
Definition: vtkX3D.h:219
vtkObject.h
vtkX3D::string
Definition: vtkX3D.h:490
vtkTypeTemplate::IsA
vtkTypeBool IsA(const char *type) override
Definition: vtkTypeTemplate.h:86
vtkTypeBool
int vtkTypeBool
Definition: vtkABI.h:69
vtkObjectBase::IsA
virtual vtkTypeBool IsA(const char *name)
Return 1 if this class is the same type of (or a subclass of) the named class.
vtkTypeTemplate
Provides the equivalent of vtkTypeMacro for use with template classes.
Definition: vtkTypeTemplate.h:43