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