Panda3D
|
00001 // Filename: typeRegistryNode.h 00002 // Created by: drose (06Aug01) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #ifndef TYPEREGISTRYNODE_H 00016 #define TYPEREGISTRYNODE_H 00017 00018 #include "dtoolbase.h" 00019 00020 #include "typeHandle.h" 00021 #include "numeric_types.h" 00022 00023 #include <assert.h> 00024 #include <vector> 00025 00026 //////////////////////////////////////////////////////////////////// 00027 // Class : TypeRegistryNode 00028 // Description : This is a single entry in the TypeRegistry. 00029 // Normally, user code will never directly access this 00030 // class; this class is hidden within the TypeRegistry 00031 // accessors. 00032 //////////////////////////////////////////////////////////////////// 00033 class EXPCL_DTOOL TypeRegistryNode { 00034 public: 00035 TypeRegistryNode(TypeHandle handle, const string &name, TypeHandle &ref); 00036 00037 static bool is_derived_from(const TypeRegistryNode *child, 00038 const TypeRegistryNode *base); 00039 00040 static TypeHandle get_parent_towards(const TypeRegistryNode *child, 00041 const TypeRegistryNode *base); 00042 00043 void clear_subtree(); 00044 void define_subtree(); 00045 00046 TypeHandle _handle; 00047 string _name; 00048 TypeHandle &_ref; 00049 typedef vector<TypeRegistryNode *> Classes; 00050 Classes _parent_classes; 00051 Classes _child_classes; 00052 00053 #ifdef DO_MEMORY_USAGE 00054 AtomicAdjust::Integer _memory_usage[TypeHandle::MC_limit]; 00055 #endif 00056 00057 static bool _paranoid_inheritance; 00058 00059 private: 00060 typedef int SubtreeMaskType; 00061 00062 // This class defines the inheritance relationship of this node from 00063 // some ancestor denoted as a "subtree top" node. This is usually 00064 // the nearest ancestor that has multiple inheritance. 00065 class Inherit { 00066 public: 00067 INLINE Inherit(); 00068 INLINE Inherit(TypeRegistryNode *top, int bit_count, 00069 SubtreeMaskType bits); 00070 INLINE Inherit(const Inherit ©); 00071 INLINE void operator = (const Inherit ©); 00072 00073 INLINE bool operator < (const Inherit &other) const; 00074 INLINE static bool is_derived_from(const Inherit &child, const Inherit &base); 00075 00076 TypeRegistryNode *_top; 00077 SubtreeMaskType _mask; 00078 SubtreeMaskType _bits; 00079 }; 00080 typedef vector<Inherit> TopInheritance; 00081 00082 void r_build_subtrees(TypeRegistryNode *top, 00083 int bit_count, SubtreeMaskType bits); 00084 00085 static bool check_derived_from(const TypeRegistryNode *child, 00086 const TypeRegistryNode *base); 00087 00088 Inherit _inherit; 00089 00090 // The _top_inheritance member is only filled for nodes that are 00091 // denoted as "subtree top" nodes. It represents the complete set 00092 // of subtree_top nodes that this node inherits from, directly or 00093 // indirectly. 00094 TopInheritance _top_inheritance; 00095 00096 // _visit_count is only used during r_build_subtree(). 00097 int _visit_count; 00098 }; 00099 00100 #include "typeRegistryNode.I" 00101 00102 #endif