Panda3D
 All Classes Functions Variables Enumerations
configPage.h
00001 // Filename: configPage.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 CONFIGPAGE_H
00016 #define CONFIGPAGE_H
00017 
00018 #include "dtoolbase.h"
00019 
00020 #include <vector>
00021 
00022 class ConfigDeclaration;
00023 class ConfigVariableCore;
00024 
00025 ////////////////////////////////////////////////////////////////////
00026 //       Class : ConfigPage
00027 // Description : A page of ConfigDeclarations that may be loaded or
00028 //               unloaded.  Typically this represents a single .prc
00029 //               file that is read from disk at runtime, but it may
00030 //               also represent a list of declarations built up
00031 //               by application code and explicitly loaded.
00032 ////////////////////////////////////////////////////////////////////
00033 class EXPCL_DTOOLCONFIG ConfigPage {
00034 private:
00035   ConfigPage(const string &name, bool implicit_load, int page_seq);
00036   ~ConfigPage();
00037 
00038 public:
00039   INLINE bool operator < (const ConfigPage &other) const;
00040 
00041 PUBLISHED:
00042   static ConfigPage *get_default_page();
00043   static ConfigPage *get_local_page();
00044 
00045   INLINE const string &get_name() const;
00046 
00047   INLINE bool is_special() const;
00048   INLINE bool is_implicit() const;
00049 
00050   void set_sort(int sort);
00051   INLINE int get_sort() const;
00052 
00053   INLINE int get_page_seq() const;
00054   INLINE int get_trust_level() const;
00055   INLINE void set_trust_level(int trust_level);
00056   INLINE const string &get_signature() const;
00057 
00058   void clear();
00059   bool read_prc(istream &in);
00060   bool read_encrypted_prc(istream &in, const string &password);
00061 
00062   ConfigDeclaration *make_declaration(const string &variable, const string &value);
00063   ConfigDeclaration *make_declaration(ConfigVariableCore *variable, const string &value);
00064   bool delete_declaration(ConfigDeclaration *decl);
00065 
00066   int get_num_declarations() const;
00067   const ConfigDeclaration *get_declaration(int n) const;
00068   ConfigDeclaration *modify_declaration(int n);
00069   string get_variable_name(int n) const;
00070   string get_string_value(int n) const;
00071   bool is_variable_used(int n) const;
00072 
00073   void output(ostream &out) const;
00074   void output_brief_signature(ostream &out) const;
00075   void write(ostream &out) const;
00076 
00077 private:
00078   INLINE void make_dirty();
00079   void read_prc_line(const string &line);
00080   static unsigned int hex_digit(unsigned char digit);
00081 
00082   string _name;
00083   bool _implicit_load;
00084   int _page_seq;
00085   int _sort;
00086   int _next_decl_seq;
00087   int _trust_level;
00088 
00089   typedef vector<ConfigDeclaration *> Declarations;
00090   Declarations _declarations;
00091 
00092   string _signature;
00093 
00094 #ifdef HAVE_OPENSSL
00095   // This maintains the hash of the prc file as we are scanning it, so
00096   // we can compare its signature which we discover at the end.
00097   void *_md_ctx;
00098 #endif  // HAVE_OPENSSL
00099 
00100   static ConfigPage *_default_page;
00101   static ConfigPage *_local_page;
00102 
00103   friend class ConfigPageManager;
00104 };
00105 
00106 INLINE ostream &operator << (ostream &out, const ConfigPage &page);
00107 
00108 #include "configPage.I"
00109 
00110 #endif
 All Classes Functions Variables Enumerations