libpniio
float_policy.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 <limits>
27 #include <iostream>
28 #include <boost/spirit/include/karma_real.hpp>
29 
30 namespace pni{
31 namespace io{
32 
50  template<typename T>
51  struct float_policy : boost::spirit::karma::real_policies<T>
52  {
53  //--------------------------------------------------------------------
57  static int floatfield(T)
58  {
59  return 0;
60  }
61 
62  //--------------------------------------------------------------------
66  static int precision(T)
67  {
68  return std::numeric_limits<T>::digits10;
69  }
70 
71  };
72 
73  //------------------------------------------------------------------------
86  template<typename T>
87  struct imag_policy : boost::spirit::karma::real_policies<T>
88  {
90  typedef boost::spirit::karma::real_policies<T> base_type;
91 
92  //--------------------------------------------------------------------
96  static int floatfield(T)
97  {
98  return 0;
99  }
100 
101  //--------------------------------------------------------------------
105  static int precision(T)
106  {
107  return std::numeric_limits<T>::digits10;
108  }
109 
110  //--------------------------------------------------------------------
123  template<typename OITER>
124  static bool integer_part(OITER &sink,T n,bool sign,bool )
125  {
126  if(sign)
127  *(sink++) = '-';
128  else
129  *(sink++) = '+';
130 
131  *(sink++) = 'I';
132 
133  return base_type::integer_part(sink,n,false,false);
134  }
135  };
136 
137 
138 //end of namespace
139 }
140 }
static int precision(T)
set output to full number precision
Definition: float_policy.hpp:66
Definition: cbf_reader.hpp:41
static int floatfield(T)
use scientific format by default
Definition: float_policy.hpp:96
static int floatfield(T)
use scientific format by default
Definition: float_policy.hpp:57
boost::spirit::karma::real_policies< T > base_type
policy to parse the base type
Definition: float_policy.hpp:90
static bool integer_part(OITER &sink, T n, bool sign, bool)
add sign and I in front of the output
Definition: float_policy.hpp:124
static int precision(T)
always use maximum precision of required
Definition: float_policy.hpp:105
policy for real numbers
Definition: float_policy.hpp:51
real policy for imaginary part
Definition: float_policy.hpp:87