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