Dune Core Modules (2.9.0)

iostream.hh
1#ifndef DUNE_COMMON_IOSTREAM_HH
2#define DUNE_COMMON_IOSTREAM_HH
3
4#include <iostream>
5
6namespace 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 {
89 return iostream::Match< typename iostream::MatchTraits< T >::Type >( value );
90 }
91
92} // namespace Dune
93
94#endif // #ifndef DUNE_COMMON_IOSTREAM_HH
Stream & operator>>(Stream &stream, std::tuple< Ts... > &t)
Read a std::tuple.
Definition: streamoperators.hh:43
Dune namespace.
Definition: alignedallocator.hh:13
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 21, 23:30, 2024)