3 * - By John Hodge (thePowersGang)
6 * - typeid and dynamic_cast
10 #include <acess/sys.h>
15 type_info::~type_info()
20 bool type_info::operator==(const type_info& other) const
22 //_SysDebug("type_info::operator== - '%s' == '%s'", this->__type_name, other.__type_name);
23 return this->__type_name == other.__type_name;
26 bool type_info::operator!=(const type_info& other) const
28 //_SysDebug("type_info::operator!= - '%s' != '%s'", this->__type_name, other.__type_name);
29 return this->__type_name != other.__type_name;
32 bool type_info::before(const type_info& other) const
34 //_SysDebug("type_info::before - '%s' < '%s'", this->__type_name, other.__type_name);
35 return this->__type_name < other.__type_name;
38 const char *type_info::name() const
40 return this->__type_name;
44 type_info::type_info(const type_info& rhs):
45 __type_name(rhs.__type_name)
48 type_info& type_info::operator=(const type_info& rhs)
50 _SysDebug("type_info::operator=, was %s now %s", __type_name, rhs.__type_name);
51 __type_name = rhs.__type_name;
55 bool type_info::is_class() const
57 if( typeid(*this) == typeid(::__cxxabiv1::__class_type_info) )
64 bool type_info::is_subclass() const
66 if( typeid(*this) == typeid(::__cxxabiv1::__si_class_type_info) )
68 if( typeid(*this) == typeid(::__cxxabiv1::__vmi_class_type_info) )
74 bool type_info::__is_child(const type_info &poss_child, unsigned long &offset) const
76 _SysDebug("typeids = this:%s , poss_child:%s", typeid(*this).name(), typeid(poss_child).name());
78 // Check #1: Child is same type
79 if( poss_child == *this ) {
84 // Check #2: This type must be a class
85 if( !this->is_class() ) {
88 // Check #3: Child class must be a subclass
89 if( !poss_child.is_subclass() ) {
93 if( typeid(poss_child) == typeid(::__cxxabiv1::__si_class_type_info) ) {
94 auto &si_poss_child = reinterpret_cast<const ::__cxxabiv1::__si_class_type_info&>(poss_child);
96 _SysDebug("type_info::__is_child - Single inheritance");
97 return __is_child( *si_poss_child.__base_type, offset );
99 else if( typeid(poss_child) == typeid(::__cxxabiv1::__vmi_class_type_info) ) {
100 // Multiple inheritance
101 _SysDebug("TODO: type_info::__is_child - Multiple inheritance");
107 _SysDebug("ERROR: type_info::__is_child - Reported subclass type, but not a subclass %s",
108 typeid(poss_child).name()
116 // NOTE: Not defined by the C++ ABI, but is similar to one defined by GCC (__cxa_type_match
117 //bool __acess_type_match(std::typeinfo& possibly_derived, const std::typeinfo& base_type)