Panda3D
configVariableCore.h
1 // Filename: configVariableCore.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 CONFIGVARIABLECORE_H
16 #define CONFIGVARIABLECORE_H
17 
18 #include "dtoolbase.h"
19 #include "configFlags.h"
20 #include "configPageManager.h"
21 #include "pnotify.h"
22 
23 #include <vector>
24 
25 class ConfigDeclaration;
26 
27 ////////////////////////////////////////////////////////////////////
28 // Class : ConfigVariableCore
29 // Description : The internal definition of a ConfigVariable. This
30 // object is shared between all instances of a
31 // ConfigVariable that use the same variable name.
32 //
33 // You cannot create a ConfigVariableCore instance
34 // directly; instead, use the make() method, which may
35 // return a shared instance. Once created, these
36 // objects are never destructed.
37 ////////////////////////////////////////////////////////////////////
38 class EXPCL_DTOOLCONFIG ConfigVariableCore : public ConfigFlags {
39 private:
40  ConfigVariableCore(const string &name);
41  ConfigVariableCore(const ConfigVariableCore &templ, const string &name);
43 
44 PUBLISHED:
45  INLINE const string &get_name() const;
46  INLINE bool is_used() const;
47 
48  INLINE ValueType get_value_type() const;
49  INLINE const string &get_description() const;
50  INLINE int get_flags() const;
51  INLINE bool is_closed() const;
52  INLINE int get_trust_level() const;
53  INLINE bool is_dynamic() const;
54  INLINE const ConfigDeclaration *get_default_value() const;
55 
56  void set_value_type(ValueType value_type);
57  void set_flags(int flags);
58  void set_description(const string &description);
59  void set_default_value(const string &default_value);
60  INLINE void set_used();
61 
62  ConfigDeclaration *make_local_value();
63  bool clear_local_value();
64  INLINE bool has_local_value() const;
65 
66  bool has_value() const;
67  int get_num_declarations() const;
68  const ConfigDeclaration *get_declaration(int n) const;
69  MAKE_SEQ(get_declarations, get_num_declarations, get_declaration);
70 
71  INLINE int get_num_references() const;
72  INLINE const ConfigDeclaration *get_reference(int n) const;
73  MAKE_SEQ(get_references, get_num_references, get_reference);
74 
75  INLINE int get_num_trusted_references() const;
76  INLINE const ConfigDeclaration *get_trusted_reference(int n) const;
77  MAKE_SEQ(get_trusted_references, get_num_trusted_references, get_trusted_reference);
78 
79  INLINE int get_num_unique_references() const;
80  INLINE const ConfigDeclaration *get_unique_reference(int n) const;
81  MAKE_SEQ(get_unique_references, get_num_unique_references, get_unique_reference);
82 
83  void output(ostream &out) const;
84  void write(ostream &out) const;
85 
86 private:
87  void add_declaration(ConfigDeclaration *decl);
88  void remove_declaration(ConfigDeclaration *decl);
89 
90  INLINE void check_sort_declarations() const;
91  void sort_declarations();
92 
93 private:
94  string _name;
95  bool _is_used;
96  ValueType _value_type;
97  string _description;
98  int _flags;
99  ConfigDeclaration *_default_value;
100  ConfigDeclaration *_local_value;
101 
102  typedef vector<const ConfigDeclaration *> Declarations;
103  Declarations _declarations;
104  Declarations _trusted_declarations;
105  Declarations _untrusted_declarations;
106  Declarations _unique_declarations;
107  bool _declarations_sorted;
108  bool _value_queried;
109 
110  friend class ConfigDeclaration;
111  friend class ConfigVariableManager;
112 };
113 
114 INLINE ostream &operator << (ostream &out, const ConfigVariableCore &variable);
115 
116 #include "configVariableCore.I"
117 
118 #endif
The internal definition of a ConfigVariable.
This class is the base class of both ConfigVariable and ConfigVariableCore.
Definition: configFlags.h:29
A global object that maintains the set of ConfigVariables (actually, ConfigVariableCores) everywhere ...
A single declaration of a config variable, typically defined as one line in a .prc file...