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
=========================================================================*/
59
#ifndef vtkNew_h
60
#define vtkNew_h
61
62
#include "
vtkIOStream.h
"
63
64
class
vtkObjectBase
;
65
66
template
<
class
T>
67
class
vtkNew
68
{
72
void
CheckObjectBase(
vtkObjectBase
*) {}
73
public
:
77
vtkNew
() : Object(T::New())
78
{
79
this->CheckObjectBase(this->Object);
80
}
81
83
86
~vtkNew
()
87
{
88
T* obj = this->Object;
89
if
(obj)
90
{
91
this->Object = 0;
92
obj->Delete();
93
}
94
}
96
101
T*
operator->
()
const
102
{
103
return
this->Object;
104
}
105
107
113
T*
GetPointer
()
const
114
{
115
return
this->Object;
116
}
117
T*
Get
()
const
118
{
119
return
this->Object;
120
}
122
123
private
:
124
vtkNew
(
vtkNew<T>
const
&) VTK_DELETE_FUNCTION;
125
void
operator=(
vtkNew<T>
const
&) VTK_DELETE_FUNCTION;
126
T* Object;
127
};
128
132
template
<
class
T>
133
inline
ostream&
operator <<
(ostream& os,
const
vtkNew<T>
& p)
134
{
135
return
os << p.
GetPointer
();
136
}
137
138
#endif
139
// VTK-HeaderTest-Exclude: vtkNew.h
operator<<
ostream & operator<<(ostream &os, const vtkNew< T > &p)
Streaming operator to print vtkNew like regular pointers.
Definition:
vtkNew.h:133
vtkNew::operator->
T * operator->() const
Enable pointer-like dereference syntax.
Definition:
vtkNew.h:101
vtkObjectBase
abstract base class for most VTK objects
Definition:
vtkObjectBase.h:66
vtkNew::~vtkNew
~vtkNew()
Deletes reference to instance of T on destruction.
Definition:
vtkNew.h:86
vtkNew
Allocate and hold a VTK object.
Definition:
vtkNew.h:68
vtkNew::GetPointer
T * GetPointer() const
Get a raw pointer to the contained object.
Definition:
vtkNew.h:113
vtkNew::vtkNew
vtkNew()
Create a new T on construction.
Definition:
vtkNew.h:77
vtkIOStream.h
vtkNew::Get
T * Get() const
Definition:
vtkNew.h:117
Generated by
1.8.20