Panda3D
Loading...
Searching...
No Matches
configVariableCore.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 configVariableCore.h
10 * @author drose
11 * @date 2004-10-15
12 */
13
14#ifndef CONFIGVARIABLECORE_H
15#define CONFIGVARIABLECORE_H
16
17#include "dtoolbase.h"
18#include "configFlags.h"
19#include "configPageManager.h"
20#include "pnotify.h"
21
22#include <vector>
23
25
26/**
27 * The internal definition of a ConfigVariable. This object is shared between
28 * all instances of a ConfigVariable that use the same variable name.
29 *
30 * You cannot create a ConfigVariableCore instance directly; instead, use the
31 * make() method, which may return a shared instance. Once created, these
32 * objects are never destructed.
33 */
34class EXPCL_DTOOL_PRC ConfigVariableCore : public ConfigFlags {
35private:
36 ConfigVariableCore(const std::string &name);
37 ConfigVariableCore(const ConfigVariableCore &templ, const std::string &name);
38 ~ConfigVariableCore();
39
40PUBLISHED:
41 INLINE const std::string &get_name() const;
42 INLINE bool is_used() const;
43
44 INLINE ValueType get_value_type() const;
45 INLINE const std::string &get_description() const;
46 INLINE int get_flags() const;
47 INLINE bool is_closed() const;
48 INLINE int get_trust_level() const;
49 INLINE bool is_dynamic() const;
50 INLINE const ConfigDeclaration *get_default_value() const;
51
52 void set_value_type(ValueType value_type);
53 void set_flags(int flags);
54 void set_description(const std::string &description);
55 void set_default_value(const std::string &default_value);
56 INLINE void set_used();
57
58 ConfigDeclaration *make_local_value();
59 bool clear_local_value();
60 INLINE bool has_local_value() const;
61
62 bool has_value() const;
63 size_t get_num_declarations() const;
64 const ConfigDeclaration *get_declaration(size_t n) const;
65 MAKE_SEQ(get_declarations, get_num_declarations, get_declaration);
66
67 INLINE size_t get_num_references() const;
68 INLINE const ConfigDeclaration *get_reference(size_t n) const;
69 MAKE_SEQ(get_references, get_num_references, get_reference);
70
71 INLINE size_t get_num_trusted_references() const;
72 INLINE const ConfigDeclaration *get_trusted_reference(size_t n) const;
73 MAKE_SEQ(get_trusted_references, get_num_trusted_references, get_trusted_reference);
74
75 INLINE size_t get_num_unique_references() const;
76 INLINE const ConfigDeclaration *get_unique_reference(size_t n) const;
77 MAKE_SEQ(get_unique_references, get_num_unique_references, get_unique_reference);
78 MAKE_SEQ_PROPERTY(declarations, get_num_declarations, get_declaration);
79
80 void output(std::ostream &out) const;
81 void write(std::ostream &out) const;
82
83 MAKE_PROPERTY(name, get_name);
84 MAKE_PROPERTY(used, is_used);
85 MAKE_PROPERTY(closed, is_closed);
86 MAKE_PROPERTY(trust_level, get_trust_level);
87 MAKE_PROPERTY(dynamic, is_dynamic);
88
90 MAKE_PROPERTY(description, get_description, set_description);
91 MAKE_PROPERTY(default_value, get_default_value, set_default_value);
92
93 MAKE_SEQ_PROPERTY(references, get_num_references, get_reference);
94 MAKE_SEQ_PROPERTY(trusted_references, get_num_trusted_references, get_trusted_reference);
95 MAKE_SEQ_PROPERTY(unique_references, get_num_unique_references, get_unique_reference);
96
97private:
98 void add_declaration(ConfigDeclaration *decl);
99 void remove_declaration(ConfigDeclaration *decl);
100
101 INLINE void check_sort_declarations() const;
102 void sort_declarations();
103
104private:
105 std::string _name;
106 bool _is_used;
107 ValueType _value_type;
108 std::string _description;
109 int _flags;
110 ConfigDeclaration *_default_value;
111 ConfigDeclaration *_local_value;
112
113 typedef std::vector<const ConfigDeclaration *> Declarations;
114 Declarations _declarations;
115 Declarations _trusted_declarations;
116 Declarations _untrusted_declarations;
117 Declarations _unique_declarations;
118 bool _declarations_sorted;
119 bool _value_queried;
120
121 friend class ConfigDeclaration;
122 friend class ConfigVariableManager;
123};
124
125INLINE std::ostream &operator << (std::ostream &out, const ConfigVariableCore &variable);
126
127#include "configVariableCore.I"
128
129#endif
A single declaration of a config variable, typically defined as one line in a .prc file,...
This class is the base class of both ConfigVariable and ConfigVariableCore.
Definition configFlags.h:26
The internal definition of a ConfigVariable.
void set_flags(int flags)
Specifies the trust level of this variable.
get_trusted_reference
Returns the nth declaration in a trusted prc file that references this variable.
bool has_local_value() const
Returns true if this variable's value has been shadowed by a local assignment (as created via make_lo...
get_num_trusted_references
Returns the number of trusted prc files that reference this variable.
get_declaration
Returns the nth declarations that contributes to this variable's value.
get_unique_reference
Returns the nth trusted, unique value for this variable.
get_value_type
Returns the stated type of this variable.
set_default_value
Specifies the default value for this variable if it is not defined in any prc file.
get_default_value
Returns the default variable specified for this variable.
get_reference
Returns the nth declaration in a prc file that references this variable.
bool has_value() const
Returns true if this variable has an explicit value, either from a prc file or locally set,...
is_dynamic
Returns true if the variable was indicated as "dynamic" by its constructor, indicating that its name ...
void set_used()
Marks that the variable has been "declared" by a ConfigVariable.
set_description
Specifies the one-line description of this variable.
bool clear_local_value()
Removes the local value defined for this variable, and allows its value to be once again retrieved fr...
int get_flags() const
Returns the flags value as set by set_flags().
is_closed
Returns true if the variable is not trusted by any prc file (and hence cannot be modified from its co...
get_num_references
Returns the number of prc files that reference this variable.
get_description
Returns the brief description of this variable, if it has been defined.
get_num_declarations
Returns the number of declarations that contribute to this variable's value.
get_name
Returns the name of the variable.
ConfigDeclaration * make_local_value()
Creates a new local value for this variable, if there is not already one specified.
get_trust_level
Returns the minimum trust_level a prc file must demonstrate in order to redefine the value for this v...
get_num_unique_references
Returns the number of trusted, unique (by string value) values there exist for this variable.
set_value_type
Specifies the type of this variable.
is_used
Returns true if the variable has been referenced by a ConfigVariable somewhere in code,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.