Panda3D
|
00001 // Filename: typeRegistryNode.I 00002 // Created by: drose (06Aug01) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 00016 //////////////////////////////////////////////////////////////////// 00017 // Function: TypeRegistryNode::Inherit::Default Constructor 00018 // Access: Public 00019 // Description: 00020 //////////////////////////////////////////////////////////////////// 00021 INLINE TypeRegistryNode::Inherit:: 00022 Inherit() { 00023 _top = (TypeRegistryNode *)NULL; 00024 _mask = 0; 00025 _bits = 0; 00026 } 00027 00028 //////////////////////////////////////////////////////////////////// 00029 // Function: TypeRegistryNode::Inherit::Constructor 00030 // Access: Public 00031 // Description: 00032 //////////////////////////////////////////////////////////////////// 00033 INLINE TypeRegistryNode::Inherit:: 00034 Inherit(TypeRegistryNode *top, int bit_count, 00035 TypeRegistryNode::SubtreeMaskType bits) { 00036 assert(bit_count < (int)(sizeof(SubtreeMaskType) * 8)); 00037 _top = top; 00038 00039 // Build a bitmask consisting of bit_count low-order bits. 00040 _mask = ((SubtreeMaskType)1 << bit_count) - 1; 00041 00042 // There shouldn't be anything but zeroes after bit_count bits. 00043 assert((bits & ~_mask) == 0); 00044 _bits = bits; 00045 } 00046 00047 //////////////////////////////////////////////////////////////////// 00048 // Function: TypeRegistryNode::Inherit::Copy Constructor 00049 // Access: Public 00050 // Description: 00051 //////////////////////////////////////////////////////////////////// 00052 INLINE TypeRegistryNode::Inherit:: 00053 Inherit(const TypeRegistryNode::Inherit ©) : 00054 _top(copy._top), 00055 _mask(copy._mask), 00056 _bits(copy._bits) 00057 { 00058 } 00059 00060 //////////////////////////////////////////////////////////////////// 00061 // Function: TypeRegistryNode::Inherit::Copy Assignment Operator 00062 // Access: Public 00063 // Description: 00064 //////////////////////////////////////////////////////////////////// 00065 INLINE void TypeRegistryNode::Inherit:: 00066 operator = (const TypeRegistryNode::Inherit ©) { 00067 _top = copy._top; 00068 _mask = copy._mask; 00069 _bits = copy._bits; 00070 } 00071 00072 //////////////////////////////////////////////////////////////////// 00073 // Function: TypeRegistryNode::Inherit::Ordering operator 00074 // Access: Public 00075 // Description: 00076 //////////////////////////////////////////////////////////////////// 00077 INLINE bool TypeRegistryNode::Inherit:: 00078 operator < (const Inherit &other) const { 00079 return _top < other._top; 00080 } 00081 00082 //////////////////////////////////////////////////////////////////// 00083 // Function: TypeRegistryNode::Inherit::is_derived_from 00084 // Access: Public 00085 // Description: Assuming the two Inherit objects share the same 00086 // subtree top, this returns true if the bitmasks 00087 // indicate that child inherits from base, or false 00088 // otherwise. 00089 //////////////////////////////////////////////////////////////////// 00090 INLINE bool TypeRegistryNode::Inherit:: 00091 is_derived_from(const TypeRegistryNode::Inherit &child, 00092 const TypeRegistryNode::Inherit &base) { 00093 assert(child._top == base._top); 00094 00095 // Child derives from base if and only if its subtree mask contains 00096 // more bits (or the same number of bits), and the n low-order 00097 // subtree bits that are in common are identical. 00098 return ((child._mask & base._mask) == base._mask && 00099 (child._bits & base._mask) == base._bits); 00100 }