dune-spgrid  2.7
iostream.hh
Go to the documentation of this file.
1 #ifndef DUNE_COMMON_IOSTREAM_HH
2 #define DUNE_COMMON_IOSTREAM_HH
3 
4 #include <iostream>
5 
6 namespace Dune
7 {
8 
9  namespace iostream
10  {
11 
12  template< class T >
13  struct MatchTraits
14  {
15  typedef T Type;
16  };
17 
18  template< class T >
19  struct MatchTraits< const T >
20  {
21  typedef const typename MatchTraits< T >::Type Type;
22  };
23 
24  template< int n >
25  struct MatchTraits< char[ n ] >
26  {
27  typedef std::string Type;
28  };
29 
30 
31  template< class T >
32  struct Match
33  {
34  explicit Match ( const T &value )
35  : value_( value )
36  {}
37 
38  template< class U >
39  Match ( const Match< U > &other )
40  : value_( other.value_ )
41  {}
42 
43  bool operator() ( const T &value ) const
44  {
45  return (value_ == value);
46  }
47 
48  private:
49  T value_;
50  };
51 
52 
53 
54  template< class char_type, class traits, class T >
55  inline std::basic_istream< char_type, traits > &
56  operator>> ( std::basic_istream< char_type, traits > &in, const Match< T > &match )
57  {
58  T value;
59  in >> value;
60  if( !match( value ) )
61  in.clear( std::ios_base::failbit );
62  return in;
63  }
64 
65  } // namespace iostream
66 
67 
68  template< class char_type, class traits >
69  inline bool isGood ( std::basic_istream< char_type, traits > &in )
70  {
71  bool good = in.good();
72  if( good )
73  {
74  char_type c;
75  in >> c;
76  good = !in.fail();
77  if( good )
78  in.unget();
79  in.clear();
80  }
81  return good;
82  }
83 
84 
85  template< class T >
86  inline iostream::Match< typename iostream::MatchTraits< T >::Type >
87  match ( const T &value )
88  {
90  }
91 
92 } // namespace Dune
93 
94 #endif // #ifndef DUNE_COMMON_IOSTREAM_HH
Definition: iostream.hh:7
bool isGood(std::basic_istream< char_type, traits > &in)
Definition: iostream.hh:69
iostream::Match< typename iostream::MatchTraits< T >::Type > match(const T &value)
Definition: iostream.hh:87
std::basic_istream< char_type, traits > & operator>>(std::basic_istream< char_type, traits > &in, const Match< T > &match)
Definition: iostream.hh:56
Definition: iostream.hh:14
T Type
Definition: iostream.hh:15
const MatchTraits< T >::Type Type
Definition: iostream.hh:21
std::string Type
Definition: iostream.hh:27
Definition: iostream.hh:33
Match(const T &value)
Definition: iostream.hh:34
bool operator()(const T &value) const
Definition: iostream.hh:43
Match(const Match< U > &other)
Definition: iostream.hh:39