32#ifndef DRAIN_TYPE_UTILS
33#define DRAIN_TYPE_UTILS
55 return static_cast<long int>(std::numeric_limits<S>::min());
59 unsigned long int getMaxI(){
60 return static_cast<unsigned long int>(std::numeric_limits<S>::max());
65 return static_cast<double>(std::numeric_limits<S>::max());
72template <>
inline unsigned long int typeLimits<void>::getMaxI(){
return 0l; }
73template <>
inline double typeLimits<void>::getMaxF(){
return 0.0; }
75template <>
inline long int typeLimits<std::string>::getMinI(){
return 0l; }
76template <>
inline unsigned long int typeLimits<std::string>::getMaxI(){
return 0l; }
77template <>
inline double typeLimits<std::string>::getMaxF(){
return 0.0; }
107 template <
class S,
class T>
110 if (std::numeric_limits<S>::is_integer)
126 template <
class S,
class T>
134 else if (x > maxValue)
145 template <
class S,
class T>
153 else if (x > maxValue)
171 const std::type_info &
guessType(
const std::string & value);
178 const std::type_info &
guessType(
double d,
const std::type_info & type =
typeid(
unsigned char));
195 template <
typename T,
typename S>
206 template <
typename S>
220 template <
typename T=
unsigned char>
233 const std::type_info &
minimizeIntType(
double value,
const std::type_info & type =
typeid(
unsigned char));
311 typedef std::set<const std::type_info *> typeset;
314 for (
typename C::const_iterator it = l.begin(); it != l.end(); ++it) {
319 if (s.find(&
typeid(std::string)) != s.end())
320 return typeid(std::string);
323 if (s.find(&
typeid(
double)) != s.end())
324 return typeid(
double);
326 if (s.find(&
typeid(
int)) != s.end())
330 if (s.find(&
typeid(
bool)) != s.end())
334 return typeid(std::string);
348 template <
class S,
class T>
351 target.template setType<S>();
369 typedef std::size_t value_t;
375 template <
class S,
class T>
378 return static_cast<T
>(getSize<S>());
394size_t sizeGetter::getSize<void>(){
414 typedef const std::string & value_t;
420 template <
class S,
class T>
424 static std::string s;
427 std::stringstream sstr;
428 size_t n = sizeGetter::callback<S, std::size_t>();
429 if (std::numeric_limits<S>::is_specialized){
430 if (std::numeric_limits<S>::is_integer){
431 if (!std::numeric_limits<S>::is_signed)
443 if (
typeid(S) ==
typeid(
bool))
465 typedef const std::string & value_t;
471 template <
class S,
class T>
476 static std::string s;
479 std::stringstream sstr;
480 size_t n = sizeGetter::callback<S, std::size_t>();
481 if (std::numeric_limits<S>::is_specialized){
482 if (std::numeric_limits<S>::is_integer){
483 if (std::numeric_limits<S>::is_signed)
497 if (
typeid(S) ==
typeid(
bool))
502 sstr <<
"non-numeric";
504 sstr <<
" (" << (8 * n) <<
"b)";
524 typedef const char * value_t;
526 template <
class S,
class T>
529 return typeid(S).name();
544 typedef bool value_t;
550 template <
class S,
class T>
552 T
callback(){
return std::is_fundamental<S>::value; }
563 typedef bool value_t;
569 template <
class S,
class T>
572 return static_cast<T
>( std::numeric_limits<S>::is_signed);
589 typedef bool value_t;
595 template <
class S,
class T>
597 T
callback(){
return std::numeric_limits<S>::is_specialized; }
610 typedef bool value_t;
616 template <
class S,
class T>
618 T
callback(){
return std::numeric_limits<S>::is_integer; }
631 typedef bool value_t;
637 template <
class S,
class T>
640 return (
typeid(S)==
typeid(
float)) || (
typeid(S)==
typeid(
double));
659 typedef bool value_t;
665 template <
class S,
class D>
668 return (
typeid(S) ==
typeid(
char)) || (
typeid(S) ==
typeid(
unsigned char)) || (
typeid(S) ==
typeid(short)) || (
typeid(S) ==
typeid(
unsigned short));
692 template <
class S,
class D>
695 if (std::numeric_limits<S>::is_integer)
720 template <
class S,
class D>
723 if (std::numeric_limits<S>::is_integer)
743 typedef double value_t;
749 template <
class S,
class D>
752 if (typeIsSmallInt::callback<S,bool>())
755 return static_cast<D
>(1.0);
static T call(const std::type_info &t)
Calls a static function that has no parameters.
Definition Type.h:223
Returns the basic type (integer, float, bool, string, void) as a string.
Definition TypeUtils.h:410
static T callback()
Definition TypeUtils.h:422
Definition TypeUtils.h:460
static T callback()
Definition TypeUtils.h:473
Definition TypeUtils.h:559
static T callback()
Definition TypeUtils.h:571
Returns the compiler specific ie. non-standard name of the type.
Definition TypeUtils.h:520
Returns the sizeof() of a type. Accepts void (and returns size 0), which is not supported by std::num...
Definition TypeUtils.h:365
static T callback()
Definition TypeUtils.h:377
Definition TypeUtils.h:627
static T callback()
Definition TypeUtils.h:639
Definition TypeUtils.h:540
static T callback()
Definition TypeUtils.h:552
Definition TypeUtils.h:606
static T callback()
Definition TypeUtils.h:618
Checks if type is numeric.
Definition TypeUtils.h:585
static T callback()
Definition TypeUtils.h:597
The maximum value of a type given as type_info, char or std::string.
Definition TypeUtils.h:655
static D callback()
Definition TypeUtils.h:667
Class for ensuring that variable of type D remains within limits of type S.
Definition TypeUtils.h:96
static T limitFloat(T x)
Definition TypeUtils.h:147
static T limitInteger(T x)
Definition TypeUtils.h:128
D(* value_t)(D)
Definition that simplifies.
Definition TypeUtils.h:101
static T callback()
Definition TypeUtils.h:109
The maximum value of a type given as type_info, char or std::string.
Definition TypeUtils.h:710
static D callback()
Definition TypeUtils.h:722
The minimum value of a type given as type_info, char or std::string.
Definition TypeUtils.h:682
static D callback()
Definition TypeUtils.h:694
The maximum value of a.
Definition TypeUtils.h:739
static D callback()
Definition TypeUtils.h:751
Utility for implementing setType(const std::type_info &t) in classes supporting setType<T>().
Definition TypeUtils.h:341
static void callback(T &target)
Definition TypeUtils.h:350
Definition DataSelector.cpp:1277
Definition TypeUtils.h:163
static const std::type_info & guessType(double d, const std::type_info &type=typeid(unsigned char))
Returns the (loosely) minimal type that could store the value without precision loss.
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:308
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:52
static const std::type_info & minimizeIntType(double value)
Return a minimal numeric type, that can contain a numeric value.
Definition TypeUtils.h:222
static bool isWithinRange(const S &x, const std::type_info &type)
Definition TypeUtils.h:208
static bool isWithinRange(const S &x)
Definition TypeUtils.h:197
Definition TypeUtils.h:51