52 Type() : currentType(&
typeid(
void)) {
56 Type(
const Type & t) : currentType(t.currentType) {
61 Type(
const T & t) : currentType(&
typeid(
void)){
70 currentType = &
typeid(T);
81 call<typeSetter>(*
this, t);
87 Type & operator=(
const T & t){
93 operator const std::type_info & ()
const {
return (*currentType); }
96 operator char ()
const {
return getTypeChar(*currentType); }
99 operator std::string ()
const {
return std::string(1, getTypeChar(*currentType)); }
137 return typeid(
unsigned char);
139 return typeid(short);
141 return typeid(
unsigned short);
145 return typeid(
unsigned int);
149 return typeid(
unsigned long);
151 return typeid(float);
153 return typeid(double);
158 return typeid(std::string);
165 std::cerr << __FILE__ <<
' ' << __FUNCTION__ <<
" undefined type: '" << t <<
"'=" << (int)t << std::endl;
167 throw std::runtime_error(
"undefined type");
175 char getTypeChar(
const std::type_info & t){
176 if (t ==
typeid(
char))
178 else if (t ==
typeid(
unsigned char))
180 else if (t ==
typeid(
short))
182 else if (t ==
typeid(
unsigned short))
184 else if (t ==
typeid(
int))
186 else if (t ==
typeid(
unsigned int))
188 else if (t ==
typeid(
long))
190 else if (t ==
typeid(
unsigned long))
192 else if (t ==
typeid(
float))
194 else if (t ==
typeid(
double))
196 else if (t ==
typeid(
bool))
198 else if (t ==
typeid(
void))
200 else if (t ==
typeid(std::string))
202 else if (t ==
typeid(
const char *))
204 else if (t ==
typeid(
char *))
218 template <
class F,
class T>
220 T
call(
const std::type_info & t){
224 if (t ==
typeid(
char)){
225 return F::template callback<char,T>();
227 else if (t ==
typeid(
unsigned char)) {
228 return F::template callback<unsigned char,T>();
230 else if (t ==
typeid(
int)) {
231 return F::template callback<int,T>();
233 else if (t ==
typeid(
unsigned int)) {
234 return F::template callback<unsigned int,T>();
236 else if (t ==
typeid(
short int)) {
237 return F::template callback<short int,T>();
239 else if (t ==
typeid(
unsigned short int)) {
240 return F::template callback<unsigned short int,T>();
242 else if (t ==
typeid(
long int)) {
243 return F::template callback<long int,T>();
245 else if (t ==
typeid(
unsigned long int)) {
246 return F::template callback<unsigned long int,T>();
248 else if (t ==
typeid(
float)) {
249 return F::template callback<float,T>();
251 else if (t ==
typeid(
double)) {
252 return F::template callback<double,T>();
254 else if (t ==
typeid(
bool)) {
255 return F::template callback<bool,T>();
257 else if (t ==
typeid(
void)) {
258 return F::template callback<void,T>();
260 else if (t ==
typeid(std::string)) {
261 return F::template callback<std::string,T>();
270 std::cerr << __FILE__ <<
' ' << __FUNCTION__ <<
"unimplemented type: ..." << t.name() << std::endl;
272 throw std::runtime_error(
"unimplemented type: ...");
277 return F::template callback<char,T>();
288 template <
class F,
class D,
class S>
301 template <
class F,
class S>
303 typename F::value_t
call(
const S & typeCode){
304 return call<F,typename F::value_t>(
getTypeInfo(typeCode));
335 template <
class F,
class T>
337 void call(T & target,
const std::type_info &t){
339 if (t ==
typeid(
char))
340 F::template callback<char>(target);
341 else if (t ==
typeid(
unsigned char))
342 F::template callback<unsigned char>(target);
343 else if (t ==
typeid(
int))
344 F::template callback<int>(target);
345 else if (t ==
typeid(
unsigned int))
346 F::template callback<unsigned int>(target);
347 else if (t ==
typeid(
short))
348 F::template callback<short>(target);
349 else if (t ==
typeid(
unsigned short))
350 F::template callback<unsigned short>(target);
351 else if (t ==
typeid(
long))
352 F::template callback<long>(target);
353 else if (t ==
typeid(
unsigned long))
354 F::template callback<unsigned long>(target);
355 else if (t ==
typeid(
float))
356 F::template callback<float>(target);
357 else if (t ==
typeid(
double))
358 F::template callback<double>(target);
359 else if (t ==
typeid(
bool))
360 F::template callback<bool>(target);
361 else if (t ==
typeid(std::string))
362 F::template callback<std::string>(target);
363 else if (t ==
typeid(
void)) {
364 F::template callback<void>(target);
372 std::cerr << __FILE__ <<
' ' << __FUNCTION__ <<
"unimplemented type: ..." << t.name() << std::endl;
374 throw std::runtime_error(
"unimplemented type: ...");
393 template <
class F,
class T,
class T2>
395 void call(T & target,
const T2 &t){
408 if ((typeCode != NULL) && (*typeCode !=
'\0'))
410 else if (typeCode == NULL)
413 throw std::runtime_error(std::string(
"Type::operator=, not unit-length std::string: ") + typeCode);
423 if (typeCode.length() == 1)
425 else if (typeCode.empty())
428 throw std::runtime_error(std::string(
"Type::operator=, not unit-length std::string: ") + typeCode);
457 const std::type_info & guessArrayType(const C & container);
462 const std::type_info & type = t.
getType();
463 ostr << Type::getTypeChar(type) <<
'@';
468 std::ostream & toStreamFull(std::ostream & ostr,
const Type &t){
483 typedef bool value_t;
489 template <
class S,
class T>
492 return std::is_enum<S>::value;
527 template <
class S,
class T>
530 target.template setType<S>();
534 const std::type_info *currentType;
541std::ostream & operator<<(std::ostream & ostr,
const Type &t){
557 typedef std::string value_t;
563 template <
class S,
class T>
566 return TypeName<S>::str();
static void callback(T &target)
Definition Type.h:529
Utilities related to std::type_info.
Definition Type.h:48
static const std::type_info & getTypeInfo(const char *typeCode)
Returns the type corresponding to a single-character string.
Definition Type.h:407
static const std::type_info & getTypeInfo(const std::string &typeCode)
Returns the type corresponding to a single-character string.
Definition Type.h:422
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:461
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:434
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:337
const std::type_info & getType() const
Deprecated! Use cast (above) instead?
Definition Type.h:104
void setType(const T &t)
Set current type to t.
Definition Type.h:80
static T call(const std::type_info &t)
Calls a static function that has no parameters.
Definition Type.h:220
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:303
static D call(const S &typeCode)
New, preferred implementation: a single if-then structure once and for all.
Definition Type.h:290
static void call(T &target, const T2 &t)
Static function call with a single parameter.
Definition Type.h:395
static const std::type_info & getTypeInfo(char t)
Returns the base type associated with a character key.
Definition Type.h:131
Definition DataSelector.cpp:1277
static T callback()
Definition Type.h:491
static void callback(Type &target)
Definition Type.h:513