25 #ifndef _TABLE_CASTVISITOR_H 26 #define _TABLE_CASTVISITOR_H 31 #include <type_traits> 32 #include <boost/variant/static_visitor.hpp> 33 #include <boost/tokenizer.hpp> 40 template <
typename To>
45 template <
typename From>
50 template <
typename From>
53 <<
typeid(From).name() <<
" type to " <<
typeid(To).name();
63 template <
typename From>
73 class CastVisitor<double> :
public boost::static_visitor<double> {
75 template <
typename From>
76 static constexpr
bool generic() {
82 template <
typename From>
85 <<
typeid(From).name() <<
" type to " <<
typeid(double).name();
88 template <
typename From>
94 char *endptr =
nullptr;
96 if (endptr == from.
c_str()) {
98 << from <<
"' to " <<
typeid(double).name();
100 if (value == HUGE_VAL || value == -HUGE_VAL) {
102 << from <<
"' to " <<
typeid(double).name();
112 template <
typename From>
113 static constexpr
bool generic() {
120 template <
typename From>
121 double operator() (
const From& ,
typename std::enable_if<!generic<From>()>::type* = 0)
const {
123 <<
typeid(From).name() <<
" type to " <<
typeid(float).name();
126 template <
typename From>
127 float operator() (
const From& from,
typename std::enable_if<generic<From>()>::type* = 0)
const {
132 char *endptr =
nullptr;
134 if (endptr == from.
c_str()) {
136 << from <<
"' to " <<
typeid(float).name();
138 if (value == HUGE_VALF || value == -HUGE_VALF) {
140 << from <<
"' to " <<
typeid(float).name();
150 template <
typename From>
151 static constexpr
bool generic() {
157 template <
typename From>
158 double operator() (
const From& ,
typename std::enable_if<!generic<From>()>::type* = 0)
const {
160 <<
typeid(From).name() <<
" type to " <<
typeid(int64_t).name();
163 template <
typename From>
164 int64_t operator() (
const From& from,
typename std::enable_if<generic<From>()>::type* = 0)
const {
169 char *endptr =
nullptr;
171 if (endptr == from.
c_str()) {
173 << from <<
"' to " <<
typeid(int64_t).name();
183 template <
typename From>
184 static constexpr
bool generic() {
191 template <
typename From>
192 double operator() (
const From& ,
typename std::enable_if<!generic<From>()>::type* = 0)
const {
194 <<
typeid(From).name() <<
" type to " <<
typeid(int32_t).name();
197 template <
typename From>
198 int32_t operator() (
const From& from,
typename std::enable_if<generic<From>()>::type* = 0)
const {
203 char *endptr =
nullptr;
205 if (endptr == from.
c_str()) {
207 << from <<
"' to " <<
typeid(int32_t).name();
209 if (value > INT32_MAX || value < INT32_MIN) {
211 << from <<
"' to " <<
typeid(int32_t).name();
213 return static_cast<int32_t
>(value);
218 template <
typename VectorType>
223 template <
typename From>
230 template <
typename From>
233 for (
auto v : from) {
241 boost::char_separator<char> sep {
","};
242 boost::tokenizer< boost::char_separator<char> > tok {from, sep};
243 for (
auto&
s : tok) {
To operator()(const From &from, typename std::enable_if< std::is_same< From, To >::value >::type *=0) const