Teuchos Package Browser (Single Doxygen Collection)
Version of the Day
Toggle main menu visibility
Loading...
Searching...
No Matches
core
src
Teuchos_Ptr.hpp
Go to the documentation of this file.
1
// @HEADER
2
// ***********************************************************************
3
//
4
// Teuchos: Common Tools Package
5
// Copyright (2004) Sandia Corporation
6
//
7
// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8
// license for use of this work by or on behalf of the U.S. Government.
9
//
10
// Redistribution and use in source and binary forms, with or without
11
// modification, are permitted provided that the following conditions are
12
// met:
13
//
14
// 1. Redistributions of source code must retain the above copyright
15
// notice, this list of conditions and the following disclaimer.
16
//
17
// 2. Redistributions in binary form must reproduce the above copyright
18
// notice, this list of conditions and the following disclaimer in the
19
// documentation and/or other materials provided with the distribution.
20
//
21
// 3. Neither the name of the Corporation nor the names of the
22
// contributors may be used to endorse or promote products derived from
23
// this software without specific prior written permission.
24
//
25
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36
//
37
// Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38
//
39
// ***********************************************************************
40
// @HEADER
41
42
43
#ifndef TEUCHOS_PTR_HPP
44
#define TEUCHOS_PTR_HPP
45
46
47
#include "
Teuchos_PtrDecl.hpp
"
48
#include "
Teuchos_RCP.hpp
"
49
50
51
namespace
Teuchos
{
52
53
54
namespace
PtrPrivateUtilityPack
{
55
TEUCHOSCORE_LIB_DLL_EXPORT
void
throw_null
(
const
std::string &type_name );
56
}
// namespace PtrPrivateUtilityPack
57
58
59
template
<
class
T>
inline
60
Ptr<T>::Ptr
( ENull
/*null_in*/
)
61
:
ptr_
(0)
62
{}
63
64
65
template
<
class
T>
inline
66
Ptr<T>::Ptr
( T *ptr_in )
67
:
ptr_
(ptr_in)
68
{}
69
70
71
template
<
class
T>
inline
72
Ptr<T>::Ptr
(
const
Ptr<T>
& ptr_in)
73
:
ptr_
(ptr_in.
ptr_
)
74
#ifdef TEUCHOS_DEBUG
75
,rcp_(ptr_in.access_rcp())
76
#endif
77
{}
78
79
80
template
<
class
T>
81
template
<
class
T2>
inline
82
Ptr<T>::Ptr
(
const
Ptr<T2>
& ptr_in)
83
:
ptr_
(ptr_in.
get
())
84
#ifdef TEUCHOS_DEBUG
85
,rcp_(ptr_in.access_rcp())
86
#endif
87
{}
88
89
90
template
<
class
T>
inline
91
Ptr<T>
&
Ptr<T>::operator=
(
const
Ptr<T>
& ptr_in)
92
{
93
ptr_
= ptr_in.
get
();
94
#ifdef TEUCHOS_DEBUG
95
rcp_ = ptr_in.rcp_;
96
#endif
97
return
*
this
;
98
}
99
100
101
template
<
class
T>
inline
102
T*
Ptr<T>::operator->
()
const
103
{
104
debug_assert_not_null
();
105
debug_assert_valid_ptr
();
106
return
ptr_
;
107
}
108
109
110
template
<
class
T>
inline
111
T&
Ptr<T>::operator*
()
const
112
{
113
debug_assert_not_null
();
114
debug_assert_valid_ptr
();
115
return
*
ptr_
;
116
}
117
118
119
template
<
class
T>
inline
120
T*
Ptr<T>::get
()
const
121
{
122
debug_assert_valid_ptr
();
123
return
ptr_
;
124
}
125
126
127
template
<
class
T>
inline
128
T*
Ptr<T>::getRawPtr
()
const
129
{
130
return
get
();
131
}
132
133
134
template
<
class
T>
inline
135
const
Ptr<T>
&
Ptr<T>::assert_not_null
()
const
136
{
137
if
(!
ptr_
)
138
PtrPrivateUtilityPack::throw_null
(
TypeNameTraits<T>::name
());
139
return
*
this
;
140
}
141
142
143
template
<
class
T>
inline
144
bool
Ptr<T>::is_null
()
const
{
145
return
ptr_
== NULL;
146
}
147
148
149
template
<
class
T>
inline
150
const
Ptr<T>
Ptr<T>::ptr
()
const
151
{
152
return
*
this
;
153
}
154
155
156
template
<
class
T>
inline
157
Ptr<const T>
Ptr<T>::getConst
()
const
158
{
159
return
ptr_implicit_cast<const T>
(*
this
);
160
}
161
162
163
template
<
class
T>
inline
164
void
Ptr<T>::debug_assert_valid_ptr
()
const
165
{
166
#ifdef TEUCHOS_DEBUG
167
rcp_.access_private_node().assert_valid_ptr(*
this
);
168
#endif
169
}
170
171
172
#ifdef TEUCHOS_DEBUG
173
174
175
template
<
class
T>
inline
176
Ptr<T>::Ptr
(
const
RCP<T>
&p )
177
:
ptr_
(p.
getRawPtr
()), rcp_(p)
178
{}
179
180
181
#endif
// TEUCHOS_DEBUG
182
183
184
}
// namespace Teuchos
185
186
187
template
<
class
T>
188
std::ostream&
Teuchos::operator<<
( std::ostream& out,
const
Ptr<T>
& p )
189
{
190
out
191
<<
TypeNameTraits<RCP<T>
>::name() <<
"{"
192
<<
"ptr="
<<(
const
void
*)(p.
get
())
// I can't find any alternative to this C cast :-(
193
<<
"}"
;
194
return
out;
195
}
196
197
198
#endif
// TEUCHOS_PTR_HPP
TEUCHOSCORE_LIB_DLL_EXPORT
#define TEUCHOSCORE_LIB_DLL_EXPORT
Definition
Teuchos_DLLExportMacro.h:9
Teuchos_PtrDecl.hpp
Teuchos_RCP.hpp
Reference-counted pointer class and non-member templated function implementations.
Teuchos::Ptr< const Teuchos::Comm< int > >::debug_assert_not_null
void debug_assert_not_null() const
Definition
Teuchos_PtrDecl.hpp:198
Teuchos::Ptr< const Teuchos::Comm< int > >::getRawPtr
const Teuchos::Comm< int > * getRawPtr() const
Definition
Teuchos_Ptr.hpp:128
Teuchos::Ptr< const Teuchos::Comm< int > >::ptr_
const Teuchos::Comm< int > * ptr_
Definition
Teuchos_PtrDecl.hpp:192
Teuchos::Ptr< const Teuchos::Comm< int > >::debug_assert_valid_ptr
void debug_assert_valid_ptr() const
Definition
Teuchos_Ptr.hpp:164
Teuchos::Ptr< const Teuchos::Comm< int > >::Ptr
Ptr(ENull null_in=null)
Definition
Teuchos_Ptr.hpp:60
Teuchos::ParameterList::get
T & get(ParameterList &l, const std::string &name)
A shorter name for getParameter().
Definition
Teuchos_ParameterList.hpp:1320
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:429
Teuchos::Ptr::debug_assert_not_null
void debug_assert_not_null() const
Definition
Teuchos_PtrDecl.hpp:198
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:135
Teuchos::Ptr::getConst
Ptr< const T > getConst() const
Return a Ptr<const T> version of *this.
Definition
Teuchos_Ptr.hpp:157
Teuchos::Ptr::getRawPtr
T * getRawPtr() const
Get the raw C++ pointer to the underlying object.
Definition
Teuchos_Ptr.hpp:128
Teuchos::Ptr::operator=
Ptr< T > & operator=(const Ptr< T > &ptr)
Shallow copy of the underlying pointer.
Definition
Teuchos_Ptr.hpp:91
Teuchos::Ptr::ptr_
T * ptr_
Definition
Teuchos_PtrDecl.hpp:192
Teuchos::Ptr::debug_assert_valid_ptr
void debug_assert_valid_ptr() const
Definition
Teuchos_Ptr.hpp:164
Teuchos::Ptr::is_null
bool is_null() const
Return true if the wrapped raw pointer is NULL, else return false.
Definition
Teuchos_Ptr.hpp:144
Teuchos::Ptr::operator->
T * operator->() const
Pointer (->) access to members of underlying object.
Definition
Teuchos_Ptr.hpp:102
Teuchos::Ptr::operator*
T & operator*() const
Dereference the underlying object.
Definition
Teuchos_Ptr.hpp:111
Teuchos::Ptr::get
T * get() const
Get the raw C++ pointer to the underlying object.
Definition
Teuchos_Ptr.hpp:120
Teuchos::Ptr::ptr
const Ptr< T > ptr() const
Return a copy of *this.
Definition
Teuchos_Ptr.hpp:150
Teuchos::Ptr::Ptr
Ptr(ENull null_in=null)
Default construct to NULL.
Definition
Teuchos_Ptr.hpp:60
Teuchos::RCP
Smart reference counting pointer class for automatic garbage collection.
Definition
Teuchos_RCPDecl.hpp:429
Teuchos::TypeNameTraits
Default traits class that just returns typeid(T).name().
Definition
Teuchos_TypeNameTraits.hpp:85
Teuchos::TypeNameTraits::name
static std::string name()
Definition
Teuchos_TypeNameTraits.hpp:88
Teuchos::PtrPrivateUtilityPack
Definition
Teuchos_Ptr.hpp:54
Teuchos::PtrPrivateUtilityPack::throw_null
TEUCHOSCORE_LIB_DLL_EXPORT void throw_null(const std::string &type_name)
Definition
Teuchos_Ptr.cpp:48
Teuchos
Definition
Teuchos_AbstractFactory.hpp:47
Teuchos::operator<<
std::ostream & operator<<(std::ostream &os, BigUInt< n > a)
Definition
Teuchos_BigUInt.hpp:188
Generated by
1.17.0