-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformatting.hpp
60 lines (49 loc) · 1.43 KB
/
formatting.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
* formatting.hpp
*
* Created on: Sep 23, 2016
* Author: Joost Huizinga
*/
#ifndef MODULES_MISC_FORMATTING_HPP_
#define MODULES_MISC_FORMATTING_HPP_
#ifdef __GNUC__
#if __GNUC__ >= 4 && __GNUC_MINOR__ >= 6
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-W#pragma-messages"
#elif __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-W#pragma-messages"
#endif
#endif
#include <boost/spirit/include/karma.hpp>
#include <boost/spirit/include/karma_real.hpp>
#include <boost/lexical_cast.hpp>
namespace modules{
namespace misc{
namespace formatting{
using namespace boost::spirit::karma;
template <typename T>
struct real6_policy : real_policies<T> {
static unsigned int precision(T) { return 6; }
static int floatfield(T n) { return real_policies<T>::fmtflags::fixed; }
};
//template <typename RealT>
std::string pad(float value, int padding){
real_generator<float, real6_policy<float> > pl;
return boost::lexical_cast<std::string>(format(left_align(padding, '0')[maxwidth(padding)[pl]], value));
}
std::string pad(double value, int padding){
real_generator<double, real6_policy<double> > pl;
return boost::lexical_cast<std::string>(format(left_align(padding, '0')[maxwidth(padding)[pl]], value));
}
}
}
}
#ifdef __GNUC__
#if __GNUC__ >= 4 && __GNUC_MINOR__ >= 6
#pragma GCC diagnostic pop
#elif __clang__
#pragma clang diagnostic pop
#endif
#endif
#endif /* MODULES_MISC_FORMATTING_HPP_ */