VTK
dox
Common
Core
vtkNew.h
Go to the documentation of this file.
1
/*=========================================================================
2
3
Program: Visualization Toolkit
4
Module: vtkNew.h
5
6
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7
All rights reserved.
8
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10
This software is distributed WITHOUT ANY WARRANTY; without even
11
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12
PURPOSE. See the above copyright notice for more information.
13
14
=========================================================================*/
50
#ifndef vtkNew_h
51
#define vtkNew_h
52
53
#include "
vtkIOStream.h
"
54
55
class
vtkObjectBase
;
56
57
template
<
class
T>
58
class
vtkNew
59
{
63
void
CheckObjectBase(
vtkObjectBase
*) {}
64
public
:
68
vtkNew
() : Object(T::New())
69
{
70
this->CheckObjectBase(this->Object);
71
}
72
74
77
~vtkNew
()
78
{
79
T* obj = this->Object;
80
if
(obj)
81
{
82
this->Object =
nullptr
;
83
obj->Delete();
84
}
85
}
87
92
T*
operator->
()
const
93
{
94
return
this->Object;
95
}
96
98
104
T*
GetPointer
()
const
105
{
106
return
this->Object;
107
}
108
T*
Get
()
const
109
{
110
return
this->Object;
111
}
112
operator
T* ()
const
113
{
114
return
static_cast<T*>(this->Object);
115
}
117
123
T&
operator*
()
const
124
{
125
return
*static_cast<T*>(this->Object);
126
}
127
128
private
:
129
vtkNew
(
vtkNew<T>
const
&) =
delete
;
130
void
operator=(
vtkNew<T>
const
&) =
delete
;
131
T* Object;
132
};
133
134
#endif
135
// VTK-HeaderTest-Exclude: vtkNew.h
vtkNew::operator->
T * operator->() const
Enable pointer-like dereference syntax.
Definition:
vtkNew.h:92
vtkNew::operator*
T & operator*() const
Dereference the pointer and return a reference to the contained object.
Definition:
vtkNew.h:123
vtkObjectBase
abstract base class for most VTK objects
Definition:
vtkObjectBase.h:65
vtkNew::~vtkNew
~vtkNew()
Deletes reference to instance of T on destruction.
Definition:
vtkNew.h:77
vtkNew
Allocate and hold a VTK object.
Definition:
vtkNew.h:58
vtkNew::GetPointer
T * GetPointer() const
Get a raw pointer to the contained object.
Definition:
vtkNew.h:104
vtkNew::vtkNew
vtkNew()
Create a new T on construction.
Definition:
vtkNew.h:68
vtkIOStream.h
vtkNew::Get
T * Get() const
Definition:
vtkNew.h:108
Generated by
1.8.16