Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

dtool/src/interrogatedb/interrogateDatabase.h

Go to the documentation of this file.
00001 // Filename: interrogateDatabase.h
00002 // Created by:  drose (01Aug00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #ifndef INTERROGATEDATABASE_H
00020 #define INTERROGATEDATABASE_H
00021 
00022 #include <dtoolbase.h>
00023 
00024 #include "interrogate_interface.h"
00025 #include "interrogateType.h"
00026 #include "interrogateFunction.h"
00027 #include "interrogateFunctionWrapper.h"
00028 #include "interrogateManifest.h"
00029 #include "interrogateElement.h"
00030 #include "interrogate_request.h"
00031 
00032 #include <map>
00033 
00034 class IndexRemapper;
00035 
00036 ////////////////////////////////////////////////////////////////////
00037 //       Class : InterrogateDatabase
00038 // Description : This stores all of the interrogate data and handles
00039 //               reading the data from a disk file when necessary.
00040 ////////////////////////////////////////////////////////////////////
00041 class EXPCL_DTOOLCONFIG InterrogateDatabase {
00042 private:
00043   InterrogateDatabase();
00044 
00045 public:
00046   static InterrogateDatabase *get_ptr();
00047   void request_module(InterrogateModuleDef *def);
00048 
00049 public:
00050   // Functions to read the database.
00051   int get_num_global_types();
00052   TypeIndex get_global_type(int n);
00053   int get_num_all_types();
00054   TypeIndex get_all_type(int n);
00055   int get_num_global_functions();
00056   FunctionIndex get_global_function(int n);
00057   int get_num_all_functions();
00058   FunctionIndex get_all_function(int n);
00059   int get_num_global_manifests();
00060   ManifestIndex get_global_manifest(int n);
00061   int get_num_global_elements();
00062   ElementIndex get_global_element(int n);
00063 
00064   const InterrogateType &get_type(TypeIndex type);
00065   const InterrogateFunction &get_function(FunctionIndex function);
00066   const InterrogateFunctionWrapper &get_wrapper(FunctionWrapperIndex wrapper);
00067   const InterrogateManifest &get_manifest(ManifestIndex manifest);
00068   const InterrogateElement &get_element(ElementIndex 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   // Functions to build the database.
00090   int get_next_index();
00091   void add_type(TypeIndex index, const InterrogateType &type);
00092   void add_function(FunctionIndex index, InterrogateFunction *function);
00093   void add_wrapper(FunctionWrapperIndex index,
00094                    const InterrogateFunctionWrapper &wrapper);
00095   void add_manifest(ManifestIndex index, const InterrogateManifest &manifest);
00096   void add_element(ElementIndex index, const InterrogateElement &element);
00097 
00098   InterrogateType &update_type(TypeIndex type);
00099   InterrogateFunction &update_function(FunctionIndex function);
00100   InterrogateFunctionWrapper &update_wrapper(FunctionWrapperIndex wrapper);
00101   InterrogateManifest &update_manifest(ManifestIndex manifest);
00102   InterrogateElement &update_element(ElementIndex element);
00103 
00104   int remap_indices(int first_index);
00105   int remap_indices(int first_index, IndexRemapper &remap);
00106 
00107   void write(ostream &out, InterrogateModuleDef *def) const;
00108   bool read(istream &in, InterrogateModuleDef *def);
00109 
00110 private:
00111   INLINE void check_latest();
00112   void load_latest();
00113 
00114   bool read_new(istream &in, InterrogateModuleDef *def);
00115   void merge_from(const InterrogateDatabase &other);
00116 
00117   bool find_module(FunctionWrapperIndex wrapper,
00118                    InterrogateModuleDef *&def, int &module_index);
00119   int binary_search_module(int begin, int end, FunctionIndex function);
00120   int binary_search_wrapper_hash(InterrogateUniqueNameDef *begin,
00121                                  InterrogateUniqueNameDef *end,
00122                                  const string &wrapper_hash_name);
00123 
00124   // This data is loaded from the various database files.
00125   typedef map<TypeIndex, InterrogateType> TypeMap;
00126   TypeMap _type_map;
00127   typedef map<FunctionIndex, InterrogateFunction *> FunctionMap;
00128   FunctionMap _function_map;
00129   typedef map<FunctionWrapperIndex, InterrogateFunctionWrapper> FunctionWrapperMap;
00130   FunctionWrapperMap _wrapper_map;
00131 
00132   typedef map<ManifestIndex, InterrogateManifest> ManifestMap;
00133   ManifestMap _manifest_map;
00134   typedef map<ElementIndex, InterrogateElement> ElementMap;
00135   ElementMap _element_map;
00136 
00137   typedef vector<TypeIndex> GlobalTypes;
00138   GlobalTypes _global_types;
00139   GlobalTypes _all_types;
00140   typedef vector<FunctionIndex> GlobalFunctions;
00141   GlobalFunctions _global_functions;
00142   GlobalFunctions _all_functions;
00143   typedef vector<ManifestIndex> GlobalManifests;
00144   GlobalManifests _global_manifests;
00145   typedef vector<ElementIndex> GlobalElements;
00146   GlobalElements _global_elements;
00147 
00148   // This data is compiled in directly to the shared libraries that we
00149   // link with.
00150   typedef vector<InterrogateModuleDef *> Modules;
00151   Modules _modules;
00152   typedef map<string, InterrogateModuleDef *> ModulesByHash;
00153   ModulesByHash _modules_by_hash;
00154 
00155   // This records the set of database files that are still to be
00156   // loaded.
00157   typedef vector<InterrogateModuleDef *> Requests;
00158   Requests _requests;
00159 
00160   int _next_index;
00161 
00162   enum LookupType {
00163     LT_type_name           = 0x001,
00164     LT_type_scoped_name    = 0x002,
00165     LT_type_true_name      = 0x004,
00166     LT_manifest_name       = 0x008,
00167     LT_element_name        = 0x010,
00168     LT_element_scoped_name = 0x020,
00169   };
00170 
00171   int _lookups_fresh;
00172   typedef map<string, int> Lookup;
00173   Lookup _types_by_name;
00174   Lookup _types_by_scoped_name;
00175   Lookup _types_by_true_name;
00176   Lookup _manifests_by_name;
00177   Lookup _elements_by_name;
00178   Lookup _elements_by_scoped_name;
00179 
00180   void freshen_types_by_name();
00181   void freshen_types_by_scoped_name();
00182   void freshen_types_by_true_name();
00183   void freshen_manifests_by_name();
00184   void freshen_elements_by_name();
00185   void freshen_elements_by_scoped_name();
00186 
00187   int lookup(const string &name,
00188              Lookup &lookup, LookupType type,
00189              void (InterrogateDatabase::*freshen)());
00190 
00191   static InterrogateDatabase *_global_ptr;
00192   static int _file_major_version;
00193   static int _file_minor_version;
00194   static int _current_major_version;
00195   static int _current_minor_version;
00196 };
00197 
00198 #include "interrogateDatabase.I"
00199 
00200 #endif

Generated on Thu May 1 22:13:06 2003 for DTool by doxygen1.3