dune-fem  2.4.1-rc
tuples.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_IO_STREAMS_TUPLES_HH
2 #define DUNE_FEM_IO_STREAMS_TUPLES_HH
3 
4 #include <dune/common/tuples.hh>
5 #include <dune/common/tupleutility.hh>
6 
8 
9 namespace
10 {
11 
12  // TupleToInStream
13  // ---------------
14 
15  template< class InStream >
16  class TupleToInStream
17  {
18  struct InStreamFunctor
19  {
20  InStreamFunctor ( InStream &in ) : in_( in ) {}
21 
22  template< class T >
23  void visit ( T &t ) const
24  {
25  in_ >> t;
26  }
27 
28  private:
29  InStream &in_;
30  };
31 
32  public:
33  template< class Tuple >
34  static InStream &apply ( InStream &in, Tuple &tuple )
35  {
36  Dune::ForEachValue< Tuple > forEach( tuple );
37  InStreamFunctor functor( in );
38  forEach.apply( functor );
39  return in;
40  }
41  };
42 
43 
44 
45  // TupleToOutStream
46  // ----------------
47 
48  template< class OutStream >
49  class TupleToOutStream
50  {
51  struct OutStreamFunctor
52  {
53  OutStreamFunctor ( OutStream &out ) : out_( out ) {}
54 
55  template< class T >
56  void visit ( T &t ) const
57  {
58  out_ << t;
59  }
60 
61  private:
62  OutStream &out_;
63  };
64 
65  public:
66  template< class Tuple >
67  static OutStream &apply ( OutStream &out, const Tuple &tuple )
68  {
69  Dune::ForEachValue< Tuple > forEach( const_cast< Tuple & >( tuple ) );
70  OutStreamFunctor functor( out );
71  forEach.apply( functor );
72  return out;
73  }
74  };
75 
76 } // namespace
77 
78 
79 
80 namespace Dune
81 {
82 
83  namespace Fem
84  {
85 
86  // External forward declarations
87  // -----------------------------
88 
89  template <class StreamTraits>
90  class OutStreamInterface;
91  template <class StreamTraits>
92  class InStreamInterface;
93 
94 
95 
96  // std::tuple to InStream
97  // ----------------------
98 
99  template< class StreamTraits >
100  inline InStreamInterface< StreamTraits > &
101  operator>> ( InStreamInterface< StreamTraits > &in, std::tuple<> &tuple )
102  {
103  return in;
104  }
105 
106  template< class StreamTraits, class... Args >
108  operator>> ( InStreamInterface< StreamTraits > &in, std::tuple< Args... > &tuple )
109  {
110  return TupleToInStream< InStreamInterface< StreamTraits > >::template apply< std::tuple< Args... > >( in, tuple );
111  }
112 
113 
114 
115  // std::tuple to OutStream
116  // -----------------------
117 
118  template< class StreamTraits >
120  operator<< ( OutStreamInterface< StreamTraits > &out, const std::tuple<> &tuple )
121  {
122  return out;
123  }
124 
125  template< class StreamTraits, class... Args >
127  operator<< ( OutStreamInterface< StreamTraits > &out, const std::tuple< Args... > &tuple )
128  {
129  return TupleToOutStream< OutStreamInterface< StreamTraits > >::template apply< std::tuple < Args... > >( out, tuple );
130  }
131 
132  } // namespace Fem
133 
134 } // namespace Dune
135 
136 #endif // #ifndef DUNE_FEM_IO_STREAMS_TUPLES_HH
InStreamInterface< StreamTraits > & operator>>(InStreamInterface< StreamTraits > &in, std::tuple< Args... > &tuple)
Definition: tuples.hh:108
Definition: coordinate.hh:4
abstract interface for an input stream
Definition: streams.hh:177
abstract interface for an output stream
Definition: streams.hh:44