Panda3D
 All Classes Functions Variables Enumerations
configPage.h
1 // Filename: configPage.h
2 // Created by: drose (15Oct04)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef CONFIGPAGE_H
16 #define CONFIGPAGE_H
17 
18 #include "dtoolbase.h"
19 
20 #include <vector>
21 
22 class ConfigDeclaration;
23 class ConfigVariableCore;
24 
25 ////////////////////////////////////////////////////////////////////
26 // Class : ConfigPage
27 // Description : A page of ConfigDeclarations that may be loaded or
28 // unloaded. Typically this represents a single .prc
29 // file that is read from disk at runtime, but it may
30 // also represent a list of declarations built up
31 // by application code and explicitly loaded.
32 ////////////////////////////////////////////////////////////////////
33 class EXPCL_DTOOLCONFIG ConfigPage {
34 private:
35  ConfigPage(const string &name, bool implicit_load, int page_seq);
36  ~ConfigPage();
37 
38 public:
39  INLINE bool operator < (const ConfigPage &other) const;
40 
41 PUBLISHED:
42  static ConfigPage *get_default_page();
43  static ConfigPage *get_local_page();
44 
45  INLINE const string &get_name() const;
46 
47  INLINE bool is_special() const;
48  INLINE bool is_implicit() const;
49 
50  void set_sort(int sort);
51  INLINE int get_sort() const;
52 
53  INLINE int get_page_seq() const;
54  INLINE int get_trust_level() const;
55  INLINE void set_trust_level(int trust_level);
56  INLINE const string &get_signature() const;
57 
58  void clear();
59  bool read_prc(istream &in);
60  bool read_encrypted_prc(istream &in, const string &password);
61 
62  ConfigDeclaration *make_declaration(const string &variable, const string &value);
63  ConfigDeclaration *make_declaration(ConfigVariableCore *variable, const string &value);
64  bool delete_declaration(ConfigDeclaration *decl);
65 
66  int get_num_declarations() const;
67  const ConfigDeclaration *get_declaration(int n) const;
68  ConfigDeclaration *modify_declaration(int n);
69  string get_variable_name(int n) const;
70  string get_string_value(int n) const;
71  bool is_variable_used(int n) const;
72 
73  void output(ostream &out) const;
74  void output_brief_signature(ostream &out) const;
75  void write(ostream &out) const;
76 
77 private:
78  INLINE void make_dirty();
79  void read_prc_line(const string &line);
80  static unsigned int hex_digit(unsigned char digit);
81 
82  string _name;
83  bool _implicit_load;
84  int _page_seq;
85  int _sort;
86  int _next_decl_seq;
87  int _trust_level;
88 
89  typedef vector<ConfigDeclaration *> Declarations;
90  Declarations _declarations;
91 
92  string _signature;
93 
94 #ifdef HAVE_OPENSSL
95  // This maintains the hash of the prc file as we are scanning it, so
96  // we can compare its signature which we discover at the end.
97  void *_md_ctx;
98 #endif // HAVE_OPENSSL
99 
100  static ConfigPage *_default_page;
101  static ConfigPage *_local_page;
102 
103  friend class ConfigPageManager;
104 };
105 
106 INLINE ostream &operator << (ostream &out, const ConfigPage &page);
107 
108 #include "configPage.I"
109 
110 #endif
The internal definition of a ConfigVariable.
A global object that maintains the set of ConfigPages everywhere in the world, and keeps them in sort...
A page of ConfigDeclarations that may be loaded or unloaded.
Definition: configPage.h:33
A single declaration of a config variable, typically defined as one line in a .prc file...