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