56 Type() : currentType(&
typeid(
void)) {
60 Type(
const Type & t) : currentType(t.currentType) {
65 Type(
const T & t) : currentType(&
typeid(
void)){
74 currentType = &
typeid(T);
85 call<typeSetter>(*
this, t);
91 Type & operator=(
const T & t){
97 operator const std::type_info & ()
const {
return (*currentType); }
100 operator char ()
const {
return getTypeChar(*currentType); }
103 operator std::string ()
const {
return std::string(1, getTypeChar(*currentType)); }
141 return typeid(
unsigned char);
143 return typeid(short);
145 return typeid(
unsigned short);
149 return typeid(
unsigned int);
153 return typeid(
unsigned long);
155 return typeid(float);
157 return typeid(double);
162 return typeid(std::string);
169 std::cerr << __FILE__ <<
' ' << __FUNCTION__ <<
" undefined type: '" << t <<
"'=" << (int)t << std::endl;
171 throw std::runtime_error(
"undefined type");
179 char getTypeChar(
const std::type_info & t){
180 if (t ==
typeid(
char))
182 else if (t ==
typeid(
unsigned char))
184 else if (t ==
typeid(
short))
186 else if (t ==
typeid(
unsigned short))
188 else if (t ==
typeid(
int))
190 else if (t ==
typeid(
unsigned int))
192 else if (t ==
typeid(
long))
194 else if (t ==
typeid(
unsigned long))
196 else if (t ==
typeid(
float))
198 else if (t ==
typeid(
double))
200 else if (t ==
typeid(
bool))
202 else if (t ==
typeid(
void))
204 else if (t ==
typeid(std::string))
206 else if (t ==
typeid(
const char *))
208 else if (t ==
typeid(
char *))
222 template <
class F,
class T>
224 T
call(
const std::type_info & t){
228 if (t ==
typeid(
char)){
229 return F::template callback<char,T>();
231 else if (t ==
typeid(
unsigned char)) {
232 return F::template callback<unsigned char,T>();
234 else if (t ==
typeid(
int)) {
235 return F::template callback<int,T>();
237 else if (t ==
typeid(
unsigned int)) {
238 return F::template callback<unsigned int,T>();
240 else if (t ==
typeid(
short int)) {
241 return F::template callback<short int,T>();
243 else if (t ==
typeid(
unsigned short int)) {
244 return F::template callback<unsigned short int,T>();
246 else if (t ==
typeid(
long int)) {
247 return F::template callback<long int,T>();
249 else if (t ==
typeid(
unsigned long int)) {
250 return F::template callback<unsigned long int,T>();
252 else if (t ==
typeid(
float)) {
253 return F::template callback<float,T>();
255 else if (t ==
typeid(
double)) {
256 return F::template callback<double,T>();
258 else if (t ==
typeid(
bool)) {
259 return F::template callback<bool,T>();
261 else if (t ==
typeid(
void)) {
262 return F::template callback<void,T>();
264 else if (t ==
typeid(std::string)) {
265 return F::template callback<std::string,T>();
274 std::cerr << __FILE__ <<
' ' << __FUNCTION__ <<
"unimplemented type: ..." << t.name() << std::endl;
276 throw std::runtime_error(
"unimplemented type: ...");
281 return F::template callback<char,T>();
292 template <
class F,
class D,
class S>
305 template <
class F,
class S>
307 typename F::value_t
call(
const S & typeCode){
308 return call<F,typename F::value_t>(
getTypeInfo(typeCode));
339 template <
class F,
class T>
341 void call(T & target,
const std::type_info &t){
343 if (t ==
typeid(
char))
344 F::template callback<char>(target);
345 else if (t ==
typeid(
unsigned char))
346 F::template callback<unsigned char>(target);
347 else if (t ==
typeid(
int))
348 F::template callback<int>(target);
349 else if (t ==
typeid(
unsigned int))
350 F::template callback<unsigned int>(target);
351 else if (t ==
typeid(
short))
352 F::template callback<short>(target);
353 else if (t ==
typeid(
unsigned short))
354 F::template callback<unsigned short>(target);
355 else if (t ==
typeid(
long))
356 F::template callback<long>(target);
357 else if (t ==
typeid(
unsigned long))
358 F::template callback<unsigned long>(target);
359 else if (t ==
typeid(
float))
360 F::template callback<float>(target);
361 else if (t ==
typeid(
double))
362 F::template callback<double>(target);
363 else if (t ==
typeid(
bool))
364 F::template callback<bool>(target);
365 else if (t ==
typeid(std::string))
366 F::template callback<std::string>(target);
367 else if (t ==
typeid(
void)) {
368 F::template callback<void>(target);
376 std::cerr << __FILE__ <<
' ' << __FUNCTION__ <<
"unimplemented type: ..." << t.name() << std::endl;
378 throw std::runtime_error(
"unimplemented type: ...");
397 template <
class F,
class T,
class T2>
399 void call(T & target,
const T2 &t){
412 if ((typeCode != NULL) && (*typeCode !=
'\0'))
414 else if (typeCode == NULL)
417 throw std::runtime_error(std::string(
"Type::operator=, not unit-length std::string: ") + typeCode);
427 if (typeCode.length() == 1)
429 else if (typeCode.empty())
432 throw std::runtime_error(std::string(
"Type::operator=, not unit-length std::string: ") + typeCode);
461 const std::type_info & guessArrayType(const C & container);
466 const std::type_info & type = t.
getType();
467 ostr << Type::getTypeChar(type) <<
'@';
472 std::ostream & toStreamFull(std::ostream & ostr,
const Type &t){
487 typedef bool value_t;
493 template <
class S,
class T>
496 return std::is_enum<S>::value;
531 template <
class S,
class T>
534 target.template setType<S>();
538 const std::type_info *currentType;
545std::ostream & operator<<(std::ostream & ostr,
const Type &t){
561 typedef std::string value_t;
567 template <
class S,
class T>
570 return TypeName<S>::str();
static void callback(T &target)
Definition Type.h:533
Utilities related to std::type_info.
Definition Type.h:52
static const std::type_info & getTypeInfo(const char *typeCode)
Returns the type corresponding to a single-character string.
Definition Type.h:411
static const std::type_info & getTypeInfo(const std::string &typeCode)
Returns the type corresponding to a single-character string.
Definition Type.h:426
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 .
Definition Type.h:465
static const std::type_info & getTypeInfo(const Type &t)
Convenience. Purpose is to have a full set of getTypeInfo commands for templated constructs.
Definition Type.h:438
static void call(T &target, const std::type_info &t)
Static function call without parameters on a single target of type T.
Definition Type.h:341
const std::type_info & getType() const
Deprecated! Use cast (above) instead?
Definition Type.h:108
void setType(const T &t)
Set current type to t.
Definition Type.h:84
static T call(const std::type_info &t)
Calls a static function that has no parameters.
Definition Type.h:224
static F::value_t call(const S &typeCode)
A shorthand for functors with a fixed return type, hence D = F::value_t.
Definition Type.h:307
static D call(const S &typeCode)
New, preferred implementation: a single if-then structure once and for all.
Definition Type.h:294
static void call(T &target, const T2 &t)
Static function call with a single parameter.
Definition Type.h:399
static const std::type_info & getTypeInfo(char t)
Returns the base type associated with a character key.
Definition Type.h:135
Definition DataSelector.cpp:1277
static T callback()
Definition Type.h:495
static void callback(Type &target)
Definition Type.h:517