Panda3D

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