32#ifndef DRAIN_TYPE_UTILS
33#define DRAIN_TYPE_UTILS
57 return static_cast<long int>(std::numeric_limits<S>::min());
61 unsigned long int getMaxI(){
62 return static_cast<unsigned long int>(std::numeric_limits<S>::max());
67 return static_cast<double>(std::numeric_limits<S>::max());
74template <>
inline unsigned long int typeLimits<void>::getMaxI(){
return 0l; }
75template <>
inline double typeLimits<void>::getMaxF(){
return 0.0; }
77template <>
inline long int typeLimits<std::string>::getMinI(){
return 0l; }
78template <>
inline unsigned long int typeLimits<std::string>::getMaxI(){
return 0l; }
79template <>
inline double typeLimits<std::string>::getMaxF(){
return 0.0; }
109 template <
class S,
class T>
112 if (std::numeric_limits<S>::is_integer)
128 template <
class S,
class T>
136 else if (x > maxValue)
147 template <
class S,
class T>
155 else if (x > maxValue)
173 const std::type_info &
guessType(
const std::string & value);
180 const std::type_info &
guessType(
double d,
const std::type_info & type =
typeid(
unsigned char));
197 template <
typename T,
typename S>
208 template <
typename S>
222 template <
typename T=
unsigned char>
235 const std::type_info &
minimizeIntType(
double value,
const std::type_info & type =
typeid(
unsigned char));
313 typedef std::set<const std::type_info *> typeset;
316 for (
typename C::const_iterator it = l.begin(); it != l.end(); ++it) {
321 if (s.find(&
typeid(std::string)) != s.end())
322 return typeid(std::string);
325 if (s.find(&
typeid(
double)) != s.end())
326 return typeid(
double);
328 if (s.find(&
typeid(
int)) != s.end())
332 if (s.find(&
typeid(
bool)) != s.end())
336 return typeid(std::string);
351 template <
class S,
class T>
354 target.template setType<S>();
372 typedef std::size_t value_t;
378 template <
class S,
class T>
381 return static_cast<T
>(getSize<S>());
397size_t sizeGetter::getSize<void>(){
417 typedef const std::string & value_t;
423 template <
class S,
class T>
427 static std::string s;
430 std::stringstream sstr;
431 size_t n = sizeGetter::callback<S, std::size_t>();
432 if (std::numeric_limits<S>::is_specialized){
433 if (std::numeric_limits<S>::is_integer){
434 if (!std::numeric_limits<S>::is_signed)
446 if (
typeid(S) ==
typeid(
bool))
468 typedef const std::string & value_t;
474 template <
class S,
class T>
479 static std::string s;
482 std::stringstream sstr;
483 size_t n = sizeGetter::callback<S, std::size_t>();
484 if (std::numeric_limits<S>::is_specialized){
485 if (std::numeric_limits<S>::is_integer){
486 if (std::numeric_limits<S>::is_signed)
500 if (
typeid(S) ==
typeid(
bool))
505 sstr <<
"non-numeric";
507 sstr <<
" (" << (8 * n) <<
"b)";
527 typedef const char * value_t;
529 template <
class S,
class T>
532 return typeid(S).name();
547 typedef bool value_t;
553 template <
class S,
class T>
555 T
callback(){
return std::is_fundamental<S>::value; }
566 typedef bool value_t;
572 template <
class S,
class T>
575 return static_cast<T
>( std::numeric_limits<S>::is_signed);
592 typedef bool value_t;
598 template <
class S,
class T>
600 T
callback(){
return std::numeric_limits<S>::is_specialized; }
613 typedef bool value_t;
619 template <
class S,
class T>
621 T
callback(){
return std::numeric_limits<S>::is_integer; }
634 typedef bool value_t;
640 template <
class S,
class T>
643 return (
typeid(S)==
typeid(
float)) || (
typeid(S)==
typeid(
double));
662 typedef bool value_t;
668 template <
class S,
class D>
671 return (
typeid(S) ==
typeid(
char)) || (
typeid(S) ==
typeid(
unsigned char)) || (
typeid(S) ==
typeid(short)) || (
typeid(S) ==
typeid(
unsigned short));
695 template <
class S,
class D>
698 if (std::numeric_limits<S>::is_integer)
723 template <
class S,
class D>
726 if (std::numeric_limits<S>::is_integer)
746 typedef double value_t;
752 template <
class S,
class D>
755 if (typeIsSmallInt::callback<S,bool>())
758 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:224
Returns the basic type (integer, float, bool, string, void) as a string.
Definition TypeUtils.h:413
static T callback()
Definition TypeUtils.h:425
Definition TypeUtils.h:463
static T callback()
Definition TypeUtils.h:476
Definition TypeUtils.h:562
static T callback()
Definition TypeUtils.h:574
Returns the compiler specific ie. non-standard name of the type.
Definition TypeUtils.h:523
Returns the sizeof() of a type. Accepts void (and returns size 0), which is not supported by std::num...
Definition TypeUtils.h:368
static T callback()
Definition TypeUtils.h:380
Definition TypeUtils.h:630
static T callback()
Definition TypeUtils.h:642
Definition TypeUtils.h:543
static T callback()
Definition TypeUtils.h:555
Definition TypeUtils.h:609
static T callback()
Definition TypeUtils.h:621
Checks if type is numeric.
Definition TypeUtils.h:588
static T callback()
Definition TypeUtils.h:600
The maximum value of a type given as type_info, char or std::string.
Definition TypeUtils.h:658
static D callback()
Definition TypeUtils.h:670
Class for ensuring that variable of type D remains within limits of type S.
Definition TypeUtils.h:98
static T limitFloat(T x)
Definition TypeUtils.h:149
static T limitInteger(T x)
Definition TypeUtils.h:130
D(* value_t)(D)
Definition that simplifies.
Definition TypeUtils.h:103
static T callback()
Definition TypeUtils.h:111
The maximum value of a type given as type_info, char or std::string.
Definition TypeUtils.h:713
static D callback()
Definition TypeUtils.h:725
The minimum value of a type given as type_info, char or std::string.
Definition TypeUtils.h:685
static D callback()
Definition TypeUtils.h:697
The maximum value of a.
Definition TypeUtils.h:742
static D callback()
Definition TypeUtils.h:754
Utility for implementing setType(const std::type_info &t) in classes supporting setType<T>().
Definition TypeUtils.h:344
static void callback(T &target)
Definition TypeUtils.h:353
Definition DataSelector.cpp:1277
Definition TypeUtils.h:165
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:310
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:224
static bool isWithinRange(const S &x, const std::type_info &type)
Definition TypeUtils.h:210
static bool isWithinRange(const S &x)
Definition TypeUtils.h:199
Definition TypeUtils.h:53