Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:44:51

0001 #ifndef GENERS_COMPLEXIO_HH_
0002 #define GENERS_COMPLEXIO_HH_
0003 
0004 #include <complex>
0005 
0006 #include "Alignment/Geners/interface/IOIsContainer.hh"
0007 #include "Alignment/Geners/interface/IOIsPOD.hh"
0008 #include "Alignment/Geners/interface/binaryIO.hh"
0009 
0010 #define gs_specialize_complex_read_write(T) /**/                                                                    \
0011   namespace gs {                                                                                                    \
0012     template <>                                                                                                     \
0013     inline void write_pod<std::complex<T>>(std::ostream & of, const std::complex<T> &s) {                           \
0014       write_pod(of, s.real());                                                                                      \
0015       write_pod(of, s.imag());                                                                                      \
0016     }                                                                                                               \
0017     template <>                                                                                                     \
0018     inline void read_pod<std::complex<T>>(std::istream & in, std::complex<T> *ps) {                                 \
0019       assert(ps);                                                                                                   \
0020       T re, im;                                                                                                     \
0021       read_pod(in, &re);                                                                                            \
0022       read_pod(in, &im);                                                                                            \
0023       *ps = std::complex<T>(re, im);                                                                                \
0024     }                                                                                                               \
0025     template <>                                                                                                     \
0026     inline void write_pod_array<std::complex<T>>(std::ostream & of,                                                 \
0027                                                  const std::complex<T> *pod,                                        \
0028                                                  const unsigned long len) {                                         \
0029       if (len) {                                                                                                    \
0030         assert(pod);                                                                                                \
0031         for (unsigned long i = 0; i < len; ++i)                                                                     \
0032           write_pod<std::complex<T>>(of, pod[i]);                                                                   \
0033       }                                                                                                             \
0034     }                                                                                                               \
0035     template <>                                                                                                     \
0036     inline void read_pod_array<std::complex<T>>(std::istream & in, std::complex<T> *pod, const unsigned long len) { \
0037       if (len) {                                                                                                    \
0038         assert(pod);                                                                                                \
0039         T re, im;                                                                                                   \
0040         for (unsigned long i = 0; i < len; ++i) {                                                                   \
0041           read_pod(in, &re);                                                                                        \
0042           read_pod(in, &im);                                                                                        \
0043           pod[i] = std::complex<T>(re, im);                                                                         \
0044         }                                                                                                           \
0045       }                                                                                                             \
0046     }                                                                                                               \
0047   }
0048 
0049 gs_specialize_complex_read_write(float) gs_specialize_complex_read_write(double)
0050     gs_specialize_complex_read_write(long double)
0051 
0052         namespace gs {
0053   template <typename T>
0054   struct IOIsPOD<std::complex<T>> {
0055     enum { value = 1 };
0056   };
0057 
0058   template <typename T>
0059   struct IOIsPOD<const std::complex<T>> {
0060     enum { value = 1 };
0061   };
0062 
0063   template <typename T>
0064   struct IOIsPOD<volatile std::complex<T>> {
0065     enum { value = 1 };
0066   };
0067 
0068   template <typename T>
0069   struct IOIsPOD<const volatile std::complex<T>> {
0070     enum { value = 1 };
0071   };
0072 
0073   template <typename T>
0074   class IOIsContainer<std::complex<T>> {
0075   public:
0076     enum { value = 0 };
0077   };
0078 
0079   template <typename T>
0080   class IOIsContainer<const std::complex<T>> {
0081   public:
0082     enum { value = 0 };
0083   };
0084 
0085   template <typename T>
0086   class IOIsContainer<volatile std::complex<T>> {
0087   public:
0088     enum { value = 0 };
0089   };
0090 
0091   template <typename T>
0092   class IOIsContainer<const volatile std::complex<T>> {
0093   public:
0094     enum { value = 0 };
0095   };
0096 }
0097 
0098 gs_specialize_template_id_T(std::complex, 0, 1)
0099 
0100 #endif  // GENERS_COMPLEXIO_HH_