24 #if defined(__linux) || defined(__APPLE__)
27 typedef abi::__class_type_info class_t;
28 using abi::__dynamic_cast;
33 int hour,
int minutes,
int seconds)
36 ::memset(&tm_init,0,
sizeof(tm_init));
37 tm_init.tm_year = year > 1900 ? year-1900 : year;
38 tm_init.tm_mon = month;
39 tm_init.tm_mday = day;
40 tm_init.tm_hour = hour;
41 tm_init.tm_min = minutes;
42 tm_init.tm_sec = seconds;
43 tm_init.tm_isdst = -1;
44 long int ti = ::mktime(&tm_init);
45 if ( ti >= 0 )
return ti;
46 except(
"DD4hep",
"Invalid time data given for conversion to epoch: %d-%d-%d %02d:%02d:%02d",
47 year, month, day, hour, minutes, seconds);
54 char* c = ::strptime(date.c_str(),fmt,&tm);
57 "Invalid time format given for update:%s should be: %s",
60 long ti = ::mktime(&tm);
61 if ( ti >= 0 )
return ti;
63 "Invalid time string given for conversion to epoch: %s (fmt='%s')",
69 const char* class_name = tinfo.name();
73 if ( ::strncmp(class_name,
"class ", 6) == 0 ) {
77 if ( ::strncmp(class_name,
"struct ", 7) == 0 ) {
81 if ( off != std::string::npos ) {
82 std::string tmp = class_name + off;
84 while( (loc = tmp.find(
"class ")) != std::string::npos ) {
88 while( (loc = tmp.find(
"struct ")) != std::string::npos ) {
97 while ( (off=result.find(
" *")) != std::string::npos ) {
98 result.replace(off, 2,
"*");
101 while ( (off=result.find(
" &")) != std::string::npos ) {
102 result.replace(off, 2,
"&");
106 #elif !defined(__ICC)
107 if (::strlen(class_name) == 1) {
110 switch (class_name[0]) {
124 result =
"unsigned char";
130 result =
"unsigned short";
136 result =
"unsigned int";
142 result =
"unsigned long";
145 result =
"long long";
148 result =
"unsigned long long";
154 result =
"unsigned __int128";
163 result =
"long double";
166 result =
"__float128";
174 char buff[16 * 1024];
175 std::size_t len =
sizeof(buff);
177 result = __cxxabiv1::__cxa_demangle(class_name, buff, &len, &status);
181 throw std::runtime_error(
"CXXABI is missing for ICC!");
196 const std::type_info& to)
198 std::string msg =
"Wrong assingment from ";
202 msg +=
" not possible!!";
209 std::string
m =
"The requested feature " + msg +
" is not implemented!";
210 throw std::runtime_error(m);
239 ::snprintf(text,
sizeof(text),default_format(),value);
248 throw std::runtime_error(
"Failed to convert (char*)NULL to std::string!");
255 throw std::runtime_error(
"Failed to convert (char*)NULL to std::string!");
277 : type(t), destroy(d), cast(c) {
283 throw std::runtime_error(
"Class type " +
typeName(
type) +
" is not an abi object type!");
301 __dynamic_cast(
const void* __src_ptr,
302 const abi::__class_type_info* __src_type,
303 const abi::__class_type_info* __dst_type,
304 ptrdiff_t __src2dst);
309 const abi::__class_type_info* src,
310 const abi::__class_type_info* dst,
313 return abi::__dynamic_cast(p,src,dst,src2dst);
325 void *r = (*to.
cast)(ptr);
333 void* r = (
void*)ptr;
335 bool cast_worked = type.__do_upcast((
const class_t*)to.
abi_class,&r);
336 if ( cast_worked )
return r;
338 cast_worked = to.
type.__do_upcast((
const class_t*)abi_class,&r);
339 if ( cast_worked )
return r;
341 const class_t* src_type = (
const class_t*)to.
abi_class;
344 void *r =
cast_wrap(ptr, src_type, (
const class_t*) abi_class, -1);
347 r =
cast_wrap(ptr, (
const class_t*) abi_class, src_type, -1);
363 return apply_dynCast(to, ptr);
373 void *r = (*to.
cast)(ptr);
380 void* r = (
void*)ptr;
381 bool cast_worked = type.__do_upcast((
const class_t*)to.
abi_class,&r);
382 if ( cast_worked )
return r;
384 void *r =
cast_wrap(ptr, src_type, (
const class_t*)abi_class, -1);
static void * cast_wrap(const void *p, const abi::__class_type_info *src, const abi::__class_type_info *dst, ptrdiff_t src2dst)
void notImplemented(const std::string &msg)
Throw exception when handles are check for validity.
std::string typeName(const std::type_info &type)
ABI information about type names.
int except(const std::string &src, const std::string &fmt,...)
Calls the display action with ERROR and throws an std::runtime_error exception.
virtual ~ComponentCast()
Defautl destructor.
static const char * default_format()
Access to default printf format.
void invalidHandleAssignmentError(const std::type_info &from, const std::type_info &to)
Throw exception when handles are badly assigned.
void * apply_dynCast(const ComponentCast &to, const void *ptr) const
Apply cast using typeinfo instead of dynamic_cast.
void * apply_downCast(const ComponentCast &to, const void *ptr) const
Apply cast using typeinfo instead of dynamic_cast.
Specialized exception to be thrown if invalid handles are accessed.
const std::type_info & type
Class to perform dynamic casts using unknown pointers.
static const std::string __typeinfoName(const std::type_info &tinfo)
long int makeTime(int year, int month, int day, int hour=0, int minutes=0, int seconds=0)
Convert date into epoch time (seconds since 1970)
ComponentCast(const std::type_info &t, destroy_t d, cast_t c)
Initializing Constructor.
void invalidHandleError(const std::type_info &type)
Throw exception when handles are check for validity.
void * apply_upCast(const ComponentCast &to, const void *ptr) const
Apply cast using typeinfo instead of dynamic_cast.
static std::string toString(T value)
Auto conversion to string using the default format.
void typeinfoCheck(const std::type_info &typ1, const std::type_info &typ2, const std::string &text="")
Check type infos for equivalence (dynamic casts) using ABI information.