All Classes Files Functions Variables Typedefs Pages
RepCommon.hpp
Go to the documentation of this file.
1 #pragma once
2 
13 #include <string>
14 
15 namespace lumina {
16 
17 class half;
18 namespace internal {
30 template <typename T>
31 typename std::enable_if<std::is_integral<T>::value, std::string>::type
32 numberToRep(T in) {
33  return std::to_string(in);
34 }
35 
36 template <typename T>
37 typename std::enable_if<std::is_floating_point<T>::value
38  && !std::is_same<T, half>::value,
39  std::string>::type
40 numberToRep(T in) {
41  char buf[20];
42  std::snprintf(buf, 20, "%g", in);
43  return std::string(buf);
44 }
45 
46 template <typename T>
47 typename std::enable_if<std::is_same<T, half>::value, std::string>::type
48 numberToRep(T in) {
49  return numberToRep(static_cast<float>(in));
50 }
51 
52 // void numberToRep(half in) {
53 // char buf[20];
54 // std::snprintf(buf, 20, "%g", in);
55 // return std::string(buf);
56 // }
57 
58 template <typename T>
59 typename std::enable_if<!std::is_arithmetic<T>::value, std::string>::type
60 numberToRep(const T& in) {
61  return static_cast<std::string>(in);
62 }
63 
64 
65 template <typename T> const char* typeCharRep() { return "?"; }
66 template <> constexpr const char* typeCharRep<int>() { return "i"; }
67 template <> constexpr const char* typeCharRep<unsigned int>() { return "ui"; }
68 template <> constexpr const char* typeCharRep<float>() { return "f"; }
69 template <> constexpr const char* typeCharRep<double>() { return "d"; }
70 
71 
72 }
73 }