25#ifndef _TABLE_CASTVISITOR_H
26#define _TABLE_CASTVISITOR_H
29#include <boost/tokenizer.hpp>
30#include <boost/variant/static_visitor.hpp>
44 template <
typename From>
49 template <
typename From>
51 throw Elements::Exception() <<
"CastVisitor cannot convert " <<
typeid(From).name() <<
" type to "
68 while (it != v.
end()) {
75 template <
typename From>
84class CastVisitor<double> :
public boost::static_visitor<double> {
86 template <
typename From>
87 static constexpr bool generic() {
92 template <
typename From>
94 throw Elements::Exception() <<
"CastVisitor cannot convert " <<
typeid(From).name() <<
" type to "
95 <<
typeid(double).name();
98 template <
typename From>
104 char* endptr =
nullptr;
106 if (endptr == from.
c_str()) {
107 throw Elements::Exception() <<
"CastVisitor cannot convert the string '" << from <<
"' to "
108 <<
typeid(double).name();
110 if (value == HUGE_VAL || value == -HUGE_VAL) {
111 throw Elements::Exception() <<
"CastVisitor overflows converting the string '" << from <<
"' to "
112 <<
typeid(double).name();
121 template <
typename From>
122 static constexpr bool generic() {
128 template <
typename From>
130 throw Elements::Exception() <<
"CastVisitor cannot convert " <<
typeid(From).name() <<
" type to "
131 <<
typeid(float).name();
134 template <
typename From>
140 char* endptr =
nullptr;
142 if (endptr == from.
c_str()) {
143 throw Elements::Exception() <<
"CastVisitor cannot convert the string '" << from <<
"' to "
144 <<
typeid(float).name();
146 if (value == HUGE_VALF || value == -HUGE_VALF) {
147 throw Elements::Exception() <<
"CastVisitor overflows converting the string '" << from <<
"' to "
148 <<
typeid(float).name();
155class CastVisitor<int64_t> :
public boost::static_visitor<int64_t> {
157 template <
typename From>
158 static constexpr bool generic() {
163 template <
typename From>
165 throw Elements::Exception() <<
"CastVisitor cannot convert " <<
typeid(From).name() <<
" type to "
166 <<
typeid(int64_t).name();
169 template <
typename From>
175 char* endptr =
nullptr;
177 if (endptr == from.
c_str()) {
178 throw Elements::Exception() <<
"CastVisitor cannot convert the string '" << from <<
"' to "
179 <<
typeid(int64_t).name();
186class CastVisitor<int32_t> :
public boost::static_visitor<int32_t> {
188 template <
typename From>
189 static constexpr bool generic() {
195 template <
typename From>
197 throw Elements::Exception() <<
"CastVisitor cannot convert " <<
typeid(From).name() <<
" type to "
198 <<
typeid(int32_t).name();
201 template <
typename From>
207 char* endptr =
nullptr;
209 if (endptr == from.
c_str()) {
210 throw Elements::Exception() <<
"CastVisitor cannot convert the string '" << from <<
"' to "
211 <<
typeid(int32_t).name();
213 if (value > INT32_MAX || value < INT32_MIN) {
214 throw Elements::Exception() <<
"CastVisitor overflows converting the string '" << from <<
"' to "
215 <<
typeid(int32_t).name();
217 return static_cast<int32_t
>(value);
221template <
typename VectorType>
222class CastVisitor<
std::vector<VectorType>> :
public boost::static_visitor<std::vector<VectorType>> {
225 template <
typename From>
232 template <
typename From>
235 for (
auto v : from) {
243 boost::char_separator<char> sep{
","};
244 boost::tokenizer<boost::char_separator<char>> tok{from, sep};
245 for (
auto& s : tok) {
double operator()(const From &, typename std::enable_if<!generic< From >()>::type *=0) const
double operator()(const std::string &from) const
double operator()(const From &from, typename std::enable_if< generic< From >()>::type *=0) const
float operator()(const From &from, typename std::enable_if< generic< From >()>::type *=0) const
double operator()(const From &, typename std::enable_if<!generic< From >()>::type *=0) const
float operator()(const std::string &from) const
double operator()(const From &, typename std::enable_if<!generic< From >()>::type *=0) const
int32_t operator()(const std::string &from) const
int32_t operator()(const From &from, typename std::enable_if< generic< From >()>::type *=0) const
int64_t operator()(const std::string &from) const
int64_t operator()(const From &from, typename std::enable_if< generic< From >()>::type *=0) const
double operator()(const From &, typename std::enable_if<!generic< From >()>::type *=0) const
std::string operator()(const std::vector< T > &v) const
std::string operator()(const From &from) const
std::vector< VectorType > operator()(const std::string &from) const
std::vector< VectorType > operator()(const std::vector< From > &from) const
std::vector< VectorType > operator()(const From &from) const
const std::vector< VectorType > & operator()(const std::vector< VectorType > &from) const
To operator()(const From &, typename std::enable_if<!std::is_same< From, To >::value >::type *=0) const
To operator()(const From &from, typename std::enable_if< std::is_same< From, To >::value >::type *=0) const