interrogateDatabase.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. // Filename: interrogateDatabase.h
  2. // Created by: drose (01Aug00)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
  8. //
  9. // All use of this software is subject to the terms of the Panda 3d
  10. // Software license. You should have received a copy of this license
  11. // along with this source code; you will also find a current copy of
  12. // the license at http://etc.cmu.edu/panda3d/docs/license/ .
  13. //
  14. // To contact the maintainers of this program write to
  15. // [email protected] .
  16. //
  17. ////////////////////////////////////////////////////////////////////
  18. #ifndef INTERROGATEDATABASE_H
  19. #define INTERROGATEDATABASE_H
  20. #include "dtoolbase.h"
  21. #include "interrogate_interface.h"
  22. #include "interrogateType.h"
  23. #include "interrogateFunction.h"
  24. #include "interrogateFunctionWrapper.h"
  25. #include "interrogateManifest.h"
  26. #include "interrogateElement.h"
  27. #include "interrogate_request.h"
  28. #include <map>
  29. class IndexRemapper;
  30. ////////////////////////////////////////////////////////////////////
  31. // Class : InterrogateDatabase
  32. // Description : This stores all of the interrogate data and handles
  33. // reading the data from a disk file when necessary.
  34. ////////////////////////////////////////////////////////////////////
  35. class EXPCL_DTOOLCONFIG InterrogateDatabase {
  36. private:
  37. InterrogateDatabase();
  38. public:
  39. static InterrogateDatabase *get_ptr();
  40. void request_module(InterrogateModuleDef *def);
  41. public:
  42. // Functions to read the database.
  43. bool get_error_flag();
  44. int get_num_global_types();
  45. TypeIndex get_global_type(int n);
  46. int get_num_all_types();
  47. TypeIndex get_all_type(int n);
  48. int get_num_global_functions();
  49. FunctionIndex get_global_function(int n);
  50. int get_num_all_functions();
  51. FunctionIndex get_all_function(int n);
  52. int get_num_global_manifests();
  53. ManifestIndex get_global_manifest(int n);
  54. int get_num_global_elements();
  55. ElementIndex get_global_element(int n);
  56. const InterrogateType &get_type(TypeIndex type);
  57. const InterrogateFunction &get_function(FunctionIndex function);
  58. const InterrogateFunctionWrapper &get_wrapper(FunctionWrapperIndex wrapper);
  59. const InterrogateManifest &get_manifest(ManifestIndex manifest);
  60. const InterrogateElement &get_element(ElementIndex element);
  61. INLINE TypeIndex lookup_type_by_name(const string &name);
  62. INLINE TypeIndex lookup_type_by_scoped_name(const string &name);
  63. INLINE TypeIndex lookup_type_by_true_name(const string &name);
  64. INLINE ManifestIndex lookup_manifest_by_name(const string &name);
  65. INLINE ElementIndex lookup_element_by_name(const string &name);
  66. INLINE ElementIndex lookup_element_by_scoped_name(const string &name);
  67. void remove_type(TypeIndex type);
  68. void *get_fptr(FunctionWrapperIndex wrapper);
  69. FunctionWrapperIndex get_wrapper_by_unique_name(const string &unique_name);
  70. static int get_file_major_version();
  71. static int get_file_minor_version();
  72. static int get_current_major_version();
  73. static int get_current_minor_version();
  74. public:
  75. // Functions to build the database.
  76. void set_error_flag(bool error_flag);
  77. int get_next_index();
  78. void add_type(TypeIndex index, const InterrogateType &type);
  79. void add_function(FunctionIndex index, InterrogateFunction *function);
  80. void add_wrapper(FunctionWrapperIndex index,
  81. const InterrogateFunctionWrapper &wrapper);
  82. void add_manifest(ManifestIndex index, const InterrogateManifest &manifest);
  83. void add_element(ElementIndex index, const InterrogateElement &element);
  84. InterrogateType &update_type(TypeIndex type);
  85. InterrogateFunction &update_function(FunctionIndex function);
  86. InterrogateFunctionWrapper &update_wrapper(FunctionWrapperIndex wrapper);
  87. InterrogateManifest &update_manifest(ManifestIndex manifest);
  88. InterrogateElement &update_element(ElementIndex element);
  89. int remap_indices(int first_index);
  90. int remap_indices(int first_index, IndexRemapper &remap);
  91. void write(ostream &out, InterrogateModuleDef *def) const;
  92. bool read(istream &in, InterrogateModuleDef *def);
  93. private:
  94. INLINE void check_latest();
  95. void load_latest();
  96. bool read_new(istream &in, InterrogateModuleDef *def);
  97. void merge_from(const InterrogateDatabase &other);
  98. bool find_module(FunctionWrapperIndex wrapper,
  99. InterrogateModuleDef *&def, int &module_index);
  100. int binary_search_module(int begin, int end, FunctionIndex function);
  101. int binary_search_wrapper_hash(InterrogateUniqueNameDef *begin,
  102. InterrogateUniqueNameDef *end,
  103. const string &wrapper_hash_name);
  104. // This data is loaded from the various database files.
  105. typedef map<TypeIndex, InterrogateType> TypeMap;
  106. TypeMap _type_map;
  107. typedef map<FunctionIndex, InterrogateFunction *> FunctionMap;
  108. FunctionMap _function_map;
  109. typedef map<FunctionWrapperIndex, InterrogateFunctionWrapper> FunctionWrapperMap;
  110. FunctionWrapperMap _wrapper_map;
  111. typedef map<ManifestIndex, InterrogateManifest> ManifestMap;
  112. ManifestMap _manifest_map;
  113. typedef map<ElementIndex, InterrogateElement> ElementMap;
  114. ElementMap _element_map;
  115. typedef vector<TypeIndex> GlobalTypes;
  116. GlobalTypes _global_types;
  117. GlobalTypes _all_types;
  118. typedef vector<FunctionIndex> GlobalFunctions;
  119. GlobalFunctions _global_functions;
  120. GlobalFunctions _all_functions;
  121. typedef vector<ManifestIndex> GlobalManifests;
  122. GlobalManifests _global_manifests;
  123. typedef vector<ElementIndex> GlobalElements;
  124. GlobalElements _global_elements;
  125. // This data is compiled in directly to the shared libraries that we
  126. // link with.
  127. typedef vector<InterrogateModuleDef *> Modules;
  128. Modules _modules;
  129. typedef map<string, InterrogateModuleDef *> ModulesByHash;
  130. ModulesByHash _modules_by_hash;
  131. // This records the set of database files that are still to be
  132. // loaded.
  133. typedef vector<InterrogateModuleDef *> Requests;
  134. Requests _requests;
  135. bool _error_flag;
  136. int _next_index;
  137. enum LookupType {
  138. LT_type_name = 0x001,
  139. LT_type_scoped_name = 0x002,
  140. LT_type_true_name = 0x004,
  141. LT_manifest_name = 0x008,
  142. LT_element_name = 0x010,
  143. LT_element_scoped_name = 0x020,
  144. };
  145. int _lookups_fresh;
  146. typedef map<string, int> Lookup;
  147. Lookup _types_by_name;
  148. Lookup _types_by_scoped_name;
  149. Lookup _types_by_true_name;
  150. Lookup _manifests_by_name;
  151. Lookup _elements_by_name;
  152. Lookup _elements_by_scoped_name;
  153. void freshen_types_by_name();
  154. void freshen_types_by_scoped_name();
  155. void freshen_types_by_true_name();
  156. void freshen_manifests_by_name();
  157. void freshen_elements_by_name();
  158. void freshen_elements_by_scoped_name();
  159. int lookup(const string &name,
  160. Lookup &lookup, LookupType type,
  161. void (InterrogateDatabase::*freshen)());
  162. static InterrogateDatabase *_global_ptr;
  163. static int _file_major_version;
  164. static int _file_minor_version;
  165. static int _current_major_version;
  166. static int _current_minor_version;
  167. };
  168. #include "interrogateDatabase.I"
  169. #endif