Panda3D
|
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 INLINE int get_page_seq() const; 00051 INLINE int get_trust_level() const; 00052 INLINE void set_trust_level(int trust_level); 00053 INLINE const string &get_signature() const; 00054 00055 void clear(); 00056 bool read_prc(istream &in); 00057 bool read_encrypted_prc(istream &in, const string &password); 00058 00059 ConfigDeclaration *make_declaration(const string &variable, const string &value); 00060 ConfigDeclaration *make_declaration(ConfigVariableCore *variable, const string &value); 00061 bool delete_declaration(ConfigDeclaration *decl); 00062 00063 int get_num_declarations() const; 00064 const ConfigDeclaration *get_declaration(int n) const; 00065 string get_variable_name(int n) const; 00066 string get_string_value(int n) const; 00067 bool is_variable_used(int n) const; 00068 00069 void output(ostream &out) const; 00070 void output_brief_signature(ostream &out) const; 00071 void write(ostream &out) const; 00072 00073 private: 00074 INLINE void make_dirty(); 00075 void read_prc_line(const string &line); 00076 static unsigned int hex_digit(unsigned char digit); 00077 00078 string _name; 00079 bool _implicit_load; 00080 int _page_seq; 00081 int _next_decl_seq; 00082 int _trust_level; 00083 00084 typedef vector<ConfigDeclaration *> Declarations; 00085 Declarations _declarations; 00086 00087 string _signature; 00088 00089 #ifdef HAVE_OPENSSL 00090 // This maintains the hash of the prc file as we are scanning it, so 00091 // we can compare its signature which we discover at the end. 00092 void *_md_ctx; 00093 #endif // HAVE_OPENSSL 00094 00095 static ConfigPage *_default_page; 00096 static ConfigPage *_local_page; 00097 00098 friend class ConfigPageManager; 00099 }; 00100 00101 INLINE ostream &operator << (ostream &out, const ConfigPage &page); 00102 00103 #include "configPage.I" 00104 00105 #endif