libpniio
complex_generator.hpp
Go to the documentation of this file.
1 //
2 // (c) Copyright 2015 DESY, Eugen Wintersberger <eugen.wintersberger@desy.de>
3 //
4 // This file is part of libpniio.
5 //
6 // libpniio is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // libpniio is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with libpniio. If not, see <http://www.gnu.org/licenses/>.
18 // ===========================================================================
19 //
20 // Created on: Feb 11, 2015
21 // Author: Eugen Wintersberger <eugen.wintersberger@desy.de>
22 //
23 //
24 #pragma once
25 
26 #include <iterator>
27 #include <complex>
28 #include <pni/core/types.hpp>
29 #include <boost/spirit/include/karma.hpp>
30 #include <boost/spirit/include/phoenix.hpp>
31 
32 #include "float_policy.hpp"
33 
34 namespace pni{
35 namespace io{
36 
45  template<
46  typename OITER,
47  typename T
48  >
49  struct complex_generator : boost::spirit::karma::grammar<OITER,std::complex<T>()>
50  {
57  struct get_real
58  {
62  template<typename Sig> struct result
63  {
64  typedef T type;
65  };
66 
77  template<typename Arg>
78  T operator()(Arg const &n) const
79  {
80  return std::real(n);
81  }
82  };
83 
84  //--------------------------------------------------------------------
90  struct get_imag
91  {
95  template<typename Sig> struct result
96  {
97  typedef T type;
98  };
99 
110  template<typename Arg>
111  T operator()(Arg const &n) const
112  {
113  return std::imag(n);
114  }
115 
116  };
117 
118  //-------------------------------------------------------------------
120  boost::phoenix::function<get_real> real;
122  boost::phoenix::function<get_imag> imag;
123 
125  boost::spirit::karma::real_generator<T,float_policy<T>> float_rule;
127  boost::spirit::karma::real_generator<T,imag_policy<T>> imag_rule;
129  boost::spirit::karma::rule<OITER,std::complex<T>()> complex_rule;
130 
137  {
138  using boost::spirit::karma::_1;
139  using boost::spirit::karma::_val;
140 #ifdef __clang__
141 #pragma clang diagnostic push
142 #pragma clang diagnostic ignored "-Wunsequenced"
143 #endif
144  complex_rule = float_rule[_1 = real(_val)]<<
145  imag_rule[_1 = imag(_val)];
146 #ifdef __clang__
147 #pragma clang diagnostic pop
148 #endif
149  }
150 
151  };
152 
153 }
154 }
get imaginary part
Definition: complex_generator.hpp:90
boost::spirit::karma::real_generator< T, float_policy< T > > float_rule
rule to produce the real part
Definition: complex_generator.hpp:125
T type
result type
Definition: complex_generator.hpp:64
result type of the lazy function
Definition: complex_generator.hpp:62
Definition: cbf_reader.hpp:41
T type
result type
Definition: complex_generator.hpp:97
boost::phoenix::function< get_real > real
instance of the get_real lazy function
Definition: complex_generator.hpp:120
T operator()(Arg const &n) const
get imaginary part
Definition: complex_generator.hpp:111
boost::spirit::karma::real_generator< T, imag_policy< T > > imag_rule
rule to produce the imaginary part
Definition: complex_generator.hpp:127
complex_generator()
default constructor
Definition: complex_generator.hpp:136
T operator()(Arg const &n) const
get real part
Definition: complex_generator.hpp:78
get real part
Definition: complex_generator.hpp:57
generator for complex numbers
Definition: complex_generator.hpp:49
boost::phoenix::function< get_imag > imag
instance of the get_imag lazy function
Definition: complex_generator.hpp:122
complex number rule
Definition: complex_rule.hpp:53
result type of the lazy function
Definition: complex_generator.hpp:95