Teuchos Package Browser (Single Doxygen Collection)
Version of the Day
Toggle main menu visibility
Loading...
Searching...
No Matches
core
test
MemoryManagement
TestClasses.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_TEST_CLASSES_HPP
43
#define TEUCHOS_TEST_CLASSES_HPP
44
45
46
#include "
Teuchos_RCP.hpp
"
47
48
49
// Return constants from class functions
50
const
int
A_g_return
= 1;
51
const
int
A_f_return
= 2;
52
const
int
B1_g_return
= 3;
53
const
int
B1_f_return
= 4;
54
const
int
B2_g_return
= 5;
55
const
int
B2_f_return
= 6;
56
const
int
C_g_return
= 7;
57
const
int
C_f_return
= 8;
58
const
int
D_g_return
= 9;
59
const
int
D_f_return
= 10;
60
const
int
E_g_return
= 11;
61
const
int
E_f_return
= 12;
62
63
64
/*
65
66
Polymorphic multiple inheritance example
67
68
-----
69
| A |
70
-----
71
/|\
72
|
73
------------
74
| |
75
----- ------
76
| B1 | | B2 |
77
----- ------
78
/|\ /|\
79
| |
80
------------
81
|
82
-----
83
| C |
84
-----
85
86
*/
87
88
89
class
C
;
90
91
92
class
A
{
93
int
A_g_
,
A_f_
;
94
public
:
95
A
() :
A_g_
(
A_g_return
),
A_f_
(
A_f_return
) {}
96
A
(
const
int
A_g
,
const
int
A_f
) :
A_g_
(
A_g
),
A_f_
(
A_f
) {}
97
static
Teuchos::RCP<A>
create
() {
return
Teuchos::rcp
(
new
A
); }
98
virtual
~A
()
TEUCHOS_NOEXCEPT_FALSE
;
// See below
99
virtual
int
A_g
() {
return
A_g_
; }
100
virtual
int
A_f
()
const
{
return
A_f_
; }
101
int
call_C_f();
102
private
:
103
Teuchos::RCP<C>
c_
;
104
public
:
105
void
set_C
(
const
Teuchos::RCP<C>
&c ) {
c_
= c; }
106
};
107
108
109
class
B1
:
virtual
public
A
{
110
int
B1_g_
,
B1_f_
;
111
public
:
112
B1
() :
B1_g_
(
B1_g_return
),
B1_f_
(
B1_f_return
) {}
113
~B1
() {
B1_g_
= -1;
B1_f_
= -1; }
114
static
Teuchos::RCP<B1>
create
() {
return
Teuchos::rcp
(
new
B1
); }
115
virtual
int
B1_g
() {
return
B1_g_
; }
116
virtual
int
B1_f
()
const
{
return
B1_f_
; }
117
};
118
119
120
class
B2
:
virtual
public
A
{
121
int
B2_g_
,
B2_f_
;
122
public
:
123
B2
() :
B2_g_
(
B2_g_return
),
B2_f_
(
B2_f_return
) {}
124
static
Teuchos::RCP<B2>
create
() {
return
Teuchos::rcp
(
new
B2
); }
125
~B2
() {
B2_g_
= -1;
B2_f_
= -1; }
126
virtual
int
B2_g
() {
return
B2_g_
; }
127
virtual
int
B2_f
()
const
{
return
B2_f_
; }
128
};
129
130
131
class
C
:
virtual
public
B1
,
virtual
public
B2
132
{
133
int
C_g_
,
C_f_
;
134
public
:
135
C
() :
C_g_
(
C_g_return
),
C_f_
(
C_f_return
)
136
{
137
A_g_on_delete_
= -2;
138
}
139
static
Teuchos::RCP<C>
create
() {
return
Teuchos::rcp
(
new
C
); }
140
~C
()
141
{
142
C_g_
= -1;
C_f_
= -1;
143
}
144
virtual
int
C_g
() {
return
C_g_
; }
145
virtual
int
C_f
()
const
{
return
C_f_
; }
146
int
call_A_g
() {
return
a_
->A_g(); }
147
static
int
get_A_g_on_delete
() {
return
A_g_on_delete_
; }
148
private
:
149
Teuchos::RCP<A>
a_
;
150
static
int
A_g_on_delete_
;
151
public
:
152
void
set_A
(
const
Teuchos::RCP<A>
&a ) {
a_
= a; }
153
Teuchos::RCP<A>
get_A
() {
return
a_
; }
154
};
155
156
157
// Need to put these here if we have circular references
158
159
inline
160
A::~A
()
TEUCHOS_NOEXCEPT_FALSE
{
A_g_
= -1;
A_f_
= -1; }
161
162
163
inline
164
int
A::call_C_f
() {
return
c_
->C_f(); }
165
166
167
class
Get_A_f_return
{
168
const
A
*
a_
;
169
int
*
a_f_return_
;
170
Get_A_f_return
();
171
public
:
172
Get_A_f_return
(
const
A
*a,
int
*a_f_return ) :
a_
(a),
a_f_return_
(a_f_return) {}
173
~Get_A_f_return
() { *
a_f_return_
=
a_
->A_f(); }
174
};
175
176
177
void
deallocA
(
A
* ptr);
178
179
180
void
deallocHandleA
(
A
** handle);
181
182
183
/*
184
185
Non-polymophic classes hiearchy examlpe
186
187
-----
188
| D |
189
-----
190
/|\
191
|
192
-----
193
| E |
194
-----
195
196
*/
197
198
199
class
D
200
{
201
int
D_g_
,
D_f_
;
202
public
:
203
D
() :
D_g_
(
D_g_return
),
D_f_
(
D_f_return
) {}
204
int
D_g
() {
return
D_g_
; }
205
int
D_f
()
const
{
return
D_f_
; }
206
};
207
208
209
class
E
:
public
D
210
{
211
int
E_g_
,
E_f_
;
212
public
:
213
E
() :
E_g_
(
E_g_return
),
E_f_
(
E_f_return
) {}
214
int
E_g
() {
return
E_g_
; }
215
int
E_f
()
const
{
return
E_f_
; }
216
};
217
218
219
/*
220
221
Typedef to pointer for undefined struct as an opaque object type without a
222
specialization of TypeNameTraits.
223
224
This simulates what happens with a lot of MPI implementations.
225
226
*/
227
228
struct
UndefinedType
;
// Forward declared but never defined!
229
typedef
UndefinedType
*
Opaque_handle
;
230
const
Opaque_handle
OPAQUE_HANDLE_NULL
= 0;
231
Opaque_handle
createOpaque
();
232
const
int
getOpaqueValue_return
= 5;
233
int
getOpaqueValue
(
Opaque_handle
opaque );
234
void
destroyOpaque
(
Opaque_handle
* opaque );
235
236
237
/*
238
239
Typedef to pointer for an undefiend struct as an opaque object type out a
240
specialization of TypeNameTraits of the actually type.
241
242
This allows it to be stored in an RCP object itself.
243
244
*/
245
246
struct
UndefinedType2
;
// Forward declared but never defined!
247
typedef
UndefinedType2
*
Opaque2_handle
;
248
const
Opaque2_handle
OPAQUE2_HANDLE_NULL
= 0;
249
Opaque2_handle
createOpaque2
();
250
const
int
getOpaque2Value_return
= 8;
251
int
getOpaque2Value
(
Opaque2_handle
opaque );
252
void
destroyOpaque2
(
Opaque2_handle
* opaque );
253
254
255
namespace
Teuchos
{
256
257
258
// Here we define the traits for the underlying type itself.
259
template
<>
260
class
TypeNameTraits
<
UndefinedType2
> {
261
public
:
262
static
std::string
name
() {
return
"UndefinedType2"
; }
263
static
std::string
concreteName
(
const
UndefinedType2
&)
264
{
return
name
(); }
265
};
266
267
268
}
// namespace Teuchos
269
270
271
/*
272
273
Typedef to pointer for an undefiend struct as an opaque object type out a
274
specialization of TypeNameTraits of the actually type.
275
276
This allows handles to the type be used with Array, ArrayRCP, and ArrayView.
277
However, this type can *not* be used with RCP since it does not define a
278
TypeNameTraits specialization for the underlying undefined type.
279
280
This simulates what can happen with MPI implementations.
281
282
*/
283
284
struct
UndefinedType3;
// Forward declared but never defined!
285
typedef
UndefinedType3*
Opaque3_handle
;
286
const
Opaque3_handle
OPAQUE3_HANDLE_NULL
= 0;
287
288
289
namespace
Teuchos
{
290
291
// Here we only define the traits class for the handle type and we don't even
292
// need to worry about what the underlying type is (unless we already have a
293
// speicalization defined for it).
294
template
<>
295
class
TypeNameTraits
<
Opaque3_handle
> {
296
public
:
297
static
std::string
name
() {
return
"Opaque3_handle"
; }
298
static
std::string
concreteName
(
Opaque3_handle
)
299
{
return
name
(); }
300
};
301
302
303
}
// namespace Teuchos
304
305
306
#endif
// TEUCHOS_TEST_CLASSES_HPP
D_g_return
const int D_g_return
Definition
TestClasses.hpp:58
destroyOpaque
void destroyOpaque(Opaque_handle *opaque)
Definition
TestClasses.cpp:83
Opaque2_handle
UndefinedType2 * Opaque2_handle
Definition
TestClasses.hpp:247
Opaque3_handle
UndefinedType3 * Opaque3_handle
Definition
TestClasses.hpp:285
createOpaque
Opaque_handle createOpaque()
Definition
TestClasses.cpp:69
OPAQUE_HANDLE_NULL
const Opaque_handle OPAQUE_HANDLE_NULL
Definition
TestClasses.hpp:230
D_f_return
const int D_f_return
Definition
TestClasses.hpp:59
getOpaqueValue
int getOpaqueValue(Opaque_handle opaque)
Definition
TestClasses.cpp:77
getOpaque2Value_return
const int getOpaque2Value_return
Definition
TestClasses.hpp:250
E_g_return
const int E_g_return
Definition
TestClasses.hpp:60
A_f_return
const int A_f_return
Definition
TestClasses.hpp:51
C_f_return
const int C_f_return
Definition
TestClasses.hpp:57
getOpaqueValue_return
const int getOpaqueValue_return
Definition
TestClasses.hpp:232
deallocA
void deallocA(A *ptr)
Definition
TestClasses.cpp:48
B1_f_return
const int B1_f_return
Definition
TestClasses.hpp:53
OPAQUE3_HANDLE_NULL
const Opaque3_handle OPAQUE3_HANDLE_NULL
Definition
TestClasses.hpp:286
getOpaque2Value
int getOpaque2Value(Opaque2_handle opaque)
Definition
TestClasses.cpp:104
createOpaque2
Opaque2_handle createOpaque2()
Definition
TestClasses.cpp:96
destroyOpaque2
void destroyOpaque2(Opaque2_handle *opaque)
Definition
TestClasses.cpp:110
B2_f_return
const int B2_f_return
Definition
TestClasses.hpp:55
Opaque_handle
UndefinedType * Opaque_handle
Definition
TestClasses.hpp:229
A_g_return
const int A_g_return
Definition
TestClasses.hpp:50
OPAQUE2_HANDLE_NULL
const Opaque2_handle OPAQUE2_HANDLE_NULL
Definition
TestClasses.hpp:248
B2_g_return
const int B2_g_return
Definition
TestClasses.hpp:54
C_g_return
const int C_g_return
Definition
TestClasses.hpp:56
E_f_return
const int E_f_return
Definition
TestClasses.hpp:61
B1_g_return
const int B1_g_return
Definition
TestClasses.hpp:52
deallocHandleA
void deallocHandleA(A **handle)
Definition
TestClasses.cpp:55
TEUCHOS_NOEXCEPT_FALSE
#define TEUCHOS_NOEXCEPT_FALSE
Definition
TeuchosCore_ConfigDefs.hpp:57
Teuchos_RCP.hpp
Reference-counted pointer class and non-member templated function implementations.
A::~A
virtual ~A() TEUCHOS_NOEXCEPT_FALSE
A::c_
Teuchos::RCP< C > c_
Definition
TestClasses.hpp:103
A::A_g
virtual int A_g()
Definition
TestClasses.hpp:99
A::call_C_f
int call_C_f()
Definition
TestClasses.hpp:164
A::A
A()
Definition
TestClasses.hpp:95
A::A_g_
int A_g_
Definition
TestClasses.hpp:93
A::set_C
void set_C(const Teuchos::RCP< C > &c)
Definition
TestClasses.hpp:105
A::A_f
virtual int A_f() const
Definition
TestClasses.hpp:100
A::~A
virtual ~A()
Definition
core/example/RefCountPtr/cxx_main.cpp:50
A::A
A(const int A_g, const int A_f)
Definition
TestClasses.hpp:96
A::A_f_
int A_f_
Definition
TestClasses.hpp:93
A::create
static Teuchos::RCP< A > create()
Definition
TestClasses.hpp:97
B1
Definition
core/example/RefCountPtr/cxx_main.cpp:53
B1::~B1
~B1()
Definition
TestClasses.hpp:113
B1::B1_f
virtual int B1_f() const
Definition
TestClasses.hpp:116
B1::B1_g
virtual int B1_g()
Definition
TestClasses.hpp:115
B1::B1_f_
int B1_f_
Definition
TestClasses.hpp:110
B1::B1_g_
int B1_g_
Definition
TestClasses.hpp:110
B1::create
static Teuchos::RCP< B1 > create()
Definition
TestClasses.hpp:114
B1::B1
B1()
Definition
TestClasses.hpp:112
B2
Definition
core/example/RefCountPtr/cxx_main.cpp:54
B2::B2_f
virtual int B2_f() const
Definition
TestClasses.hpp:127
B2::B2
B2()
Definition
TestClasses.hpp:123
B2::B2_f_
int B2_f_
Definition
TestClasses.hpp:121
B2::~B2
~B2()
Definition
TestClasses.hpp:125
B2::B2_g_
int B2_g_
Definition
TestClasses.hpp:121
B2::B2_g
virtual int B2_g()
Definition
TestClasses.hpp:126
B2::create
static Teuchos::RCP< B2 > create()
Definition
TestClasses.hpp:124
C::C_g_
int C_g_
Definition
TestClasses.hpp:133
C::C
C()
Definition
TestClasses.hpp:135
C::~C
~C()
Definition
TestClasses.hpp:140
C::get_A
Teuchos::RCP< A > get_A()
Definition
TestClasses.hpp:153
C::C_f_
int C_f_
Definition
TestClasses.hpp:133
C::a_
Teuchos::RCP< A > a_
Definition
TestClasses.hpp:149
C::get_A_g_on_delete
static int get_A_g_on_delete()
Definition
TestClasses.hpp:147
C::A_g_on_delete_
static int A_g_on_delete_
Definition
TestClasses.hpp:150
C::set_A
void set_A(const Teuchos::RCP< A > &a)
Definition
TestClasses.hpp:152
C::call_A_g
int call_A_g()
Definition
TestClasses.hpp:146
C::create
static Teuchos::RCP< C > create()
Definition
TestClasses.hpp:139
C::C_g
virtual int C_g()
Definition
TestClasses.hpp:144
C::C_f
virtual int C_f() const
Definition
TestClasses.hpp:145
D::D_g
int D_g()
Definition
TestClasses.hpp:204
D::D_f_
int D_f_
Definition
TestClasses.hpp:201
D::D_g_
int D_g_
Definition
TestClasses.hpp:201
D::D_f
int D_f() const
Definition
TestClasses.hpp:205
D::D
D()
Definition
TestClasses.hpp:203
E::E_f
int E_f() const
Definition
TestClasses.hpp:215
E::E_g_
int E_g_
Definition
TestClasses.hpp:211
E::E
E()
Definition
TestClasses.hpp:213
E::E_f_
int E_f_
Definition
TestClasses.hpp:211
E::E_g
int E_g()
Definition
TestClasses.hpp:214
Get_A_f_return::a_
const A * a_
Definition
TestClasses.hpp:168
Get_A_f_return::a_f_return_
int * a_f_return_
Definition
TestClasses.hpp:169
Get_A_f_return::~Get_A_f_return
~Get_A_f_return()
Definition
TestClasses.hpp:173
Get_A_f_return::Get_A_f_return
Get_A_f_return()
Get_A_f_return::Get_A_f_return
Get_A_f_return(const A *a, int *a_f_return)
Definition
TestClasses.hpp:172
Teuchos::RCP
Smart reference counting pointer class for automatic garbage collection.
Definition
Teuchos_RCPDecl.hpp:429
Teuchos::TypeNameTraits< Opaque3_handle >::concreteName
static std::string concreteName(Opaque3_handle)
Definition
TestClasses.hpp:298
Teuchos::TypeNameTraits< Opaque3_handle >::name
static std::string name()
Definition
TestClasses.hpp:297
Teuchos::TypeNameTraits< UndefinedType2 >::name
static std::string name()
Definition
TestClasses.hpp:262
Teuchos::TypeNameTraits< UndefinedType2 >::concreteName
static std::string concreteName(const UndefinedType2 &)
Definition
TestClasses.hpp:263
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
A
Definition
PackageA.cpp:3
C
Definition
PackageC.cpp:3
Teuchos
Definition
Teuchos_AbstractFactory.hpp:47
Teuchos::rcp
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
Definition
Teuchos_RCPDecl.hpp:1266
UndefinedType2
Definition
TestClasses.cpp:91
UndefinedType
Definition
TestClasses.cpp:64
Generated by
1.17.0