DUNE-FEM (unstable)

streams_inline.hh
1#ifndef DUNE_FEM_STREAMS_INLINE_HH
2#define DUNE_FEM_STREAMS_INLINE_HH
3
4#include <vector>
5#include <array>
6
8
9#include "streams.hh"
10
11namespace Dune
12{
13
14 namespace Fem
15 {
16
17 template< class Traits >
18 inline OutStreamInterface< Traits > &
19 operator<< ( OutStreamInterface< Traits > &out,
20 const double value )
21 {
22 out.writeDouble( value );
23 return out;
24 }
25
26 template< class Traits >
27 inline OutStreamInterface< Traits > &
28 operator<< ( OutStreamInterface< Traits > &out,
29 const float value )
30 {
31 out.writeFloat( value );
32 return out;
33 }
34
35 template< class Traits >
36 inline OutStreamInterface< Traits > &
37 operator<< ( OutStreamInterface< Traits > &out,
38 const int value )
39 {
40 out.writeInt( value );
41 return out;
42 }
43
44 template< class Traits >
45 inline OutStreamInterface< Traits > &
46 operator<< ( OutStreamInterface< Traits > &out,
47 const char value )
48 {
49 out.writeChar( value );
50 return out;
51 }
52
53 template< class Traits >
54 inline OutStreamInterface< Traits > &
55 operator<< ( OutStreamInterface< Traits > &out,
56 const bool value )
57 {
58 out.writeBool( value );
59 return out;
60 }
61
62 template< class Traits >
63 inline OutStreamInterface< Traits > &
64 operator<< ( OutStreamInterface< Traits > &out,
65 const std :: string &s )
66 {
67 out.writeString( s );
68 return out;
69 }
70
71 template< class Traits >
72 inline OutStreamInterface< Traits > &
73 operator<< ( OutStreamInterface< Traits > &out,
74 const unsigned int value )
75 {
76 out.writeUnsignedInt( value );
77 return out;
78 }
79
80 template< class Traits, class T >
81 inline OutStreamInterface< Traits > &
82 operator<< ( OutStreamInterface< Traits > &out,
83 const std::complex<T> value )
84 {
85 out.writeDouble( std::real(value) );
86 out.writeDouble( std::imag(value) );
87 return out;
88 }
89
90 template< class Traits >
91 inline OutStreamInterface< Traits > &
92 operator<< ( OutStreamInterface< Traits > &out,
93 const uint64_t value )
94 {
95 out.writeUnsignedInt64( value );
96 return out;
97 }
98
99 template< class Traits >
100 inline OutStreamInterface< Traits > &
101 operator<< ( OutStreamInterface< Traits > &out,
102 const std::conditional< std::is_same<unsigned long, uint64_t>::value,
103 unsigned long long, // select long long in case long and uint64 are the same
104 unsigned long >::type& value
105 )
106 {
107 assert( sizeof(value) <= sizeof(uint64_t) );
108 uint64_t v = value;
109 out.writeUnsignedInt64( v );
110 return out;
111 }
112
113 template< class Traits >
114 inline OutStreamInterface< Traits > &
115 operator<< ( OutStreamInterface< Traits > &out,
116 const int64_t value )
117 {
118 out.writeSignedInt64( value );
119 return out;
120 }
121
122 template< class Traits >
123 inline OutStreamInterface< Traits > &
124 operator<< ( OutStreamInterface< Traits > &out,
125 const std::conditional< std::is_same<long, int64_t>::value,
126 long long, // select long long in case long and int64 are the same
127 long >::type& value )
128 {
129 assert( sizeof(value) <= sizeof(int64_t));
130 int64_t v = value;
131 out.writeSignedInt64( v );
132 return out;
133 }
134
135 template< class Traits, class T, std::size_t N >
136 inline OutStreamInterface< Traits > &
137 operator<< ( OutStreamInterface< Traits > &out, const std::array< T, N > &value )
138 {
139 for( std::size_t i = 0; i < N; ++i )
140 out << value[ i ];
141 return out;
142 }
143
144 template< class Traits, class T, int N >
145 inline OutStreamInterface< Traits > &
146 operator<< ( OutStreamInterface< Traits > &out, const Dune::FieldVector< T, N > &value )
147 {
148 for( int i = 0; i < N; ++i )
149 out << value[ i ];
150 return out;
151 }
152
153 template< class Traits, class T, class A >
154 inline OutStreamInterface< Traits > &
155 operator<< ( OutStreamInterface< Traits > &out,
156 const std::vector< T, A > & value )
157 {
158 const size_t size = value.size();
159 out << size;
160 for( size_t i = 0; i < size; ++i )
161 out << value[ i ];
162 return out;
163 }
164
165 template< class Traits >
166 inline InStreamInterface< Traits > &
167 operator>> ( InStreamInterface< Traits > &in,
168 double &value )
169 {
170 in.readDouble( value );
171 return in;
172 }
173
174 template< class Traits >
175 inline InStreamInterface< Traits > &
176 operator>> ( InStreamInterface< Traits > &in,
177 float &value )
178 {
179 in.readFloat( value );
180 return in;
181 }
182
183 template< class Traits >
184 inline InStreamInterface< Traits > &
185 operator>> ( InStreamInterface< Traits > &in,
186 int &value )
187 {
188 in.readInt( value );
189 return in;
190 }
191
192 template< class Traits >
193 inline InStreamInterface< Traits > &
194 operator>> ( InStreamInterface< Traits > &in,
195 char &value )
196 {
197 in.readChar( value );
198 return in;
199 }
200
201 template< class Traits >
202 inline InStreamInterface< Traits > &
203 operator>> ( InStreamInterface< Traits > &in,
204 bool &value )
205 {
206 in.readBool( value );
207 return in;
208 }
209
210 template< class Traits >
211 inline InStreamInterface< Traits > &
212 operator>> ( InStreamInterface< Traits > &in,
213 std :: string &s )
214 {
215 in.readString( s );
216 return in;
217 }
218
219 template< class Traits >
220 inline InStreamInterface< Traits > &
221 operator>> ( InStreamInterface< Traits > &in,
222 unsigned int &value )
223 {
224 in.readUnsignedInt( value );
225 return in;
226 }
227
228 template< class Traits >
229 inline InStreamInterface< Traits > &
230 operator>> ( InStreamInterface< Traits > &in,
231 uint64_t &value )
232 {
233 in.readUnsignedInt64( value );
234 return in;
235 }
236
237 template< class Traits >
238 inline InStreamInterface< Traits > &
239 operator>> ( InStreamInterface< Traits > &in,
240 std::conditional< std::is_same<unsigned long, uint64_t>::value,
241 unsigned long long,
242 unsigned long >::type& value )
243 {
244 // in any case, convert to uint64_t
245 assert( sizeof(value) <= sizeof(uint64_t));
246 uint64_t v;
247 in.readUnsignedInt64( v );
248 value = v;
249 return in;
250 }
251
252 template< class Traits >
253 inline InStreamInterface< Traits > &
254 operator>> ( InStreamInterface< Traits > &in,
255 int64_t &value )
256 {
257 in.readSignedInt64( value );
258 return in;
259 }
260
261 template< class Traits >
262 inline InStreamInterface< Traits > &
263 operator>> ( InStreamInterface< Traits > &in,
264 std::conditional< std::is_same<long, int64_t>::value,
265 long long,
266 long >::type& value )
267 {
268 // in any case, convert to uint64_t
269 assert( sizeof(value) <= sizeof(int64_t));
270 int64_t v;
271 in.readSignedInt64( v );
272 value = v;
273 return in;
274 }
275
276 template< class Traits, class T, std::size_t N >
277 inline InStreamInterface< Traits > &
278 operator>> ( InStreamInterface< Traits > &in, std::array< T, N > &value )
279 {
280 for( std::size_t i = 0; i < N; ++i )
281 in >> value[ i ];
282 return in;
283 }
284
285 template< class Traits, class T, int N >
286 inline InStreamInterface< Traits > &
287 operator>> ( InStreamInterface< Traits > &in, Dune::FieldVector< T, N > &value )
288 {
289 for( int i = 0; i < N; ++i )
290 in >> value[ i ];
291 return in;
292 }
293
294 template< class Traits, class T >
295 inline InStreamInterface< Traits > &
296 operator>> ( InStreamInterface< Traits > &in,
297 std::complex<T> &value )
298 {
299 T r,i;
300 in.readDouble( r );
301 in.readDouble( i );
302 value = std::complex<T>(r,i);
303 return in;
304 }
305
306 template< class Traits, class T, class A >
307 inline InStreamInterface< Traits > &
308 operator>> ( InStreamInterface< Traits > &in,
309 std::vector< T, A > & value )
310 {
311 size_t size = 0;
312 in >> size;
313 value.resize( size );
314 for( size_t i = 0; i < size; ++i )
315 in >> value[ i ];
316 return in;
317 }
318
319 } // namespace Fem
320
321} // namespace Dune
322
323#endif // #ifndef DUNE_FEM_STREAMS_INLINE_HH
Implements a vector constructed from a given type representing a field and a compile-time given size.
Stream & operator>>(Stream &stream, std::tuple< Ts... > &t)
Read a std::tuple.
Definition: streamoperators.hh:43
Dune namespace.
Definition: alignedallocator.hh:13
constexpr std::integral_constant< std::size_t, sizeof...(II)> size(std::integer_sequence< T, II... >)
Return the size of the sequence.
Definition: integersequence.hh:75
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 27, 22:29, 2024)