core/vsl/vsl_complex_io.txx
Go to the documentation of this file.
00001 // This is core/vsl/vsl_complex_io.txx
00002 #ifndef vsl_complex_io_txx_
00003 #define vsl_complex_io_txx_
00004 //:
00005 // \file
00006 // \brief  binary IO functions for vcl_complex<T>
00007 // \author K.Y.McGaul
00008 //
00009 // Implementation
00010 
00011 #include "vsl_complex_io.h"
00012 #include <vsl/vsl_binary_io.h>
00013 
00014 
00015 //====================================================================================
00016 //: Write complex to binary stream
00017 template <class T>
00018 void vsl_b_write(vsl_b_ostream& s, const vcl_complex<T>& v)
00019 {
00020   // Do not write a version number here for space efficiency reasons.
00021   // There is no reason to expect the format to change
00022   vsl_b_write(s, vcl_real(v));
00023   vsl_b_write(s, vcl_imag(v));
00024 }
00025 
00026 //====================================================================================
00027 //: Read complex from binary stream
00028 template <class T>
00029 void vsl_b_read(vsl_b_istream& s, vcl_complex<T>& v)
00030 {
00031   T real_part, imag_part;
00032   vsl_b_read(s, real_part);
00033   vsl_b_read(s, imag_part);
00034   v = vcl_complex<T>(real_part, imag_part);
00035 }
00036 
00037 //====================================================================================
00038 //: Output a human readable summary to the stream
00039 template <class T>
00040 void vsl_print_summary(vcl_ostream& os, const vcl_complex<T> &v)
00041 {
00042   os << vcl_real(v) << " + " << vcl_imag(v) << "i ";
00043 }
00044 
00045 #define VSL_COMPLEX_IO_INSTANTIATE(T) \
00046 template void vsl_print_summary(vcl_ostream&, const vcl_complex<T >&); \
00047 template void vsl_b_write(vsl_b_ostream& s, const vcl_complex<T >& v); \
00048 template void vsl_b_read(vsl_b_istream& s, vcl_complex<T >& v)
00049 
00050 #endif // vsl_complex_io_txx_