#pragma implementation "typeinfo"
#include <stddef.h>
#include "tinfo.h"
#include "new" // for placement new
std::type_info::
~type_info ()
{ }
bool std::type_info::
operator== (const std::type_info& arg) const
{
return (&arg == this) || (strcmp (name (), arg.name ()) == 0);
}
extern "C" void
__rtti_class (void *addr, const char *name,
const __class_type_info::base_info *bl, size_t bn)
{ new (addr) __class_type_info (name, bl, bn); }
extern "C" void
__rtti_si (void *addr, const char *n, const std::type_info *ti)
{
new (addr) __si_type_info
(n, static_cast <const __user_type_info &> (*ti));
}
extern "C" void
__rtti_user (void *addr, const char *name)
{ new (addr) __user_type_info (name); }
void * __user_type_info::
dcast (const type_info& to, int, void *addr, const type_info *, void *) const
{ return (*this == to) ? addr : 0; }
void * __si_type_info::
dcast (const type_info& to, int require_public, void *addr,
const type_info *sub, void *subptr) const
{
if (*this == to)
return addr;
return base.dcast (to, require_public, addr, sub, subptr);
}
void* __class_type_info::
dcast (const type_info& desired, int is_public, void *objptr,
const type_info *sub, void *subptr) const
{
if (*this == desired)
return objptr;
void *match_found = 0;
for (size_t i = 0; i < n_bases; i++)
{
if (is_public && base_list[i].access != PUBLIC)
continue;
void *p = (char *)objptr + base_list[i].offset;
if (base_list[i].is_virtual)
p = *(void **)p;
p = base_list[i].base->dcast (desired, is_public, p, sub, subptr);
if (p)
{
if (match_found == 0)
match_found = p;
else if (match_found != p)
{
if (sub)
{
const __user_type_info &d =
static_cast <const __user_type_info &> (desired);
void *os = d.dcast (*sub, 1, match_found);
void *ns = d.dcast (*sub, 1, p);
if (os == ns)
;
else if (os == subptr)
continue;
else if (ns == subptr)
{
match_found = p;
continue;
}
}
return 0;
}
}
}
return match_found;
}