vsl_complex_io.hxx
Go to the documentation of this file.
1 // This is core/vsl/vsl_complex_io.hxx
2 #ifndef vsl_complex_io_hxx_
3 #define vsl_complex_io_hxx_
4 //:
5 // \file
6 // \brief binary IO functions for std::complex<T>
7 // \author K.Y.McGaul
8 //
9 // Implementation
10 
11 #include "vsl_complex_io.h"
12 #include <vsl/vsl_binary_io.h>
13 
14 
15 //====================================================================================
16 //: Write complex to binary stream
17 template <class T>
18 void vsl_b_write(vsl_b_ostream& s, const std::complex<T>& v)
19 {
20  // Do not write a version number here for space efficiency reasons.
21  // There is no reason to expect the format to change
22  vsl_b_write(s, std::real(v));
23  vsl_b_write(s, std::imag(v));
24 }
25 
26 //====================================================================================
27 //: Read complex from binary stream
28 template <class T>
29 void vsl_b_read(vsl_b_istream& s, std::complex<T>& v)
30 {
31  T real_part, imag_part;
32  vsl_b_read(s, real_part);
33  vsl_b_read(s, imag_part);
34  v = std::complex<T>(real_part, imag_part);
35 }
36 
37 //====================================================================================
38 //: Output a human readable summary to the stream
39 template <class T>
40 void vsl_print_summary(std::ostream& os, const std::complex<T> &v)
41 {
42  os << std::real(v) << " + " << std::imag(v) << "i ";
43 }
44 
45 #define VSL_COMPLEX_IO_INSTANTIATE(T) \
46 template void vsl_print_summary(std::ostream&, const std::complex<T >&); \
47 template void vsl_b_write(vsl_b_ostream& s, const std::complex<T >& v); \
48 template void vsl_b_read(vsl_b_istream& s, std::complex<T >& v)
49 
50 #endif // vsl_complex_io_hxx_
A binary output adaptor for any std::ostream.
Definition: vsl_binary_io.h:37
void vsl_b_write(vsl_b_ostream &s, const std::complex< T > &v)
Write complex to binary stream.
An adaptor for any std::istream to make it suitable for binary input.
void vsl_print_summary(std::ostream &os, const std::complex< T > &v)
Output a human readable summary to the stream.
Set of functions, and objects to perform binary IO.
void vsl_b_read(vsl_b_istream &s, std::complex< T > &v)
Read complex from binary stream.
binary IO functions for std::complex<T>