| 1 |
// { dg-do run } |
| 2 |
|
| 3 |
#include <assert.h> |
| 4 |
|
| 5 |
extern "C" int printf(const char *, ...); |
| 6 |
|
| 7 |
class Subscriptor |
| 8 |
{ |
| 9 |
public: |
| 10 |
|
| 11 |
Subscriptor() : counter(1) {} |
| 12 |
|
| 13 |
virtual ~Subscriptor() |
| 14 |
{ |
| 15 |
counter--; |
| 16 |
assert(counter == 0); |
| 17 |
} |
| 18 |
|
| 19 |
private: |
| 20 |
mutable int counter; |
| 21 |
}; |
| 22 |
|
| 23 |
template <int dim> struct Function |
| 24 |
{ |
| 25 |
Function(int i): value(dim + i) {} |
| 26 |
int value; |
| 27 |
}; |
| 28 |
|
| 29 |
template <int dim> struct Triangulation |
| 30 |
{ |
| 31 |
|
| 32 |
}; |
| 33 |
|
| 34 |
template <int dim> struct Exercise_2_3 |
| 35 |
{ |
| 36 |
enum { DIM = dim }; |
| 37 |
}; |
| 38 |
|
| 39 |
template <int dim> |
| 40 |
struct SetUpBase : public Subscriptor |
| 41 |
{ |
| 42 |
virtual |
| 43 |
const Function<dim> get_boundary_values () const = 0; |
| 44 |
|
| 45 |
virtual |
| 46 |
const Function<dim> get_right_hand_side () const = 0; |
| 47 |
|
| 48 |
// virtual |
| 49 |
// void create_coarse_grid (Triangulation<dim> &coarse_grid) const = 0; |
| 50 |
}; |
| 51 |
|
| 52 |
template <class Traits, int dim> |
| 53 |
struct SetUp : public SetUpBase<dim> |
| 54 |
{ |
| 55 |
SetUp () {}; |
| 56 |
|
| 57 |
virtual |
| 58 |
const Function<dim> get_boundary_values () const |
| 59 |
{ return Function<dim>(Traits::DIM); } |
| 60 |
|
| 61 |
virtual |
| 62 |
const Function<dim> get_right_hand_side () const |
| 63 |
{ return Function<dim>(Traits::DIM); } |
| 64 |
|
| 65 |
// virtual |
| 66 |
// void create_coarse_grid (Triangulation<dim> &coarse_grid) const; |
| 67 |
|
| 68 |
// static const typename Traits::BoundaryValues boundary_values; |
| 69 |
// static const typename Traits::RightHandSide right_hand_side; |
| 70 |
}; |
| 71 |
|
| 72 |
|
| 73 |
int main() |
| 74 |
{ |
| 75 |
/* |
| 76 |
|
| 77 |
SetUp<Exercise_2_3<1000>, 2> s1a; |
| 78 |
SetUp<Exercise_2_3<2000>, 1> s2; |
| 79 |
SetUp<Exercise_2_3<2000>, 2> s2a; |
| 80 |
return s1->get_boundary_values().value + s1a.get_boundary_values().value + |
| 81 |
s2.get_boundary_values().value + s2a.get_boundary_values().value + |
| 82 |
s1->get_right_hand_side().value + s1a.get_right_hand_side().value + |
| 83 |
s2.get_right_hand_side().value + s2a.get_right_hand_side().value; |
| 84 |
*/ |
| 85 |
#ifndef NFAIL |
| 86 |
SetUp<Exercise_2_3<1000>, 1> * s1 = new SetUp<Exercise_2_3<1000>, 1>(); |
| 87 |
printf("%d\n", s1->get_boundary_values().value); |
| 88 |
return 0; |
| 89 |
#else |
| 90 |
SetUp<Exercise_2_3<1000>, 1> s1; |
| 91 |
printf("%d\n", s1.get_boundary_values().value); |
| 92 |
return 0; |
| 93 |
#endif |
| 94 |
} |