Sacado Package Browser (Single Doxygen Collection)
Version of the Day
Toggle main menu visibility
Loading...
Searching...
No Matches
src
Sacado_Handle.hpp
Go to the documentation of this file.
1
// $Id$
2
// $Source$
3
// @HEADER
4
// ***********************************************************************
5
//
6
// Sacado Package
7
// Copyright (2006) Sandia Corporation
8
//
9
// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
10
// license for use of this work by or on behalf of the U.S. Government.
11
//
12
// This library is free software; you can redistribute it and/or modify
13
// it under the terms of the GNU Lesser General Public License as
14
// published by the Free Software Foundation; either version 2.1 of the
15
// License, or (at your option) any later version.
16
//
17
// This library is distributed in the hope that it will be useful, but
18
// WITHOUT ANY WARRANTY; without even the implied warranty of
19
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20
// Lesser General Public License for more details.
21
//
22
// You should have received a copy of the GNU Lesser General Public
23
// License along with this library; if not, write to the Free Software
24
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
25
// USA
26
// Questions? Contact David M. Gay (dmgay@sandia.gov) or Eric T. Phipps
27
// (etphipp@sandia.gov).
28
//
29
// ***********************************************************************
30
// @HEADER
31
32
#ifndef SACADO_HANDLE_HPP
33
#define SACADO_HANDLE_HPP
34
35
namespace
Sacado
{
36
40
template
<
typename
T>
41
class
Handle
{
42
public
:
43
45
Handle
(
T
* p) :
rep
(p),
count
(new int(1)) {}
46
48
Handle
(
const
Handle
& h) :
rep
(h.
rep
),
count
(h.
count
) { (*count)++; }
49
51
~Handle
() {
decrementRef
(); }
52
54
T
*
get
() {
return
rep
; }
55
57
const
T
*
get
()
const
{
return
rep
; }
58
60
void
Assign
(
const
Handle
& h) {
61
decrementRef
();
62
rep
=
new
T
(*(h.
rep
));
63
count
=
new
int(1);
64
}
65
67
void
makeOwnCopy
() {
68
T
*tmp;
69
if
(*
count
> 1) {
70
tmp =
rep
;
71
(*count)--;
72
rep
=
new
T
(*tmp);
73
count
=
new
int(1);
74
}
75
}
76
78
Handle
&
operator =
(
const
Handle
& h) {
79
if
(
this
!= &h) {
80
decrementRef
();
81
rep
= h.
rep
;
82
count
= h.
count
;
83
(*count)++;
84
}
85
return
*
this
;
86
}
87
89
T
*
operator ->
()
const
{
return
rep
; }
90
92
const
T
&
operator *
()
const
{
return
*
rep
; }
93
95
T
&
operator *
() {
return
*
rep
; }
96
97
private
:
98
100
T
*
rep
;
101
103
int
*
count
;
104
106
void
decrementRef
() {
107
(*count)--;
108
if
(*
count
== 0) {
109
delete
rep
;
110
delete
count
;
111
}
112
}
113
114
};
// class Handle
115
117
template
<
typename
T>
118
bool
operator==
(
const
Handle<T>
& h1,
const
Handle<T>
& h2) {
119
return
h1.
get
() == h2.
get
();
120
}
121
122
}
// namespace Sacado
123
124
#endif
// SACADO_HANDLE_HPP
T
#define T
Definition
Sacado_rad.hpp:573
Sacado::Handle
A generic handle class.
Definition
Sacado_Handle.hpp:41
Sacado::Handle::rep
T * rep
Pointer to data.
Definition
Sacado_Handle.hpp:100
Sacado::Handle::operator*
const T & operator*() const
Dereference.
Definition
Sacado_Handle.hpp:92
Sacado::Handle::operator->
T * operator->() const
Dereference.
Definition
Sacado_Handle.hpp:89
Sacado::Handle::count
int * count
Reference count.
Definition
Sacado_Handle.hpp:103
Sacado::Handle::Assign
void Assign(const Handle &h)
Assign to handle h as its own copy.
Definition
Sacado_Handle.hpp:60
Sacado::Handle::Handle
Handle(T *p)
Create new handle from pointer p.
Definition
Sacado_Handle.hpp:45
Sacado::Handle::get
const T * get() const
Return pointer to underlying data.
Definition
Sacado_Handle.hpp:57
Sacado::Handle::Handle
Handle(const Handle &h)
Copy handle.
Definition
Sacado_Handle.hpp:48
Sacado::Handle::makeOwnCopy
void makeOwnCopy()
Make handle have its own copy of rep.
Definition
Sacado_Handle.hpp:67
Sacado::Handle::get
T * get()
Return pointer to underlying data.
Definition
Sacado_Handle.hpp:54
Sacado::Handle::operator=
Handle & operator=(const Handle &h)
Assignment operator.
Definition
Sacado_Handle.hpp:78
Sacado::Handle::decrementRef
void decrementRef()
Decrement reference.
Definition
Sacado_Handle.hpp:106
Sacado::Handle::~Handle
~Handle()
Destroy handle.
Definition
Sacado_Handle.hpp:51
Sacado
Definition
Sacado_mpl_apply.hpp:39
Sacado::operator==
bool operator==(const Handle< T > &h1, const Handle< T > &h2)
Compare two handles.
Definition
Sacado_Handle.hpp:118
Generated by
1.17.0