Teuchos Package Browser (Single Doxygen Collection)
Version of the Day
Toggle main menu visibility
Loading...
Searching...
No Matches
remainder
src
Teuchos_Handle.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
#ifndef TEUCHOS_HANDLE_HPP
43
#define TEUCHOS_HANDLE_HPP
44
45
#include "
Teuchos_ConfigDefs.hpp
"
46
#include "
Teuchos_RCP.hpp
"
47
#include "
Teuchos_Describable.hpp
"
48
#include "
Teuchos_Handleable.hpp
"
49
50
namespace
Teuchos
51
{
52
78
template
<
typename
Po
int
erType>
79
class
ConstHandle
:
public
virtual
Describable
80
{
81
public
:
83
ConstHandle
(
const
RCP<const PointerType>
&
ptr
) :
ptr_
(
ptr
) {;}
86
explicit
ConstHandle
(
const
ConstHandleable<PointerType>
*
ptr
) :
ptr_
(
ptr
->getConstRcp()) {;}
88
const
RCP<const PointerType>
&
constPtr
()
const
{
return
ptr_
;}
90
const
PointerType *
const
rawPtr
() {
return
this->
constPtr
().
get
();}
91
protected
:
93
explicit
ConstHandle
() :
ptr_
() {;}
98
void
setRcp
(
const
RCP<PointerType>
&
ptr
)
99
{
ptr_
=
rcp_const_cast<const PointerType>
(
ptr
);}
100
104
RCP<PointerType>
nonConstPtr
()
const
105
{
return
rcp_const_cast<PointerType>
(
ptr_
);}
106
private
:
108
RCP<const PointerType>
ptr_
;
109
};
110
134
template
<
typename
Po
int
erType>
135
class
Handle
:
public
virtual
ConstHandle
<PointerType>
136
{
137
public
:
139
Handle
()
140
:
ConstHandle
<PointerType>() {}
141
142
Handle
(
const
RCP<PointerType>
& smartPtr)
143
:
ConstHandle
<PointerType>()
144
{
145
/* \brief We need to set the rcp in the base class */
146
setRcp
(smartPtr);
147
}
148
153
explicit
Handle
(
Handleable<PointerType>
*
rawPtr
)
154
:
ConstHandle
<PointerType>()
155
{
156
/* \brief We need to set the rcp in the base class. */
157
setRcp
(
rawPtr
->getRcp());
158
}
159
161
RCP<PointerType>
ptr
()
const
{
return
this->
nonConstPtr
();}
163
PointerType*
rawPtr
()
const
{
return
this->
nonConstPtr
().get();}
164
};
165
166
}
// namespace Teuchos
167
179
#define TEUCHOS_HANDLE_CTORS(handle, contents) \
180
handle() : Teuchos::Handle<contents >() {;} \
181
handle(Teuchos::Handleable<contents >* rawPtr) : Teuchos::Handle<contents >(rawPtr) {;} \
182
handle(const Teuchos::RCP<contents >& smartPtr) : Teuchos::Handle<contents >(smartPtr){;}
183
195
#define TEUCHOS_CONST_HANDLE_CTORS(handle, contents) \
196
handle( Teuchos::ENull _null = Teuchos::null ) : Teuchos::ConstHandle<contents >() {;} \
197
handle(const Teuchos::ConstHandleable<contents >* rawPtr) : Teuchos::ConstHandle<contents >(rawPtr) {;} \
198
handle(const Teuchos::RCP<const contents >& smartPtr) : Teuchos::ConstHandle<contents >(smartPtr){;}
199
200
#endif
// TEUCHOS_CONSTHANDLE_HPP
Teuchos_ConfigDefs.hpp
Teuchos header file which uses auto-configuration information to include necessary C++ headers.
Teuchos_Describable.hpp
Teuchos_Handleable.hpp
Teuchos_RCP.hpp
Reference-counted pointer class and non-member templated function implementations.
EvilPack::RCP::get
T * get() const
Get the raw C++ pointer to the underlying object.
Definition
Teuchos_RCP.hpp:397
Teuchos::ConstHandle::setRcp
void setRcp(const RCP< PointerType > &ptr)
This function is needed in Handle ctors.
Definition
Teuchos_Handle.hpp:98
Teuchos::ConstHandle::ConstHandle
ConstHandle(const ConstHandleable< PointerType > *ptr)
Construct with a raw pointer to a ConstHandleable. This will make a call to rcp(),...
Definition
Teuchos_Handle.hpp:86
Teuchos::ConstHandle::rawPtr
const PointerType *const rawPtr()
Access to raw pointer.
Definition
Teuchos_Handle.hpp:90
Teuchos::ConstHandle::nonConstPtr
RCP< PointerType > nonConstPtr() const
Protected non-const access to the underlying smart pointer.
Definition
Teuchos_Handle.hpp:104
Teuchos::ConstHandle::ptr_
RCP< const PointerType > ptr_
Definition
Teuchos_Handle.hpp:108
Teuchos::ConstHandle::constPtr
const RCP< const PointerType > & constPtr() const
Read-only access to the underlying smart pointer.
Definition
Teuchos_Handle.hpp:88
Teuchos::ConstHandle::ConstHandle
ConstHandle(const RCP< const PointerType > &ptr)
Construct with an existing RCP.
Definition
Teuchos_Handle.hpp:83
Teuchos::ConstHandle::ConstHandle
ConstHandle()
The empty ctor will only be called by Handle ctors.
Definition
Teuchos_Handle.hpp:93
Teuchos::ConstHandleable
Class ConstHandleable provides an abstract interface for polymorphic conversion from raw pointers to ...
Definition
Teuchos_Handleable.hpp:67
Teuchos::Describable
Base class for all objects that can describe themselves.
Definition
Teuchos_Describable.hpp:76
Teuchos::Handle::Handle
Handle()
Definition
Teuchos_Handle.hpp:139
Teuchos::Handle::ptr
RCP< PointerType > ptr() const
Read/write access to the underlying smart pointer.
Definition
Teuchos_Handle.hpp:161
Teuchos::Handle::Handle
Handle(const RCP< PointerType > &smartPtr)
Construct with an existing RCP.
Definition
Teuchos_Handle.hpp:142
Teuchos::Handle::rawPtr
PointerType * rawPtr() const
Access to non-const raw pointer.
Definition
Teuchos_Handle.hpp:163
Teuchos::Handle::Handle
Handle(Handleable< PointerType > *rawPtr)
Construct with a raw pointer to a Handleable.
Definition
Teuchos_Handle.hpp:153
Teuchos::Handleable
Class Handleable provides an abstract interface for polymorphic conversion from raw pointers to smart...
Definition
Teuchos_Handleable.hpp:93
Teuchos::Ptr::ptr
Ptr< T > ptr(T *p)
Create a pointer to an object from a raw pointer.
Definition
Teuchos_PtrDecl.hpp:329
Teuchos::RCP
Smart reference counting pointer class for automatic garbage collection.
Definition
Teuchos_RCPDecl.hpp:429
Teuchos::RCP::rcp_const_cast
RCP< T2 > rcp_const_cast(const RCP< T1 > &p1)
Constant cast of underlying RCP type from T1* to T2*.
Teuchos
Definition
Teuchos_AbstractFactory.hpp:47
Generated by
1.17.0