Panda3D
Loading...
Searching...
No Matches
interrogateDatabase.h
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file interrogateDatabase.h
10 * @author drose
11 * @date 2000-08-01
12 */
13
14#ifndef INTERROGATEDATABASE_H
15#define INTERROGATEDATABASE_H
16
17#include "dtoolbase.h"
18
20#include "interrogateType.h"
21#include "interrogateFunction.h"
23#include "interrogateManifest.h"
24#include "interrogateElement.h"
25#include "interrogateMakeSeq.h"
26#include "interrogate_request.h"
27
28#include <map>
29
30class IndexRemapper;
31
32/**
33 * This stores all of the interrogate data and handles reading the data from a
34 * disk file when necessary.
35 */
36class EXPCL_INTERROGATEDB InterrogateDatabase {
37private:
38 InterrogateDatabase();
39
40public:
41 static InterrogateDatabase *get_ptr();
43
44public:
45 // Functions to read the database.
46 bool get_error_flag();
47
49 TypeIndex get_global_type(int n);
51 TypeIndex get_all_type(int n);
53 FunctionIndex get_global_function(int n);
55 FunctionIndex get_all_function(int n);
57 ManifestIndex get_global_manifest(int n);
59 ElementIndex get_global_element(int n);
60
61 const InterrogateType &get_type(TypeIndex type);
62 const InterrogateFunction &get_function(FunctionIndex function);
63 const InterrogateFunctionWrapper &get_wrapper(FunctionWrapperIndex wrapper);
64 const InterrogateManifest &get_manifest(ManifestIndex manifest);
65 const InterrogateElement &get_element(ElementIndex element);
66 const InterrogateMakeSeq &get_make_seq(MakeSeqIndex element);
67
68 INLINE TypeIndex lookup_type_by_name(const std::string &name);
69 INLINE TypeIndex lookup_type_by_scoped_name(const std::string &name);
70 INLINE TypeIndex lookup_type_by_true_name(const std::string &name);
71 INLINE ManifestIndex lookup_manifest_by_name(const std::string &name);
72 INLINE ElementIndex lookup_element_by_name(const std::string &name);
73 INLINE ElementIndex lookup_element_by_scoped_name(const std::string &name);
74
75 void remove_type(TypeIndex type);
76
77 void *get_fptr(FunctionWrapperIndex wrapper);
78
79 FunctionWrapperIndex get_wrapper_by_unique_name(const std::string &unique_name);
80
81 static int get_file_major_version();
82 static int get_file_minor_version();
83 static int get_current_major_version();
84 static int get_current_minor_version();
85
86public:
87 // Functions to build the database.
88 void set_error_flag(bool error_flag);
89
90 int get_next_index();
91 void add_type(TypeIndex index, const InterrogateType &type);
92 void add_function(FunctionIndex index, InterrogateFunction *function);
93 void add_wrapper(FunctionWrapperIndex index,
94 const InterrogateFunctionWrapper &wrapper);
95 void add_manifest(ManifestIndex index, const InterrogateManifest &manifest);
96 void add_element(ElementIndex index, const InterrogateElement &element);
97 void add_make_seq(MakeSeqIndex index, const InterrogateMakeSeq &make_seq);
98
99 InterrogateType &update_type(TypeIndex type);
100 InterrogateFunction &update_function(FunctionIndex function);
101 InterrogateFunctionWrapper &update_wrapper(FunctionWrapperIndex wrapper);
102 InterrogateManifest &update_manifest(ManifestIndex manifest);
103 InterrogateElement &update_element(ElementIndex element);
104 InterrogateMakeSeq &update_make_seq(MakeSeqIndex make_seq);
105
106 int remap_indices(int first_index);
107 int remap_indices(int first_index, IndexRemapper &remap);
108
109 void write(std::ostream &out, InterrogateModuleDef *def) const;
110 bool read(std::istream &in, InterrogateModuleDef *def);
111
112private:
113 INLINE void check_latest();
114 void load_latest();
115
116 bool read_new(std::istream &in, InterrogateModuleDef *def);
117 void merge_from(const InterrogateDatabase &other);
118
119 bool find_module(FunctionWrapperIndex wrapper,
120 InterrogateModuleDef *&def, int &module_index);
121 int binary_search_module(int begin, int end, FunctionIndex function);
122 int binary_search_wrapper_hash(InterrogateUniqueNameDef *begin,
124 const std::string &wrapper_hash_name);
125
126 // This data is loaded from the various database files.
127 typedef std::map<TypeIndex, InterrogateType> TypeMap;
128 TypeMap _type_map;
129 typedef std::map<FunctionIndex, InterrogateFunction *> FunctionMap;
130 FunctionMap _function_map;
131 typedef std::map<FunctionWrapperIndex, InterrogateFunctionWrapper> FunctionWrapperMap;
132 FunctionWrapperMap _wrapper_map;
133
134 typedef std::map<ManifestIndex, InterrogateManifest> ManifestMap;
135 ManifestMap _manifest_map;
136 typedef std::map<ElementIndex, InterrogateElement> ElementMap;
137 ElementMap _element_map;
138
139 typedef std::map<MakeSeqIndex, InterrogateMakeSeq> MakeSeqMap;
140 MakeSeqMap _make_seq_map;
141
142 typedef std::vector<TypeIndex> GlobalTypes;
143 GlobalTypes _global_types;
144 GlobalTypes _all_types;
145 typedef std::vector<FunctionIndex> GlobalFunctions;
146 GlobalFunctions _global_functions;
147 GlobalFunctions _all_functions;
148 typedef std::vector<ManifestIndex> GlobalManifests;
149 GlobalManifests _global_manifests;
150 typedef std::vector<ElementIndex> GlobalElements;
151 GlobalElements _global_elements;
152
153 // This data is compiled in directly to the shared libraries that we link
154 // with.
155 typedef std::vector<InterrogateModuleDef *> Modules;
156 Modules _modules;
157 typedef std::map<std::string, InterrogateModuleDef *> ModulesByHash;
158 ModulesByHash _modules_by_hash;
159
160 // This records the set of database files that are still to be loaded.
161 typedef std::vector<InterrogateModuleDef *> Requests;
162 Requests _requests;
163
164 bool _error_flag;
165 int _next_index;
166
167 enum LookupType {
168 LT_type_name = 0x001,
169 LT_type_scoped_name = 0x002,
170 LT_type_true_name = 0x004,
171 LT_manifest_name = 0x008,
172 LT_element_name = 0x010,
173 LT_element_scoped_name = 0x020,
174 };
175
176 int _lookups_fresh;
177 typedef std::map<std::string, int> Lookup;
178 Lookup _types_by_name;
179 Lookup _types_by_scoped_name;
180 Lookup _types_by_true_name;
181 Lookup _manifests_by_name;
182 Lookup _elements_by_name;
183 Lookup _elements_by_scoped_name;
184
185 void freshen_types_by_name();
186 void freshen_types_by_scoped_name();
187 void freshen_types_by_true_name();
188 void freshen_manifests_by_name();
189 void freshen_elements_by_name();
190 void freshen_elements_by_scoped_name();
191
192 int lookup(const std::string &name,
193 Lookup &lookup, LookupType type,
194 void (InterrogateDatabase::*freshen)());
195
196 static InterrogateDatabase *_global_ptr;
197 static int _file_major_version;
198 static int _file_minor_version;
199 static int _current_major_version;
200 static int _current_minor_version;
201};
202
203#include "interrogateDatabase.I"
204
205#endif
This class manages a mapping of integers to integers.
int get_num_global_types()
Returns the total number of "global" types known to the interrogate database.
void remove_type(TypeIndex type)
Erases the type from the database.
TypeIndex lookup_type_by_scoped_name(const std::string &name)
Returns the TypeIndex associated with the first type found with the given scoped name,...
void request_module(InterrogateModuleDef *def)
Requests that the interrogate data for the given module be made available.
ManifestIndex get_global_manifest(int n)
Returns the index of the nth global manifest constant known to the interrogate database.
const InterrogateFunction & get_function(FunctionIndex function)
Returns the function associated with the given FunctionIndex, if there is one.
InterrogateFunction & update_function(FunctionIndex function)
Returns a non-const reference to the indicated function, allowing the user to update it.
static int get_current_minor_version()
Returns the minor version number currently expected in interrogate database files generated by this c...
InterrogateType & update_type(TypeIndex type)
Returns a non-const reference to the indicated type, allowing the user to update it.
ManifestIndex lookup_manifest_by_name(const std::string &name)
Returns the ManifestIndex associated with the first manifest found with the given name,...
int get_num_all_functions()
Returns the total number of functions known to the interrogate database.
InterrogateElement & update_element(ElementIndex element)
Returns a non-const reference to the indicated data element, allowing the user to update it.
int get_num_all_types()
Returns the total number of types known to the interrogate database.
void add_manifest(ManifestIndex index, const InterrogateManifest &manifest)
Adds the indicated manifest constant to the database at the given index number.
TypeIndex lookup_type_by_true_name(const std::string &name)
Returns the TypeIndex associated with the first type found with the given true name,...
const InterrogateMakeSeq & get_make_seq(MakeSeqIndex element)
Returns the make_seq associated with the given MakeSeqIndex, if there is one.
bool get_error_flag()
Returns the global error flag.
void add_wrapper(FunctionWrapperIndex index, const InterrogateFunctionWrapper &wrapper)
Adds the indicated function wrapper to the database at the given index number.
int get_num_global_elements()
Returns the total number of global data elements known to the interrogate database.
void add_type(TypeIndex index, const InterrogateType &type)
Adds the indicated type to the database at the given index number.
const InterrogateManifest & get_manifest(ManifestIndex manifest)
Returns the manifest constant associated with the given ManifestIndex, if there is one.
const InterrogateType & get_type(TypeIndex type)
Returns the type associated with the given TypeIndex, if there is one.
const InterrogateElement & get_element(ElementIndex element)
Returns the data element associated with the given ElementIndex, if there is one.
int get_num_global_manifests()
Returns the total number of global manifest constants known to the interrogate database.
InterrogateManifest & update_manifest(ManifestIndex manifest)
Returns a non-const reference to the indicated manifest constant, allowing the user to update it.
int get_num_global_functions()
Returns the total number of global functions known to the interrogate database.
InterrogateFunctionWrapper & update_wrapper(FunctionWrapperIndex wrapper)
Returns a non-const reference to the indicated function wrapper, allowing the user to update it.
void add_element(ElementIndex index, const InterrogateElement &element)
Adds the indicated data element to the database at the given index number.
static int get_file_minor_version()
Returns the minor version number of the interrogate database file currently being read.
bool read(std::istream &in, InterrogateModuleDef *def)
Reads a database from the indicated stream, associated with the indicated module definition and merge...
void set_error_flag(bool error_flag)
Sets the global error flag.
const InterrogateFunctionWrapper & get_wrapper(FunctionWrapperIndex wrapper)
Returns the function wrapper associated with the given FunctionWrapperIndex, if there is one.
static int get_current_major_version()
Returns the major version number currently expected in interrogate database files generated by this c...
int get_next_index()
Returns a new index number suitable for the next thing, that will not be shared with any other index ...
static InterrogateDatabase * get_ptr()
Returns the global pointer to the one InterrogateDatabase.
void * get_fptr(FunctionWrapperIndex wrapper)
Returns the function pointer associated with the given function wrapper, if it has a pointer availabl...
ElementIndex lookup_element_by_name(const std::string &name)
Returns the ElementIndex associated with the first element found with the given name,...
FunctionIndex get_all_function(int n)
Returns the index of the nth function known to the interrogate database.
TypeIndex get_all_type(int n)
Returns the index of the nth type known to the interrogate database.
ElementIndex lookup_element_by_scoped_name(const std::string &name)
Returns the ElementIndex associated with the first element found with the given scoped name,...
FunctionWrapperIndex get_wrapper_by_unique_name(const std::string &unique_name)
Looks up the function wrapper corresponding to the given unique name, if available.
void add_make_seq(MakeSeqIndex index, const InterrogateMakeSeq &make_seq)
Adds the indicated make_seq to the database at the given index number.
InterrogateMakeSeq & update_make_seq(MakeSeqIndex make_seq)
Returns a non-const reference to the indicated make_seq, allowing the user to update it.
void add_function(FunctionIndex index, InterrogateFunction *function)
Adds the indicated function to the database at the given index number.
int remap_indices(int first_index)
Resequences all of the various index numbers so that all of the functions start at first_index and in...
void write(std::ostream &out, InterrogateModuleDef *def) const
Writes the database to the indicated stream for later reading.
static int get_file_major_version()
Returns the major version number of the interrogate database file currently being read.
TypeIndex lookup_type_by_name(const std::string &name)
Returns the TypeIndex associated with the first type found with the given name, or 0 if no type has t...
ElementIndex get_global_element(int n)
Returns the index of the nth global data element known to the interrogate database.
TypeIndex get_global_type(int n)
Returns the index of the nth global type known to the interrogate database.
FunctionIndex get_global_function(int n)
Returns the index of the nth global function known to the interrogate database.
An internal representation of a data element, like a data member or a global variable.
An internal representation of a callable function.
An internal representation of a function.
Represents a synthetic method created via the MAKE_SEQ() macro.
An internal representation of a manifest constant.
An internal representation of a type.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.