Panda3D
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 
19 #include "interrogate_interface.h"
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 
30 class IndexRemapper;
31 
32 /**
33  * This stores all of the interrogate data and handles reading the data from a
34  * disk file when necessary.
35  */
36 class EXPCL_INTERROGATEDB InterrogateDatabase {
37 private:
39 
40 public:
41  static InterrogateDatabase *get_ptr();
42  void request_module(InterrogateModuleDef *def);
43 
44 public:
45  // Functions to read the database.
46  bool get_error_flag();
47 
48  int get_num_global_types();
49  TypeIndex get_global_type(int n);
50  int get_num_all_types();
51  TypeIndex get_all_type(int n);
52  int get_num_global_functions();
53  FunctionIndex get_global_function(int n);
54  int get_num_all_functions();
55  FunctionIndex get_all_function(int n);
56  int get_num_global_manifests();
57  ManifestIndex get_global_manifest(int n);
58  int get_num_global_elements();
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 
86 public:
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 
112 private:
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.
Definition: indexRemapper.h:29
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Represents a synthetic method created via the MAKE_SEQ() macro.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This stores all of the interrogate data and handles reading the data from a disk file when necessary.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
An internal representation of a type.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
An internal representation of a function.
An internal representation of a callable function.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
An internal representation of a manifest constant.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
An internal representation of a data element, like a data member or a global variable.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.