Panda3D
typeRegistryNode.h
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.h
10  * @author drose
11  * @date 2001-08-06
12  */
13 
14 #ifndef TYPEREGISTRYNODE_H
15 #define TYPEREGISTRYNODE_H
16 
17 #include "dtoolbase.h"
18 
19 #include "typeHandle.h"
20 #include "numeric_types.h"
21 
22 #include <assert.h>
23 #include <vector>
24 
25 /**
26  * This is a single entry in the TypeRegistry. Normally, user code will never
27  * directly access this class; this class is hidden within the TypeRegistry
28  * accessors.
29  */
30 class EXPCL_DTOOL_DTOOLBASE TypeRegistryNode {
31 public:
32  TypeRegistryNode(TypeHandle handle, const std::string &name, TypeHandle &ref);
33 
34  static bool is_derived_from(const TypeRegistryNode *child,
35  const TypeRegistryNode *base);
36 
37  static TypeHandle get_parent_towards(const TypeRegistryNode *child,
38  const TypeRegistryNode *base);
39 
40  INLINE PyObject *get_python_type() const;
41 
42  void clear_subtree();
43  void define_subtree();
44 
45  TypeHandle _handle;
46  std::string _name;
47  TypeHandle &_ref;
48  typedef std::vector<TypeRegistryNode *> Classes;
49  Classes _parent_classes;
50  Classes _child_classes;
51  PyObject *_python_type = nullptr;
52 
53  AtomicAdjust::Integer _memory_usage[TypeHandle::MC_limit];
54 
55  static bool _paranoid_inheritance;
56 
57 private:
58  typedef int SubtreeMaskType;
59 
60  // This class defines the inheritance relationship of this node from some
61  // ancestor denoted as a "subtree top" node. This is usually the nearest
62  // ancestor that has multiple inheritance.
63  class Inherit {
64  public:
65  INLINE Inherit();
66  INLINE Inherit(TypeRegistryNode *top, int bit_count,
67  SubtreeMaskType bits);
68  INLINE Inherit(const Inherit &copy);
69  INLINE void operator = (const Inherit &copy);
70 
71  INLINE bool operator < (const Inherit &other) const;
72  INLINE static bool is_derived_from(const Inherit &child, const Inherit &base);
73 
74  TypeRegistryNode *_top;
75  SubtreeMaskType _mask;
76  SubtreeMaskType _bits;
77  };
78  typedef std::vector<Inherit> TopInheritance;
79 
80  void r_build_subtrees(TypeRegistryNode *top,
81  int bit_count, SubtreeMaskType bits);
82 
83  PyObject *r_get_python_type() const;
84 
85  static bool check_derived_from(const TypeRegistryNode *child,
86  const TypeRegistryNode *base);
87 
88  Inherit _inherit;
89 
90  // The _top_inheritance member is only filled for nodes that are denoted as
91  // "subtree top" nodes. It represents the complete set of subtree_top nodes
92  // that this node inherits from, directly or indirectly.
93  TopInheritance _top_inheritance;
94 
95  // _visit_count is only used during r_build_subtree().
96  int _visit_count;
97 };
98 
99 #include "typeRegistryNode.I"
100 
101 #endif
This is a single entry in the TypeRegistry.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81