32 #ifndef DRAIN_TYPE_UTILS
33 #define DRAIN_TYPE_UTILS
54 const std::type_info &
guessType(
const std::string & value);
84 typedef std::set<const std::type_info *> typeset;
87 for (
typename C::const_iterator it = l.begin(); it != l.end(); ++it) {
92 if (s.find(&
typeid(std::string)) != s.end())
93 return typeid(std::string);
96 if (s.find(&
typeid(
double)) != s.end())
97 return typeid(
double);
99 if (s.find(&
typeid(
int)) != s.end())
103 if (s.find(&
typeid(
bool)) != s.end())
107 return typeid(std::string);
121 template <
class S,
class T>
124 target.template setType<S>();
142 typedef std::size_t value_t;
148 template <
class S,
class T>
151 return static_cast<T
>(getSize<S>());
167 size_t sizeGetter::getSize<void>(){
223 typedef const std::string & value_t;
229 template <
class S,
class T>
233 static std::string s;
236 std::stringstream sstr;
237 size_t n = sizeGetter::callback<S, std::size_t>();
238 if (std::numeric_limits<S>::is_specialized){
239 if (std::numeric_limits<S>::is_integer){
240 if (!std::numeric_limits<S>::is_signed)
252 if (
typeid(S) ==
typeid(
bool))
274 typedef const std::string & value_t;
280 template <
class S,
class T>
285 static std::string s;
288 std::stringstream sstr;
289 size_t n = sizeGetter::callback<S, std::size_t>();
290 if (std::numeric_limits<S>::is_specialized){
291 if (std::numeric_limits<S>::is_integer){
292 if (std::numeric_limits<S>::is_signed)
306 if (
typeid(S) ==
typeid(
bool))
311 sstr <<
"non-numeric";
313 sstr <<
" (" << (8 * n) <<
"b)";
368 typedef const char * value_t;
370 template <
class S,
class T>
373 return typeid(S).name();
388 typedef bool value_t;
394 template <
class S,
class T>
396 T
callback(){
return std::is_fundamental<S>::value; }
407 typedef bool value_t;
413 template <
class S,
class T>
416 return static_cast<T
>( std::numeric_limits<S>::is_signed);
433 typedef bool value_t;
439 template <
class S,
class T>
441 T
callback(){
return std::numeric_limits<S>::is_specialized; }
454 typedef bool value_t;
460 template <
class S,
class T>
462 T
callback(){
return std::numeric_limits<S>::is_integer; }
475 typedef bool value_t;
481 template <
class S,
class T>
484 return (
typeid(S)==
typeid(
float)) || (
typeid(S)==
typeid(
double));
503 typedef bool value_t;
509 template <
class S,
class D>
512 return (
typeid(S) ==
typeid(
char)) || (
typeid(S) ==
typeid(
unsigned char)) || (
typeid(S) ==
typeid(short)) || (
typeid(S) ==
typeid(
unsigned short));
526 return static_cast<long int>(std::numeric_limits<S>::min());
530 unsigned long int getMaxI(){
531 return static_cast<unsigned long int>(std::numeric_limits<S>::max());
536 return static_cast<double>(std::numeric_limits<S>::max());
543 template <>
inline unsigned long int typeLimits<void>::getMaxI(){
return 0l; }
544 template <>
inline double typeLimits<void>::getMaxF(){
return 0.0; }
546 template <>
inline long int typeLimits<std::string>::getMinI(){
return 0l; }
547 template <>
inline unsigned long int typeLimits<std::string>::getMaxI(){
return 0l; }
548 template <>
inline double typeLimits<std::string>::getMaxF(){
return 0.0; }
568 template <
class S,
class D>
571 if (std::numeric_limits<S>::is_integer)
596 template <
class S,
class D>
599 if (std::numeric_limits<S>::is_integer)
619 typedef double value_t;
625 template <
class S,
class D>
628 if (typeIsSmallInt::callback<S,bool>())
631 return static_cast<D
>(1.0);
664 template <
class S,
class T>
667 if (std::numeric_limits<S>::is_integer)
683 template <
class S,
class T>
691 else if (x > maxValue)
702 template <
class S,
class T>
710 else if (x > maxValue)
Returns the basic type (integer, float, bool, string, void) as a string.
Definition: TypeUtils.h:219
static T callback()
Definition: TypeUtils.h:231
Definition: TypeUtils.h:269
static T callback()
Definition: TypeUtils.h:282
Definition: TypeUtils.h:403
static T callback()
Definition: TypeUtils.h:415
Returns the sizeof() of a type. Accepts void (and returns size 0), which is not supported by std::num...
Definition: TypeUtils.h:138
static T callback()
Definition: TypeUtils.h:150
Definition: TypeUtils.h:471
static T callback()
Definition: TypeUtils.h:483
Definition: TypeUtils.h:384
static T callback()
Definition: TypeUtils.h:396
Definition: TypeUtils.h:450
static T callback()
Definition: TypeUtils.h:462
Checks if type is numeric.
Definition: TypeUtils.h:429
static T callback()
Definition: TypeUtils.h:441
The maximum value of a type given as type_info, char or std::string.
Definition: TypeUtils.h:499
static D callback()
Definition: TypeUtils.h:511
Class for ensuring that variable of type D remains within limits of type S.
Definition: TypeUtils.h:653
static T limitFloat(T x)
Definition: TypeUtils.h:704
static T limitInteger(T x)
Definition: TypeUtils.h:685
D(* value_t)(D)
Definition that simplifies.
Definition: TypeUtils.h:658
static T callback()
Definition: TypeUtils.h:666
The maximum value of a type given as type_info, char or std::string.
Definition: TypeUtils.h:586
static D callback()
Definition: TypeUtils.h:598
The minimum value of a type given as type_info, char or std::string.
Definition: TypeUtils.h:558
static D callback()
Definition: TypeUtils.h:570
The maximum value of a.
Definition: TypeUtils.h:615
static D callback()
Definition: TypeUtils.h:627
Utility for implementing setType(const std::type_info &t) in classes supporting setType<T>().
Definition: TypeUtils.h:114
static void callback(T &target)
Definition: TypeUtils.h:123
Definition: DataSelector.cpp:1277
Definition: TypeUtils.h:46
static const std::type_info & guessArrayType(const C &container)
Given a vector or list of strings, suggest a matching storage type (int, double, std::string).
Definition: TypeUtils.h:81
static const std::type_info & guessType(const std::string &value)
Given a string, check if it could be stored as int or double instead of std::string .
Definition: TypeUtils.cpp:49
Definition: TypeUtils.h:522