template-list-iostream.cc 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. // { dg-do run }
  2. #include <assert.h>
  3. #include <iostream>
  4. #include <fstream>
  5. using std::ofstream;
  6. using std::ifstream;
  7. using std::ios;
  8. extern "C" int printf(const char *, ...);
  9. class Subscriptor
  10. {
  11. public:
  12. Subscriptor() : counter(1) {}
  13. virtual ~Subscriptor()
  14. {
  15. counter--;
  16. assert(counter == 0);
  17. }
  18. private:
  19. mutable int counter;
  20. };
  21. template <int dim> struct Function
  22. {
  23. Function(int i): value(dim + i) {}
  24. int value;
  25. };
  26. template <int dim> struct Triangulation
  27. {
  28. };
  29. template <int dim> struct Exercise_2_3
  30. {
  31. enum { DIM = dim };
  32. };
  33. template <int dim>
  34. struct SetUpBase : public Subscriptor
  35. {
  36. virtual
  37. const Function<dim> get_boundary_values () const = 0;
  38. virtual
  39. const Function<dim> get_right_hand_side () const = 0;
  40. // virtual
  41. // void create_coarse_grid (Triangulation<dim> &coarse_grid) const = 0;
  42. };
  43. template <class Traits, int dim>
  44. struct SetUp : public SetUpBase<dim>
  45. {
  46. SetUp () {};
  47. virtual
  48. const Function<dim> get_boundary_values () const
  49. { return Function<dim>(Traits::DIM); }
  50. virtual
  51. const Function<dim> get_right_hand_side () const
  52. { return Function<dim>(Traits::DIM); }
  53. // virtual
  54. // void create_coarse_grid (Triangulation<dim> &coarse_grid) const;
  55. // static const typename Traits::BoundaryValues boundary_values;
  56. // static const typename Traits::RightHandSide right_hand_side;
  57. };
  58. void myread(std::istream * in)
  59. {
  60. char input_str[50] = "\0";
  61. if (in->good())
  62. (*in) >> input_str;
  63. std::cout << input_str << std::endl;
  64. delete in;
  65. }
  66. int main()
  67. {
  68. /*
  69. SetUp<Exercise_2_3<1000>, 2> s1a;
  70. SetUp<Exercise_2_3<2000>, 1> s2;
  71. SetUp<Exercise_2_3<2000>, 2> s2a;
  72. return s1->get_boundary_values().value + s1a.get_boundary_values().value +
  73. s2.get_boundary_values().value + s2a.get_boundary_values().value +
  74. s1->get_right_hand_side().value + s1a.get_right_hand_side().value +
  75. s2.get_right_hand_side().value + s2a.get_right_hand_side().value;
  76. */
  77. SetUp<Exercise_2_3<1000>, 1> * s1 = new SetUp<Exercise_2_3<1000>, 1>();
  78. printf("%d\n", s1->get_boundary_values().value);
  79. ifstream * infile = new ifstream("./template-list-iostream.cc");
  80. myread(infile);
  81. ofstream * outfile = new ofstream("/tmp/xxx.txt");
  82. if (outfile->good())
  83. (*outfile) << "hello there" << std::endl;
  84. std::cerr << "Reached End" << std::endl;
  85. delete outfile;
  86. return 0;
  87. }