32#ifndef DRAIN_TYPE_UTILS
33#define DRAIN_TYPE_UTILS
59 return static_cast<long int>(std::numeric_limits<S>::min());
63 unsigned long int getMaxI(){
64 return static_cast<unsigned long int>(std::numeric_limits<S>::max());
69 return static_cast<double>(std::numeric_limits<S>::max());
76template <>
inline unsigned long int typeLimits<void>::getMaxI(){
return 0l; }
77template <>
inline double typeLimits<void>::getMaxF(){
return 0.0; }
79template <>
inline long int typeLimits<std::string>::getMinI(){
return 0l; }
80template <>
inline unsigned long int typeLimits<std::string>::getMaxI(){
return 0l; }
81template <>
inline double typeLimits<std::string>::getMaxF(){
return 0.0; }
111 template <
class S,
class T>
114 if (std::numeric_limits<S>::is_integer)
130 template <
class S,
class T>
138 else if (x > maxValue)
149 template <
class S,
class T>
157 else if (x > maxValue)
175 const std::type_info &
guessType(
const std::string & value);
182 const std::type_info &
guessType(
double d,
const std::type_info & type =
typeid(
unsigned char));
199 template <
typename T,
typename S>
210 template <
typename S>
224 template <
typename T=
unsigned char>
237 const std::type_info &
minimizeIntType(
double value,
const std::type_info & type =
typeid(
unsigned char));
315 typedef std::set<const std::type_info *> typeset;
318 for (
typename C::const_iterator it = l.begin(); it != l.end(); ++it) {
323 if (s.find(&
typeid(std::string)) != s.end())
324 return typeid(std::string);
327 if (s.find(&
typeid(
double)) != s.end())
328 return typeid(
double);
330 if (s.find(&
typeid(
int)) != s.end())
334 if (s.find(&
typeid(
bool)) != s.end())
338 return typeid(std::string);
352 template <
class S,
class T>
355 target.template setType<S>();
373 typedef std::size_t value_t;
379 template <
class S,
class T>
382 return static_cast<T
>(getSize<S>());
398size_t sizeGetter::getSize<void>(){
418 typedef const std::string & value_t;
424 template <
class S,
class T>
428 static std::string s;
431 std::stringstream sstr;
432 size_t n = sizeGetter::callback<S, std::size_t>();
433 if (std::numeric_limits<S>::is_specialized){
434 if (std::numeric_limits<S>::is_integer){
435 if (!std::numeric_limits<S>::is_signed)
447 if (
typeid(S) ==
typeid(
bool))
469 typedef const std::string & value_t;
475 template <
class S,
class T>
480 static std::string s;
483 std::stringstream sstr;
484 size_t n = sizeGetter::callback<S, std::size_t>();
485 if (std::numeric_limits<S>::is_specialized){
486 if (std::numeric_limits<S>::is_integer){
487 if (std::numeric_limits<S>::is_signed)
501 if (
typeid(S) ==
typeid(
bool))
506 sstr <<
"non-numeric";
508 sstr <<
" (" << (8 * n) <<
"b)";
528 typedef const char * value_t;
530 template <
class S,
class T>
533 return typeid(S).name();
548 typedef bool value_t;
554 template <
class S,
class T>
556 T
callback(){
return std::is_fundamental<S>::value; }
567 typedef bool value_t;
573 template <
class S,
class T>
576 return static_cast<T
>( std::numeric_limits<S>::is_signed);
593 typedef bool value_t;
599 template <
class S,
class T>
601 T
callback(){
return std::numeric_limits<S>::is_specialized; }
614 typedef bool value_t;
620 template <
class S,
class T>
622 T
callback(){
return std::numeric_limits<S>::is_integer; }
635 typedef bool value_t;
641 template <
class S,
class T>
644 return (
typeid(S)==
typeid(
float)) || (
typeid(S)==
typeid(
double));
663 typedef bool value_t;
669 template <
class S,
class D>
672 return (
typeid(S) ==
typeid(
char)) || (
typeid(S) ==
typeid(
unsigned char)) || (
typeid(S) ==
typeid(short)) || (
typeid(S) ==
typeid(
unsigned short));
696 template <
class S,
class D>
699 if (std::numeric_limits<S>::is_integer)
724 template <
class S,
class D>
727 if (std::numeric_limits<S>::is_integer)
747 typedef double value_t;
753 template <
class S,
class D>
756 if (typeIsSmallInt::callback<S,bool>())
759 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:222
Returns the basic type (integer, float, bool, string, void) as a string.
Definition TypeUtils.h:414
static T callback()
Definition TypeUtils.h:426
Definition TypeUtils.h:464
static T callback()
Definition TypeUtils.h:477
Definition TypeUtils.h:563
static T callback()
Definition TypeUtils.h:575
Returns the compiler specific ie. non-standard name of the type.
Definition TypeUtils.h:524
Returns the sizeof() of a type. Accepts void (and returns size 0), which is not supported by std::num...
Definition TypeUtils.h:369
static T callback()
Definition TypeUtils.h:381
Definition TypeUtils.h:631
static T callback()
Definition TypeUtils.h:643
Definition TypeUtils.h:544
static T callback()
Definition TypeUtils.h:556
Definition TypeUtils.h:610
static T callback()
Definition TypeUtils.h:622
Checks if type is numeric.
Definition TypeUtils.h:589
static T callback()
Definition TypeUtils.h:601
The maximum value of a type given as type_info, char or std::string.
Definition TypeUtils.h:659
static D callback()
Definition TypeUtils.h:671
Class for ensuring that variable of type D remains within limits of type S.
Definition TypeUtils.h:100
static T limitFloat(T x)
Definition TypeUtils.h:151
static T limitInteger(T x)
Definition TypeUtils.h:132
D(* value_t)(D)
Definition that simplifies.
Definition TypeUtils.h:105
static T callback()
Definition TypeUtils.h:113
The maximum value of a type given as type_info, char or std::string.
Definition TypeUtils.h:714
static D callback()
Definition TypeUtils.h:726
The minimum value of a type given as type_info, char or std::string.
Definition TypeUtils.h:686
static D callback()
Definition TypeUtils.h:698
The maximum value of a.
Definition TypeUtils.h:743
static D callback()
Definition TypeUtils.h:755
Utility for implementing setType(const std::type_info &t) in classes supporting setType<T>().
Definition TypeUtils.h:345
static void callback(T &target)
Definition TypeUtils.h:354
Definition DataSelector.cpp:1277
Definition TypeUtils.h:167
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:312
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:226
static bool isWithinRange(const S &x, const std::type_info &type)
Definition TypeUtils.h:212
static bool isWithinRange(const S &x)
Definition TypeUtils.h:201
Definition TypeUtils.h:55