]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/spirit/test/karma/real.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / spirit / test / karma / real.hpp
CommitLineData
7c673cae
FG
1/*==============================================================================
2 Copyright (c) 2001-2010 Hartmut Kaiser
3 Copyright (c) 2010 Bryce Lelbach
4
5 Distributed under the Boost Software License, Version 1.0. (See accompanying
6 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7==============================================================================*/
8
9#if !defined(BOOST_SPIRIT_TEST_REAL_NUMERICS_HPP)
10#define BOOST_SPIRIT_TEST_REAL_NUMERICS_HPP
11
1e59de90 12#include <boost/spirit/include/karma_real.hpp>
7c673cae
FG
13
14#include <boost/spirit/include/karma_char.hpp>
15#include <boost/spirit/include/karma_numeric.hpp>
16#include <boost/spirit/include/karma_generate.hpp>
17#include <boost/spirit/include/karma_directive.hpp>
7c673cae
FG
18
19#include <boost/limits.hpp>
20#include "test.hpp"
21
1e59de90
TL
22#ifndef BOOST_NO_CXX11_SFINAE_EXPR
23# include <boost/math/concepts/real_concept.hpp>
24#else
25# define BOOST_SPIRIT_NO_MATH_REAL_CONCEPT
26#endif
27
7c673cae
FG
28using namespace spirit_test;
29
30///////////////////////////////////////////////////////////////////////////////
31// policy for real_generator, which forces the scientific notation
32template <typename T>
33struct scientific_policy : boost::spirit::karma::real_policies<T>
34{
35 // we want the numbers always to be in scientific format
36 typedef boost::spirit::karma::real_policies<T> base_type;
37 static int floatfield(T) { return base_type::fmtflags::scientific; }
38};
39
40///////////////////////////////////////////////////////////////////////////////
41// policy for real_generator, which forces the fixed notation
42template <typename T>
43struct fixed_policy : boost::spirit::karma::real_policies<T>
44{
45 typedef boost::spirit::karma::real_policies<T> base_type;
46
92f5a8d4 47 // we want the numbers always to be in fixed format
7c673cae
FG
48 static int floatfield(T) { return base_type::fmtflags::fixed; }
49};
50
51///////////////////////////////////////////////////////////////////////////////
52// policy for real_generator, which forces to output trailing zeros in the
53// fractional part
54template <typename T>
55struct trailing_zeros_policy : boost::spirit::karma::real_policies<T> // 4 digits
56{
57 // we want the numbers always to contain trailing zeros up to 4 digits in
58 // the fractional part
59 static bool trailing_zeros(T) { return true; }
60
61 // we want to generate up to 4 fractional digits
62 static unsigned int precision(T) { return 4; }
63};
64
65///////////////////////////////////////////////////////////////////////////////
66// policy for real_generator, which forces the sign to be generated
67template <typename T>
68struct signed_policy : boost::spirit::karma::real_policies<T>
69{
70 // we want to always have a sign generated
71 static bool force_sign(T)
72 {
73 return true;
74 }
75};
76
77///////////////////////////////////////////////////////////////////////////////
78// policy for real_generator, which forces to output trailing zeros in the
79// fractional part
80template <typename T>
81struct bordercase_policy : boost::spirit::karma::real_policies<T>
82{
83 // we want to generate up to the maximum significant amount of fractional
84 // digits
85 static unsigned int precision(T)
86 {
87 return std::numeric_limits<T>::digits10 + 1;
88 }
89};
90
91///////////////////////////////////////////////////////////////////////////////
92// policy for real_generator, which forces to output trailing zeros in the
93// fractional part
94template <typename T>
95struct statefull_policy : boost::spirit::karma::real_policies<T>
96{
97 statefull_policy(int precision = 4, bool trailingzeros = false)
98 : precision_(precision), trailingzeros_(trailingzeros)
99 {}
100
101 // we want to generate up to the maximum significant amount of fractional
102 // digits
103 unsigned int precision(T) const
104 {
105 return precision_;
106 }
107
108 bool trailing_zeros(T) const
109 {
110 return trailingzeros_;
111 }
112
113 int precision_;
114 bool trailingzeros_;
115};
116
117#endif // BOOST_SPIRIT_TEST_REAL_NUMERICS_HPP
118