00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef TYPEREGISTRY_H
00020 #define TYPEREGISTRY_H
00021
00022 #include "pandabase.h"
00023
00024 #include "typeHandle.h"
00025 #include "typeRegistryNode.h"
00026
00027 #include "notify.h"
00028 #include "pvector.h"
00029 #include "pmap.h"
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 class EXPCL_PANDAEXPRESS TypeRegistry {
00041 public:
00042
00043
00044
00045
00046 bool register_type(TypeHandle &type_handle, const string &name);
00047 TypeHandle register_dynamic_type(const string &name);
00048
00049 void record_derivation(TypeHandle child, TypeHandle parent);
00050 void record_alternate_name(TypeHandle type, const string &name);
00051
00052 PUBLISHED:
00053 TypeHandle find_type(const string &name) const;
00054
00055 string get_name(TypeHandle type, TypedObject *object) const;
00056 INLINE bool is_derived_from(TypeHandle child, TypeHandle base,
00057 TypedObject *child_object);
00058
00059 int get_num_root_classes();
00060 TypeHandle get_root_class(int n);
00061
00062 int get_num_parent_classes(TypeHandle child,
00063 TypedObject *child_object) const;
00064 TypeHandle get_parent_class(TypeHandle child, int index) const;
00065
00066 int get_num_child_classes(TypeHandle child,
00067 TypedObject *child_object) const;
00068 TypeHandle get_child_class(TypeHandle child, int index) const;
00069
00070 TypeHandle get_parent_towards(TypeHandle child, TypeHandle base,
00071 TypedObject *child_object);
00072
00073 static void reregister_types();
00074
00075 void write(ostream &out) const;
00076
00077
00078 static TypeRegistry *ptr();
00079
00080 private:
00081
00082
00083 TypeRegistry();
00084
00085 static void init_global_pointer();
00086
00087
00088
00089 #ifdef NDEBUG
00090 INLINE TypeRegistryNode *look_up(TypeHandle type, TypedObject *object) const;
00091 #else
00092 TypeRegistryNode *look_up(TypeHandle type, TypedObject *object) const;
00093 #endif
00094
00095 INLINE void freshen_derivations();
00096 void rebuild_derivations();
00097 void write_node(ostream &out, int indent_level,
00098 const TypeRegistryNode *node) const;
00099
00100 typedef pvector<TypeRegistryNode *> HandleRegistry;
00101 HandleRegistry _handle_registry;
00102
00103 typedef pmap<string, TypeRegistryNode *> NameRegistry;
00104 NameRegistry _name_registry;
00105
00106 typedef pvector<TypeRegistryNode *> RootClasses;
00107 RootClasses _root_classes;
00108
00109 bool _derivations_fresh;
00110
00111 static TypeRegistry *_global_pointer;
00112 };
00113
00114 #include "typeRegistry.I"
00115
00116 #endif