6 #ifndef TURI_TABLE_ELEMENT_PRINTERS_H_ 7 #define TURI_TABLE_ELEMENT_PRINTERS_H_ 9 #include <core/data/flexible_type/flexible_type.hpp> 10 #include <type_traits> 12 #include <core/parallel/atomic.hpp> 18 namespace table_internal {
23 void _format_time(std::stringstream& ts,
double t);
25 void _print_string(std::ostringstream& ss,
size_t width,
const std::string& s);
26 void _print_double(std::ostringstream& ss,
size_t width,
double s);
27 void _print_bool(std::ostringstream& ss,
size_t width,
bool b);
28 void _print_long(std::ostringstream& ss,
size_t width,
long v);
29 void _print_time(std::ostringstream& ss,
size_t width,
double pt);
30 void _print_flexible_type(std::ostringstream& ss,
size_t width,
const flexible_type& pt);
36 class table_printer_element_base {
38 enum class style_type : uint8_t {
44 virtual void print(std::ostringstream& ss,
size_t width){};
48 template <
typename T,
class Enable =
void>
49 struct table_printer_element :
public table_printer_element_base
51 static constexpr
bool valid_type =
false;
52 static constexpr style_type style = style_type::kDefault;
58 struct table_printer_element
59 <T, typename
std::enable_if<std::is_floating_point<T>::value>::type >
60 :
public table_printer_element_base {
63 static constexpr
bool valid_type =
true;
64 static constexpr style_type style = style_type::kDefault;
66 table_printer_element(T v)
70 void print(std::ostringstream& ss,
size_t width) {
71 _print_double(ss, width, value);
87 struct table_printer_element
88 <T, typename
std::enable_if<std::is_same<T, bool>::value>::type >
89 :
public table_printer_element_base {
91 static constexpr
bool valid_type =
true;
92 static constexpr style_type style = style_type::kBool;
94 table_printer_element(T v)
98 void print(std::ostringstream& ss,
size_t width) {
99 _print_bool(ss, width, value);
113 template <
typename T>
114 struct table_printer_element
115 <T, typename
std::enable_if< (std::is_integral<T>::value && (!std::is_same<T, bool>::value))>::type >
116 :
public table_printer_element_base {
118 static constexpr
bool valid_type =
true;
119 static constexpr style_type style = style_type::kDefault;
121 table_printer_element(
const T& v)
125 void print(std::ostringstream& ss,
size_t width) {
126 _print_long(ss, width, value);
139 template <
typename T>
140 struct table_printer_element
141 <
std::atomic<T>, typename std::enable_if<std::is_integral<T>::value>::type >
142 :
public table_printer_element<T> {
144 table_printer_element(
const std::atomic<T>& v)
145 : table_printer_element<T>(T(v))
151 template <
typename T>
152 struct table_printer_element
153 <
turi::atomic<T>, typename std::enable_if<std::is_integral<T>::value>::type >
154 :
public table_printer_element<T> {
156 table_printer_element(
const std::atomic<T>& v)
157 : table_printer_element<T>(T(v))
164 template <
typename T>
165 struct table_printer_element
166 <T, typename
std::enable_if<std::is_convertible<T, std::string>::value
167 && !std::is_same<T, flexible_type>::value>::type>
168 :
public table_printer_element_base {
171 static constexpr
bool valid_type =
true;
172 static constexpr style_type style = style_type::kDefault;
174 table_printer_element(
const T& v)
178 void print(std::ostringstream& ss,
size_t width) {
179 _print_string(ss, width, value);
192 template <
typename T>
193 struct table_printer_element
194 <T, typename
std::enable_if<std::is_same<T, progress_time>::value>::type>
195 :
public table_printer_element_base {
198 static constexpr
bool valid_type =
true;
199 static constexpr style_type style = style_type::kProgressTime;
201 table_printer_element(
double v)
205 void print(std::ostringstream& ss,
size_t width) {
206 _print_time(ss, width, value);
219 template <
typename T>
220 struct table_printer_element
221 <T, typename
std::enable_if<std::is_same<T, flexible_type>::value>::type >
222 :
public table_printer_element_base {
224 static constexpr
bool valid_type =
true;
225 static constexpr style_type style = style_type::kDefault;
227 table_printer_element(
const T& v)
231 void print(std::ostringstream& ss,
size_t width) {
232 _print_flexible_type(ss, width, value);
static flexible_type FLEX_UNDEFINED