Panda3D
 All Classes Functions Variables Enumerations
typeRegistryNode.I
1 // Filename: typeRegistryNode.I
2 // Created by: drose (06Aug01)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 
16 ////////////////////////////////////////////////////////////////////
17 // Function: TypeRegistryNode::Inherit::Default Constructor
18 // Access: Public
19 // Description:
20 ////////////////////////////////////////////////////////////////////
21 INLINE TypeRegistryNode::Inherit::
22 Inherit() {
23  _top = (TypeRegistryNode *)NULL;
24  _mask = 0;
25  _bits = 0;
26 }
27 
28 ////////////////////////////////////////////////////////////////////
29 // Function: TypeRegistryNode::Inherit::Constructor
30 // Access: Public
31 // Description:
32 ////////////////////////////////////////////////////////////////////
33 INLINE TypeRegistryNode::Inherit::
34 Inherit(TypeRegistryNode *top, int bit_count,
35  TypeRegistryNode::SubtreeMaskType bits) {
36  assert(bit_count < (int)(sizeof(SubtreeMaskType) * 8));
37  _top = top;
38 
39  // Build a bitmask consisting of bit_count low-order bits.
40  _mask = ((SubtreeMaskType)1 << bit_count) - 1;
41 
42  // There shouldn't be anything but zeroes after bit_count bits.
43  assert((bits & ~_mask) == 0);
44  _bits = bits;
45 }
46 
47 ////////////////////////////////////////////////////////////////////
48 // Function: TypeRegistryNode::Inherit::Copy Constructor
49 // Access: Public
50 // Description:
51 ////////////////////////////////////////////////////////////////////
52 INLINE TypeRegistryNode::Inherit::
53 Inherit(const TypeRegistryNode::Inherit &copy) :
54  _top(copy._top),
55  _mask(copy._mask),
56  _bits(copy._bits)
57 {
58 }
59 
60 ////////////////////////////////////////////////////////////////////
61 // Function: TypeRegistryNode::Inherit::Copy Assignment Operator
62 // Access: Public
63 // Description:
64 ////////////////////////////////////////////////////////////////////
65 INLINE void TypeRegistryNode::Inherit::
66 operator = (const TypeRegistryNode::Inherit &copy) {
67  _top = copy._top;
68  _mask = copy._mask;
69  _bits = copy._bits;
70 }
71 
72 ////////////////////////////////////////////////////////////////////
73 // Function: TypeRegistryNode::Inherit::Ordering operator
74 // Access: Public
75 // Description:
76 ////////////////////////////////////////////////////////////////////
77 INLINE bool TypeRegistryNode::Inherit::
78 operator < (const Inherit &other) const {
79  return _top < other._top;
80 }
81 
82 ////////////////////////////////////////////////////////////////////
83 // Function: TypeRegistryNode::Inherit::is_derived_from
84 // Access: Public
85 // Description: Assuming the two Inherit objects share the same
86 // subtree top, this returns true if the bitmasks
87 // indicate that child inherits from base, or false
88 // otherwise.
89 ////////////////////////////////////////////////////////////////////
90 INLINE bool TypeRegistryNode::Inherit::
91 is_derived_from(const TypeRegistryNode::Inherit &child,
92  const TypeRegistryNode::Inherit &base) {
93  assert(child._top == base._top);
94 
95  // Child derives from base if and only if its subtree mask contains
96  // more bits (or the same number of bits), and the n low-order
97  // subtree bits that are in common are identical.
98  return ((child._mask & base._mask) == base._mask &&
99  (child._bits & base._mask) == base._bits);
100 }
This is a single entry in the TypeRegistry.