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