15 #include "typeRegistryNode.h" 20 bool TypeRegistryNode::_paranoid_inheritance =
false;
29 _handle(handle), _name(name), _ref(ref)
32 #ifdef DO_MEMORY_USAGE 33 memset(_memory_usage, 0,
sizeof(_memory_usage));
56 if (child->_inherit._top == base->_inherit._top) {
60 Inherit::is_derived_from(child->_inherit, base->_inherit);
63 if (_paranoid_inheritance) {
64 bool paranoid_derives = check_derived_from(child, base);
65 if (derives != paranoid_derives) {
67 <<
"Inheritance test for " << child->_name
68 <<
" from " << base->_name <<
" failed!\n" 69 <<
"Result: " << derives <<
" should have been: " 70 << paranoid_derives <<
"\n" 71 <<
"Classes are in the same single inheritance subtree, children of " 72 << child->_inherit._top->_name <<
"\n" 74 << child->_name <<
" has mask " << child->_inherit._mask
75 <<
" and bits " << child->_inherit._bits <<
"\n" 76 << base->_name <<
" has mask " << base->_inherit._mask
77 <<
" and bits " << base->_inherit._bits <<
"\n" 79 return paranoid_derives;
100 bool derives =
false;
104 TopInheritance::const_iterator ti =
105 lower_bound(child_top->_top_inheritance.begin(),
106 child_top->_top_inheritance.end(),
107 Inherit(base_top, 0, 0));
109 while (ti != child_top->_top_inheritance.end() &&
110 (*ti)._top == base_top &&
116 const Inherit &connection = (*ti);
122 derives = Inherit::is_derived_from(connection, base->_inherit);
128 if (_paranoid_inheritance) {
129 bool paranoid_derives = check_derived_from(child, base);
130 if (derives != paranoid_derives) {
132 <<
"Inheritance test for " << child->_name
133 <<
" from " << base->_name <<
" failed!\n" 134 <<
"Result: " << derives <<
" should have been: " 135 << paranoid_derives <<
"\n" 136 << child->_name <<
" is a descendent of " 137 << child_top->_name <<
"\n" 138 << base->_name <<
" is a descendent of " 139 << base_top->_name <<
"\n";
140 return paranoid_derives;
163 return child->_handle;
166 Classes::const_iterator ni;
167 for (ni = child->_parent_classes.begin();
168 ni != child->_parent_classes.end(); ++ni) {
170 return (*ni)->_handle;
187 _inherit = Inherit();
188 _top_inheritance.clear();
214 r_build_subtrees(
this, 0, 0);
225 void TypeRegistryNode::
227 TypeRegistryNode::SubtreeMaskType bits) {
266 if (top !=
this && _parent_classes.size() != 1) {
267 assert(!_parent_classes.empty());
272 _top_inheritance.insert(_top_inheritance.end(),
273 top->_top_inheritance.begin(),
274 top->_top_inheritance.end());
275 _top_inheritance.push_back(Inherit(top, bit_count, bits));
278 if (_visit_count == (
int)_parent_classes.size()) {
282 sort(_top_inheritance.begin(), _top_inheritance.end());
291 assert(bit_count < (
int)(
sizeof(SubtreeMaskType) * 8));
293 _inherit = Inherit(top, bit_count, bits);
297 int num_children = _child_classes.size();
299 int i = num_children - 1;
307 more_bits = max(more_bits, 1);
309 assert(more_bits < (
int)(
sizeof(SubtreeMaskType) * 8));
311 if (bit_count + more_bits > (
int)(
sizeof(SubtreeMaskType) * 8)) {
316 _top_inheritance = top->_top_inheritance;
317 _top_inheritance.push_back(_inherit);
318 sort(_top_inheritance.begin(), _top_inheritance.end());
319 _inherit = Inherit();
324 for (i = 0; i < num_children; i++) {
326 SubtreeMaskType next_bits = ((SubtreeMaskType)i << bit_count);
328 child->r_build_subtrees(top, bit_count + more_bits,
345 bool TypeRegistryNode::
352 Classes::const_iterator ni;
353 for (ni = child->_parent_classes.begin();
354 ni != child->_parent_classes.end();
356 if (check_derived_from(*ni, base)) {
static TypeHandle none()
Returns a special zero-valued TypeHandle that is used to indicate no type.
void clear_subtree()
Removes any subtree definition previously set up via define_subtree(), in preparation for rebuilding ...
static TypeHandle get_parent_towards(const TypeRegistryNode *child, const TypeRegistryNode *base)
Returns the first parent class of child that is a descendant of the indicated base class...
This is a single entry in the TypeRegistry.
static bool is_derived_from(const TypeRegistryNode *child, const TypeRegistryNode *base)
Returns true if the child RegistryNode represents a class that inherits directly or indirectly from t...
void define_subtree()
Indicates that this TypeRegistryNode is the top of a subtree within the inheritance graph (typically...
TypeHandle is the identifier used to differentiate C++ class types.