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