00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef INTERROGATEDATABASE_H
00016 #define INTERROGATEDATABASE_H
00017
00018 #include "dtoolbase.h"
00019
00020 #include "interrogate_interface.h"
00021 #include "interrogateType.h"
00022 #include "interrogateFunction.h"
00023 #include "interrogateFunctionWrapper.h"
00024 #include "interrogateManifest.h"
00025 #include "interrogateElement.h"
00026 #include "interrogateMakeSeq.h"
00027 #include "interrogate_request.h"
00028
00029 #include <map>
00030
00031 class IndexRemapper;
00032
00033
00034
00035
00036
00037
00038 class EXPCL_DTOOLCONFIG InterrogateDatabase {
00039 private:
00040 InterrogateDatabase();
00041
00042 public:
00043 static InterrogateDatabase *get_ptr();
00044 void request_module(InterrogateModuleDef *def);
00045
00046 public:
00047
00048 bool get_error_flag();
00049
00050 int get_num_global_types();
00051 TypeIndex get_global_type(int n);
00052 int get_num_all_types();
00053 TypeIndex get_all_type(int n);
00054 int get_num_global_functions();
00055 FunctionIndex get_global_function(int n);
00056 int get_num_all_functions();
00057 FunctionIndex get_all_function(int n);
00058 int get_num_global_manifests();
00059 ManifestIndex get_global_manifest(int n);
00060 int get_num_global_elements();
00061 ElementIndex get_global_element(int n);
00062
00063 const InterrogateType &get_type(TypeIndex type);
00064 const InterrogateFunction &get_function(FunctionIndex function);
00065 const InterrogateFunctionWrapper &get_wrapper(FunctionWrapperIndex wrapper);
00066 const InterrogateManifest &get_manifest(ManifestIndex manifest);
00067 const InterrogateElement &get_element(ElementIndex element);
00068 const InterrogateMakeSeq &get_make_seq(MakeSeqIndex element);
00069
00070 INLINE TypeIndex lookup_type_by_name(const string &name);
00071 INLINE TypeIndex lookup_type_by_scoped_name(const string &name);
00072 INLINE TypeIndex lookup_type_by_true_name(const string &name);
00073 INLINE ManifestIndex lookup_manifest_by_name(const string &name);
00074 INLINE ElementIndex lookup_element_by_name(const string &name);
00075 INLINE ElementIndex lookup_element_by_scoped_name(const string &name);
00076
00077 void remove_type(TypeIndex type);
00078
00079 void *get_fptr(FunctionWrapperIndex wrapper);
00080
00081 FunctionWrapperIndex get_wrapper_by_unique_name(const string &unique_name);
00082
00083 static int get_file_major_version();
00084 static int get_file_minor_version();
00085 static int get_current_major_version();
00086 static int get_current_minor_version();
00087
00088 public:
00089
00090 void set_error_flag(bool error_flag);
00091
00092 int get_next_index();
00093 void add_type(TypeIndex index, const InterrogateType &type);
00094 void add_function(FunctionIndex index, InterrogateFunction *function);
00095 void add_wrapper(FunctionWrapperIndex index,
00096 const InterrogateFunctionWrapper &wrapper);
00097 void add_manifest(ManifestIndex index, const InterrogateManifest &manifest);
00098 void add_element(ElementIndex index, const InterrogateElement &element);
00099 void add_make_seq(MakeSeqIndex index, const InterrogateMakeSeq &make_seq);
00100
00101 InterrogateType &update_type(TypeIndex type);
00102 InterrogateFunction &update_function(FunctionIndex function);
00103 InterrogateFunctionWrapper &update_wrapper(FunctionWrapperIndex wrapper);
00104 InterrogateManifest &update_manifest(ManifestIndex manifest);
00105 InterrogateElement &update_element(ElementIndex element);
00106 InterrogateMakeSeq &update_make_seq(MakeSeqIndex make_seq);
00107
00108 int remap_indices(int first_index);
00109 int remap_indices(int first_index, IndexRemapper &remap);
00110
00111 void write(ostream &out, InterrogateModuleDef *def) const;
00112 bool read(istream &in, InterrogateModuleDef *def);
00113
00114 private:
00115 INLINE void check_latest();
00116 void load_latest();
00117
00118 bool read_new(istream &in, InterrogateModuleDef *def);
00119 void merge_from(const InterrogateDatabase &other);
00120
00121 bool find_module(FunctionWrapperIndex wrapper,
00122 InterrogateModuleDef *&def, int &module_index);
00123 int binary_search_module(int begin, int end, FunctionIndex function);
00124 int binary_search_wrapper_hash(InterrogateUniqueNameDef *begin,
00125 InterrogateUniqueNameDef *end,
00126 const string &wrapper_hash_name);
00127
00128
00129 typedef map<TypeIndex, InterrogateType> TypeMap;
00130 TypeMap _type_map;
00131 typedef map<FunctionIndex, InterrogateFunction *> FunctionMap;
00132 FunctionMap _function_map;
00133 typedef map<FunctionWrapperIndex, InterrogateFunctionWrapper> FunctionWrapperMap;
00134 FunctionWrapperMap _wrapper_map;
00135
00136 typedef map<ManifestIndex, InterrogateManifest> ManifestMap;
00137 ManifestMap _manifest_map;
00138 typedef map<ElementIndex, InterrogateElement> ElementMap;
00139 ElementMap _element_map;
00140
00141 typedef map<MakeSeqIndex, InterrogateMakeSeq> MakeSeqMap;
00142 MakeSeqMap _make_seq_map;
00143
00144 typedef vector<TypeIndex> GlobalTypes;
00145 GlobalTypes _global_types;
00146 GlobalTypes _all_types;
00147 typedef vector<FunctionIndex> GlobalFunctions;
00148 GlobalFunctions _global_functions;
00149 GlobalFunctions _all_functions;
00150 typedef vector<ManifestIndex> GlobalManifests;
00151 GlobalManifests _global_manifests;
00152 typedef vector<ElementIndex> GlobalElements;
00153 GlobalElements _global_elements;
00154
00155
00156
00157 typedef vector<InterrogateModuleDef *> Modules;
00158 Modules _modules;
00159 typedef map<string, InterrogateModuleDef *> ModulesByHash;
00160 ModulesByHash _modules_by_hash;
00161
00162
00163
00164 typedef vector<InterrogateModuleDef *> Requests;
00165 Requests _requests;
00166
00167 bool _error_flag;
00168 int _next_index;
00169
00170 enum LookupType {
00171 LT_type_name = 0x001,
00172 LT_type_scoped_name = 0x002,
00173 LT_type_true_name = 0x004,
00174 LT_manifest_name = 0x008,
00175 LT_element_name = 0x010,
00176 LT_element_scoped_name = 0x020,
00177 };
00178
00179 int _lookups_fresh;
00180 typedef map<string, int> Lookup;
00181 Lookup _types_by_name;
00182 Lookup _types_by_scoped_name;
00183 Lookup _types_by_true_name;
00184 Lookup _manifests_by_name;
00185 Lookup _elements_by_name;
00186 Lookup _elements_by_scoped_name;
00187
00188 void freshen_types_by_name();
00189 void freshen_types_by_scoped_name();
00190 void freshen_types_by_true_name();
00191 void freshen_manifests_by_name();
00192 void freshen_elements_by_name();
00193 void freshen_elements_by_scoped_name();
00194
00195 int lookup(const string &name,
00196 Lookup &lookup, LookupType type,
00197 void (InterrogateDatabase::*freshen)());
00198
00199 static InterrogateDatabase *_global_ptr;
00200 static int _file_major_version;
00201 static int _file_minor_version;
00202 static int _current_major_version;
00203 static int _current_minor_version;
00204 };
00205
00206 #include "interrogateDatabase.I"
00207
00208 #endif