Panda3D

configPageManager.h

00001 // Filename: configPageManager.h
00002 // Created by:  drose (15Oct04)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef CONFIGPAGEMANAGER_H
00016 #define CONFIGPAGEMANAGER_H
00017 
00018 #include "dtoolbase.h"
00019 #include "configFlags.h"
00020 #include "dSearchPath.h"
00021 #include "globPattern.h"
00022 #include "pnotify.h"
00023 
00024 #include <vector>
00025 
00026 class ConfigPage;
00027 
00028 ////////////////////////////////////////////////////////////////////
00029 //       Class : ConfigPageManager
00030 // Description : A global object that maintains the set of ConfigPages
00031 //               everywhere in the world, and keeps them in sorted
00032 //               order.
00033 ////////////////////////////////////////////////////////////////////
00034 class EXPCL_DTOOLCONFIG ConfigPageManager : public ConfigFlags {
00035 protected:
00036   ConfigPageManager();
00037   ~ConfigPageManager();
00038 
00039 PUBLISHED:
00040   INLINE bool loaded_implicit_pages() const;
00041   INLINE void load_implicit_pages();
00042   void reload_implicit_pages();
00043 
00044   INLINE DSearchPath &get_search_path();
00045 
00046   INLINE int get_num_prc_patterns() const;
00047   INLINE string get_prc_pattern(int n) const;
00048 
00049   INLINE int get_num_prc_encrypted_patterns() const;
00050   INLINE string get_prc_encrypted_pattern(int n) const;
00051 
00052   INLINE int get_num_prc_executable_patterns() const;
00053   INLINE string get_prc_executable_pattern(int n) const;
00054 
00055   ConfigPage *make_explicit_page(const string &name);
00056   bool delete_explicit_page(ConfigPage *page);
00057 
00058   INLINE int get_num_implicit_pages() const;
00059   INLINE ConfigPage *get_implicit_page(int n) const;
00060 
00061   INLINE int get_num_explicit_pages() const;
00062   INLINE ConfigPage *get_explicit_page(int n) const;
00063 
00064   void output(ostream &out) const;
00065   void write(ostream &out) const;
00066 
00067   static ConfigPageManager *get_global_ptr();
00068 
00069 private:
00070   INLINE void check_sort_pages() const;
00071   void sort_pages();
00072 
00073   bool scan_auto_prc_dir(Filename &prc_dir) const;
00074   bool scan_up_from(Filename &result, const Filename &dir, 
00075                     const Filename &suffix) const;
00076 
00077   void config_initialized();
00078 
00079   typedef vector<ConfigPage *> Pages;
00080   Pages _implicit_pages;
00081   Pages _explicit_pages;
00082   bool _pages_sorted;
00083   int _next_page_seq;
00084 
00085   bool _loaded_implicit;
00086   bool _currently_loading;
00087 
00088   DSearchPath _search_path;
00089 
00090   typedef vector<GlobPattern> Globs;
00091   Globs _prc_patterns;
00092   Globs _prc_encrypted_patterns;
00093   Globs _prc_executable_patterns;
00094 
00095   // In load_implicit_pages(), we temporarily build up a list of
00096   // potential config files to read and/or execute.  We'll need some
00097   // data structures to store that information.
00098   enum FileFlags {
00099     FF_read     = 0x001,
00100     FF_execute  = 0x002,
00101     FF_decrypt  = 0x004,
00102   };
00103   class ConfigFile {
00104   public:
00105     int _file_flags;
00106     Filename _filename;
00107   };
00108   typedef vector<ConfigFile> ConfigFiles;
00109 
00110   static ConfigPageManager *_global_ptr;
00111 };
00112 
00113 INLINE ostream &operator << (ostream &out, const ConfigPageManager &pageMgr);
00114 
00115 #include "configPageManager.I"
00116 
00117 #endif
 All Classes Functions Variables Enumerations