Teuchos - Trilinos Tools Package
Version of the Day
Toggle main menu visibility
Loading...
Searching...
No Matches
core
src
Teuchos_Ptr.hpp
1
// @HEADER
2
// *****************************************************************************
3
// Teuchos: Common Tools Package
4
//
5
// Copyright 2004 NTESS and the Teuchos contributors.
6
// SPDX-License-Identifier: BSD-3-Clause
7
// *****************************************************************************
8
// @HEADER
9
10
#ifndef TEUCHOS_PTR_HPP
11
#define TEUCHOS_PTR_HPP
12
13
14
#include "Teuchos_PtrDecl.hpp"
15
#include "
Teuchos_RCP.hpp
"
16
17
18
namespace
Teuchos
{
19
20
21
namespace
PtrPrivateUtilityPack {
22
TEUCHOSCORE_LIB_DLL_EXPORT
void
throw_null(
const
std::string &type_name );
23
}
// namespace PtrPrivateUtilityPack
24
25
26
template
<
class
T>
inline
27
Ptr<T>::Ptr
( ENull
/*null_in*/
)
28
: ptr_(0)
29
{}
30
31
32
template
<
class
T>
inline
33
Ptr<T>::Ptr
( T *ptr_in )
34
:ptr_(ptr_in)
35
{}
36
37
38
template
<
class
T>
inline
39
Ptr<T>::Ptr
(
const
Ptr<T>
& ptr_in)
40
:ptr_(ptr_in.ptr_)
41
#ifdef TEUCHOS_DEBUG
42
,rcp_(ptr_in.access_rcp())
43
#endif
44
{}
45
46
47
template
<
class
T>
48
template
<
class
T2>
inline
49
Ptr<T>::Ptr
(
const
Ptr<T2>
& ptr_in)
50
:ptr_(ptr_in.
get
())
51
#ifdef TEUCHOS_DEBUG
52
,rcp_(ptr_in.access_rcp())
53
#endif
54
{}
55
56
57
template
<
class
T>
inline
58
Ptr<T>
&
Ptr<T>::operator=
(
const
Ptr<T>
& ptr_in)
59
{
60
ptr_ = ptr_in.
get
();
61
#ifdef TEUCHOS_DEBUG
62
rcp_ = ptr_in.rcp_;
63
#endif
64
return
*
this
;
65
}
66
67
68
template
<
class
T>
inline
69
T*
Ptr<T>::operator->
()
const
70
{
71
debug_assert_not_null();
72
debug_assert_valid_ptr();
73
return
ptr_;
74
}
75
76
77
template
<
class
T>
inline
78
T&
Ptr<T>::operator*
()
const
79
{
80
debug_assert_not_null();
81
debug_assert_valid_ptr();
82
return
*ptr_;
83
}
84
85
86
template
<
class
T>
inline
87
T*
Ptr<T>::get
()
const
88
{
89
debug_assert_valid_ptr();
90
return
ptr_;
91
}
92
93
94
template
<
class
T>
inline
95
T*
Ptr<T>::getRawPtr
()
const
96
{
97
return
get
();
98
}
99
100
101
template
<
class
T>
inline
102
const
Ptr<T>
&
Ptr<T>::assert_not_null
()
const
103
{
104
if
(!ptr_)
105
PtrPrivateUtilityPack::throw_null(
TypeNameTraits<T>::name
());
106
return
*
this
;
107
}
108
109
110
template
<
class
T>
inline
111
bool
Ptr<T>::is_null
()
const
{
112
return
ptr_ == NULL;
113
}
114
115
116
template
<
class
T>
inline
117
const
Ptr<T>
Ptr<T>::ptr
()
const
118
{
119
return
*
this
;
120
}
121
122
123
template
<
class
T>
inline
124
Ptr<const T>
Ptr<T>::getConst
()
const
125
{
126
return
ptr_implicit_cast<const T>
(*
this
);
127
}
128
129
130
template
<
class
T>
inline
131
void
Ptr<T>::debug_assert_valid_ptr()
const
132
{
133
#ifdef TEUCHOS_DEBUG
134
rcp_.access_private_node().assert_valid_ptr(*
this
);
135
#endif
136
}
137
138
139
#ifdef TEUCHOS_DEBUG
140
141
142
template
<
class
T>
inline
143
Ptr<T>::Ptr
(
const
RCP<T>
&p )
144
: ptr_(p.
getRawPtr
()), rcp_(p)
145
{}
146
147
148
#endif
// TEUCHOS_DEBUG
149
150
151
}
// namespace Teuchos
152
153
154
template
<
class
T>
155
std::ostream& Teuchos::operator<<( std::ostream& out,
const
Ptr<T>
& p )
156
{
157
out
158
<<
TypeNameTraits<RCP<T>
>::name() <<
"{"
159
<<
"ptr="
<<(
const
void
*)(p.
get
())
// I can't find any alternative to this C cast :-(
160
<<
"}"
;
161
return
out;
162
}
163
164
165
#endif
// TEUCHOS_PTR_HPP
Teuchos_RCP.hpp
Reference-counted pointer class and non-member templated function implementations.
Teuchos::ParameterList::get
T & get(ParameterList &l, const std::string &name)
A shorter name for getParameter().
Definition
Teuchos_ParameterList.hpp:1308
Teuchos::Ptr::ptr_implicit_cast
Ptr< T2 > ptr_implicit_cast(const Ptr< T1 > &p1)
Implicit cast of underlying Ptr type from T1* to T2*.
Definition
Teuchos_PtrDecl.hpp:396
Teuchos::Ptr::assert_not_null
const Ptr< T > & assert_not_null() const
Throws std::logic_error if this->get()==NULL, otherwise returns reference to *this.
Definition
Teuchos_Ptr.hpp:102
Teuchos::Ptr::getConst
Ptr< const T > getConst() const
Return a Ptr<const T> version of *this.
Definition
Teuchos_Ptr.hpp:124
Teuchos::Ptr::getRawPtr
T * getRawPtr() const
Get the raw C++ pointer to the underlying object.
Definition
Teuchos_Ptr.hpp:95
Teuchos::Ptr::operator=
Ptr< T > & operator=(const Ptr< T > &ptr)
Shallow copy of the underlying pointer.
Definition
Teuchos_Ptr.hpp:58
Teuchos::Ptr::is_null
bool is_null() const
Return true if the wrapped raw pointer is NULL, else return false.
Definition
Teuchos_Ptr.hpp:111
Teuchos::Ptr::operator->
T * operator->() const
Pointer (->) access to members of underlying object.
Definition
Teuchos_Ptr.hpp:69
Teuchos::Ptr::operator*
T & operator*() const
Dereference the underlying object.
Definition
Teuchos_Ptr.hpp:78
Teuchos::Ptr::get
T * get() const
Get the raw C++ pointer to the underlying object.
Definition
Teuchos_Ptr.hpp:87
Teuchos::Ptr::ptr
const Ptr< T > ptr() const
Return a copy of *this.
Definition
Teuchos_Ptr.hpp:117
Teuchos::Ptr::Ptr
Ptr(ENull null_in=null)
Default construct to NULL.
Definition
Teuchos_Ptr.hpp:27
Teuchos::RCP
Smart reference counting pointer class for automatic garbage collection.
Definition
Teuchos_RCPDecl.hpp:397
Teuchos::TypeNameTraits
Default traits class that just returns typeid(T).name().
Definition
Teuchos_TypeNameTraits.hpp:53
Teuchos::TypeNameTraits::name
static std::string name()
Definition
Teuchos_TypeNameTraits.hpp:56
Teuchos
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...
Generated by
1.17.0