Classes | Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
Type Class Reference

Utilities related to std::type_info. More...

#include <Type.h>

Classes

struct  isEnum
 
struct  typeSetter
 

Public Member Functions

 Type (const Type &t)
 
template<class T >
 Type (const T &t)
 
template<class T >
void setType ()
 
template<class T >
void setType (const T &t)
 Set current type to t. More...
 
template<class T >
Typeoperator= (const T &t)
 
 operator const std::type_info & () const
 
 operator char () const
 
 operator std::string () const
 
const std::type_info & getType () const
 Deprecated! Use cast (above) instead?
 

Static Public Member Functions

static const std::type_info & getTypeInfo (char t)
 Returns the base type associated with a character key. More...
 
static char getTypeChar (const std::type_info &t)
 
template<class F , class T >
static T call (const std::type_info &t)
 Calls a static function that has no parameters. More...
 
template<class F , class D , class S >
static D call (const S &typeCode)
 New, preferred implementation: a single if-then structure once and for all. More...
 
template<class F , class S >
static F::value_t call (const S &typeCode)
 A shorthand for functors with a fixed return type, hence D = F::value_t. More...
 
template<class F , class T >
static void call (T &target, const std::type_info &t)
 Static function call without parameters on a single target of type T. More...
 
template<class F , class T , class T2 >
static void call (T &target, const T2 &t)
 Static function call with a single parameter. More...
 
static const std::type_info & getTypeInfo (const char *typeCode)
 Returns the type corresponding to a single-character string. More...
 
static const std::type_info & getTypeInfo (const std::string &typeCode)
 Returns the type corresponding to a single-character string. More...
 
static const std::type_info & getTypeInfo (const Type &t)
 Convenience. Purpose is to have a full set of getTypeInfo commands for templated constructs.
 
static std::ostream & toStream (std::ostream &ostr, const Type &t)
 Given a string, check if it could be stored as int or double instead of std::string . More...
 
static std::ostream & toStreamFull (std::ostream &ostr, const Type &t)
 

Protected Attributes

const std::type_info * currentType
 

Detailed Description

Utilities related to std::type_info.

Member Function Documentation

◆ call() [1/5]

static D call ( const S &  typeCode)
inlinestatic

New, preferred implementation: a single if-then structure once and for all.

Template Parameters
F- struct implementing: T callback<S>()
D- destination type
S- selector type (char, std::string, drain::Type)

◆ call() [2/5]

static F::value_t call ( const S &  typeCode)
inlinestatic

A shorthand for functors with a fixed return type, hence D = F::value_t.

Simpler template with two arguments

Template Parameters
F- struct implementing: T::callback<S>() AND value_t (replacing destination type S)
S- selector type (char, std::string, drain::Type)

◆ call() [3/5]

static T call ( const std::type_info &  t)
inlinestatic

Calls a static function that has no parameters.

Maps std::type_info to the corresponding template, calling a desired modifier function.

Template Parameters
F- struct with static method T callback<type>(), where type is a basetype or std::string.
T- return type

◆ call() [4/5]

static void call ( T &  target,
const std::type_info &  t 
)
inlinestatic

Static function call without parameters on a single target of type T.

Maps std::type_info to the corresponding template, calling a desired modifier function.

Template Parameters
F- struct that implements static void callback<type>(T & target), where <type> is basetype or std::string.
T- target object class

Example struct F:

class typesetter {
public:
// param S - target type
// param T - type to be analyzed
template <class S, class T>
static
void callback(T & target){
target.template setType<S>();
}
};
Type::call<typesetter>(obj, typeid(double));

◆ call() [5/5]

static void call ( T &  target,
const T2 &  t 
)
inlinestatic

Static function call with a single parameter.

Maps std::type_info to the corresponding template, calling a desired modifier function.

Template Parameters
F- struct that implements static callback<type>(T & target), where type is basetype or std::string.
T- target object class
T2- selector type (Type or typecode as char or string)

◆ getTypeInfo() [1/3]

static const std::type_info& getTypeInfo ( char  t)
inlinestatic

Returns the base type associated with a character key.

c - character for base types:
  • c - char
  • C - unsigned char
  • s - short
  • S - unsigned short
  • i - integer
  • I - unsigned integer
  • l - long int
  • L - unsigned long int
  • f - float
  • d - double
  • B - boolean
  • # - std::string ($)
  • * - void (identified with undefined type)

Notice that for integral types the signed and unsigned are denoted with uppercase and lowercase letters, respectivelty.

◆ getTypeInfo() [2/3]

static const std::type_info& getTypeInfo ( const char *  typeCode)
inlinestatic

Returns the type corresponding to a single-character string.

Checks that a single letter is given, and calls call(char);

◆ getTypeInfo() [3/3]

static const std::type_info& getTypeInfo ( const std::string &  typeCode)
inlinestatic

Returns the type corresponding to a single-character string.

Checks that a single letter is given, and calls call(char);

◆ setType()

void setType ( const T &  t)
inline

Set current type to t.

Template Parameters
T- type code: type_info, char, string or drain::Type.

◆ toStream()

static std::ostream& toStream ( std::ostream &  ostr,
const Type t 
)
inlinestatic

Given a string, check if it could be stored as int or double instead of std::string .

Returns
- std::type_info in priority order: int, double, std::string.

The documentation for this class was generated from the following file: