Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TestClasses.hpp
Go to the documentation of this file.
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_TEST_CLASSES_HPP
11 #define TEUCHOS_TEST_CLASSES_HPP
12 
13 
14 #include "Teuchos_RCP.hpp"
15 
16 
17 // Return constants from class functions
18 const int A_g_return = 1;
19 const int A_f_return = 2;
20 const int B1_g_return = 3;
21 const int B1_f_return = 4;
22 const int B2_g_return = 5;
23 const int B2_f_return = 6;
24 const int C_g_return = 7;
25 const int C_f_return = 8;
26 const int D_g_return = 9;
27 const int D_f_return = 10;
28 const int E_g_return = 11;
29 const int E_f_return = 12;
30 
31 
32 /*
33 
34  Polymorphic multiple inheritance example
35 
36  -----
37  | A |
38  -----
39  /|\
40  |
41  ------------
42  | |
43  ----- ------
44  | B1 | | B2 |
45  ----- ------
46  /|\ /|\
47  | |
48  ------------
49  |
50  -----
51  | C |
52  -----
53 
54 */
55 
56 
57 class C;
58 
59 
60 class A {
61  int A_g_, A_f_;
62 public:
64  A(const int A_g, const int A_f) : A_g_(A_g), A_f_(A_f) {}
65  static Teuchos::RCP<A> create() { return Teuchos::rcp(new A); }
66  virtual ~A() TEUCHOS_NOEXCEPT_FALSE; // See below
67  virtual int A_g() { return A_g_; }
68  virtual int A_f() const { return A_f_; }
69  int call_C_f();
70 private:
72 public:
73  void set_C(const Teuchos::RCP<C> &c ) { c_ = c; }
74 };
75 
76 
77 class B1 : virtual public A {
78  int B1_g_, B1_f_;
79 public:
81  ~B1() { B1_g_ = -1; B1_f_ = -1; }
82  static Teuchos::RCP<B1> create() { return Teuchos::rcp(new B1); }
83  virtual int B1_g() { return B1_g_; }
84  virtual int B1_f() const { return B1_f_; }
85 };
86 
87 
88 class B2 : virtual public A {
89  int B2_g_, B2_f_;
90 public:
92  static Teuchos::RCP<B2> create() { return Teuchos::rcp(new B2); }
93  ~B2() { B2_g_ = -1; B2_f_ = -1; }
94  virtual int B2_g() { return B2_g_; }
95  virtual int B2_f() const { return B2_f_; }
96 };
97 
98 
99 class C : virtual public B1, virtual public B2
100 {
101  int C_g_, C_f_;
102 public:
104  {
105  A_g_on_delete_ = -2;
106  }
107  static Teuchos::RCP<C> create() { return Teuchos::rcp(new C); }
108  ~C()
109  {
110  C_g_ = -1; C_f_ = -1;
111  }
112  virtual int C_g() { return C_g_; }
113  virtual int C_f() const { return C_f_; }
114  int call_A_g() { return a_->A_g(); }
115  static int get_A_g_on_delete() { return A_g_on_delete_; }
116 private:
118  static int A_g_on_delete_;
119 public:
120  void set_A(const Teuchos::RCP<A> &a ) { a_ = a; }
121  Teuchos::RCP<A> get_A() { return a_; }
122 };
123 
124 
125 // Need to put these here if we have circular references
126 
127 inline
128 A::~A() TEUCHOS_NOEXCEPT_FALSE { A_g_ = -1; A_f_ = -1; }
129 
130 
131 inline
132 int A::call_C_f() { return c_->C_f(); }
133 
134 
136  const A *a_;
138  Get_A_f_return();
139 public:
140  Get_A_f_return( const A *a, int *a_f_return ) : a_(a), a_f_return_(a_f_return) {}
142 };
143 
144 
145 void deallocA(A* ptr);
146 
147 
148 void deallocHandleA(A** handle);
149 
150 
151 /*
152 
153  Non-polymophic classes hiearchy examlpe
154 
155  -----
156  | D |
157  -----
158  /|\
159  |
160  -----
161  | E |
162  -----
163 
164 */
165 
166 
167 class D
168 {
169  int D_g_, D_f_;
170 public:
172  int D_g() { return D_g_; }
173  int D_f() const { return D_f_; }
174 };
175 
176 
177 class E : public D
178 {
179  int E_g_, E_f_;
180 public:
182  int E_g() { return E_g_; }
183  int E_f() const { return E_f_; }
184 };
185 
186 
187 /*
188 
189 Typedef to pointer for undefined struct as an opaque object type without a
190 specialization of TypeNameTraits.
191 
192 This simulates what happens with a lot of MPI implementations.
193 
194 */
195 
196 struct UndefinedType; // Forward declared but never defined!
200 const int getOpaqueValue_return = 5;
201 int getOpaqueValue( Opaque_handle opaque );
202 void destroyOpaque( Opaque_handle * opaque );
203 
204 
205 /*
206 
207 Typedef to pointer for an undefiend struct as an opaque object type out a
208 specialization of TypeNameTraits of the actually type.
209 
210 This allows it to be stored in an RCP object itself.
211 
212 */
213 
214 struct UndefinedType2; // Forward declared but never defined!
219 int getOpaque2Value( Opaque2_handle opaque );
220 void destroyOpaque2( Opaque2_handle * opaque );
221 
222 
223 namespace Teuchos {
224 
225 
226 // Here we define the traits for the underlying type itself.
227 template<>
229 public:
230  static std::string name() { return "UndefinedType2"; }
231  static std::string concreteName(const UndefinedType2&)
232  { return name(); }
233 };
234 
235 
236 } // namespace Teuchos
237 
238 
239 /*
240 
241 Typedef to pointer for an undefiend struct as an opaque object type out a
242 specialization of TypeNameTraits of the actually type.
243 
244 This allows handles to the type be used with Array, ArrayRCP, and ArrayView.
245 However, this type can *not* be used with RCP since it does not define a
246 TypeNameTraits specialization for the underlying undefined type.
247 
248 This simulates what can happen with MPI implementations.
249 
250 */
251 
252 struct UndefinedType3; // Forward declared but never defined!
253 typedef UndefinedType3* Opaque3_handle;
255 
256 
257 namespace Teuchos {
258 
259 // Here we only define the traits class for the handle type and we don't even
260 // need to worry about what the underlying type is (unless we already have a
261 // speicalization defined for it).
262 template<>
264 public:
265  static std::string name() { return "Opaque3_handle"; }
266  static std::string concreteName(Opaque3_handle)
267  { return name(); }
268 };
269 
270 
271 } // namespace Teuchos
272 
273 
274 #endif // TEUCHOS_TEST_CLASSES_HPP
int E_f_
~C()
B2()
Definition: TestClasses.hpp:91
void destroyOpaque(Opaque_handle *opaque)
Definition: TestClasses.cpp:51
void set_C(const Teuchos::RCP< C > &c)
Definition: TestClasses.hpp:73
static Teuchos::RCP< B1 > create()
Definition: TestClasses.hpp:82
const int E_f_return
Definition: TestClasses.hpp:29
const int B2_g_return
Definition: TestClasses.hpp:22
virtual int B2_g()
Definition: TestClasses.hpp:94
int B2_f_
Definition: TestClasses.hpp:89
int B1_g_
Definition: TestClasses.hpp:78
virtual int A_g()
Definition: TestClasses.hpp:67
const Opaque_handle OPAQUE_HANDLE_NULL
A(const int A_g, const int A_f)
Definition: TestClasses.hpp:64
int call_C_f()
static Teuchos::RCP< C > create()
virtual int C_f() const
A()
Definition: TestClasses.hpp:63
const int C_g_return
Definition: TestClasses.hpp:24
int C_g_
static Teuchos::RCP< A > create()
Definition: TestClasses.hpp:65
const int C_f_return
Definition: TestClasses.hpp:25
const int A_f_return
Definition: TestClasses.hpp:19
~B1()
Definition: TestClasses.hpp:81
int D_f() const
const int getOpaqueValue_return
void destroyOpaque2(Opaque2_handle *opaque)
Definition: TestClasses.cpp:78
const Opaque2_handle OPAQUE2_HANDLE_NULL
UndefinedType2 * Opaque2_handle
int A_f_
Definition: TestClasses.hpp:61
int A_g_
Definition: TestClasses.hpp:61
const int getOpaque2Value_return
static int A_g_on_delete_
Teuchos::RCP< A > get_A()
void deallocHandleA(A **handle)
Definition: TestClasses.cpp:23
const int D_f_return
Definition: TestClasses.hpp:27
int call_A_g()
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
int E_f() const
int getOpaqueValue(Opaque_handle opaque)
Definition: TestClasses.cpp:45
virtual int B2_f() const
Definition: TestClasses.hpp:95
virtual int B1_g()
Definition: TestClasses.hpp:83
int B1_f_
Definition: TestClasses.hpp:78
int D_g_
Opaque2_handle createOpaque2()
Definition: TestClasses.cpp:64
const Opaque3_handle OPAQUE3_HANDLE_NULL
static std::string concreteName(const UndefinedType2 &)
static Teuchos::RCP< B2 > create()
Definition: TestClasses.hpp:92
Teuchos::RCP< A > a_
void set_A(const Teuchos::RCP< A > &a)
static std::string concreteName(Opaque3_handle)
static int get_A_g_on_delete()
UndefinedType * Opaque_handle
Get_A_f_return(const A *a, int *a_f_return)
#define TEUCHOS_NOEXCEPT_FALSE
Ptr< T > ptr(T *p)
Create a pointer to an object from a raw pointer.
const int D_g_return
Definition: TestClasses.hpp:26
const int B1_f_return
Definition: TestClasses.hpp:21
int D_g()
Teuchos::RCP< C > c_
Definition: TestClasses.hpp:71
Default traits class that just returns typeid(T).name().
UndefinedType3 * Opaque3_handle
B1()
Definition: TestClasses.hpp:80
const int B1_g_return
Definition: TestClasses.hpp:20
int getOpaque2Value(Opaque2_handle opaque)
Definition: TestClasses.cpp:72
Opaque_handle createOpaque()
Definition: TestClasses.cpp:37
int C_f_
int E_g_
virtual int A_f() const
Definition: TestClasses.hpp:68
virtual int B1_f() const
Definition: TestClasses.hpp:84
int D_f_
~B2()
Definition: TestClasses.hpp:93
int E_g()
Reference-counted pointer class and non-member templated function implementations.
const int A_g_return
Definition: TestClasses.hpp:18
const int E_g_return
Definition: TestClasses.hpp:28
const int B2_f_return
Definition: TestClasses.hpp:23
virtual int C_g()
int B2_g_
Definition: TestClasses.hpp:89
void deallocA(A *ptr)
Definition: TestClasses.cpp:16