Panda3D
Public Member Functions | Friends | List of all members
ConfigVariableCore Class Reference

The internal definition of a ConfigVariable. More...

#include "configVariableCore.h"

Inheritance diagram for ConfigVariableCore:
ConfigFlags

Public Member Functions

bool clear_local_value ()
 Removes the local value defined for this variable, and allows its value to be once again retrieved from the .prc files. More...
 
const ConfigDeclarationget_declaration (int n) const
 Returns the nth declarations that contributes to this variable's value. More...
 
const ConfigDeclarationget_default_value () const
 Returns the default variable specified for this variable. More...
 
const string & get_description () const
 Returns the brief description of this variable, if it has been defined. More...
 
int get_flags () const
 Returns the flags value as set by set_flags(). More...
 
const string & get_name () const
 Returns the name of the variable. More...
 
int get_num_declarations () const
 Returns the number of declarations that contribute to this variable's value. More...
 
int get_num_references () const
 Returns the number of prc files that reference this variable. More...
 
int get_num_trusted_references () const
 Returns the number of trusted prc files that reference this variable. More...
 
int get_num_unique_references () const
 Returns the number of trusted, unique (by string value) values there exist for this variable. More...
 
const ConfigDeclarationget_reference (int n) const
 Returns the nth declaration in a prc file that references this variable. More...
 
int get_trust_level () const
 Returns the minimum trust_level a prc file must demonstrate in order to redefine the value for this variable. More...
 
const ConfigDeclarationget_trusted_reference (int n) const
 Returns the nth declaration in a trusted prc file that references this variable. More...
 
const ConfigDeclarationget_unique_reference (int n) const
 Returns the nth trusted, unique value for this variable. More...
 
ValueType get_value_type () const
 Returns the stated type of this variable. More...
 
bool has_local_value () const
 Returns true if this variable's value has been shadowed by a local assignment (as created via make_local_value()), or false otherwise. More...
 
bool has_value () const
 Returns true if this variable has an explicit value, either from a prc file or locally set, or false if variable has its default value. More...
 
bool is_closed () const
 Returns true if the variable is not trusted by any prc file (and hence cannot be modified from its compiled-in default value), or false for the normal case, in which the variable can be modified by any prc file at or above its trust level (see get_trust_level()). More...
 
bool is_dynamic () const
 Returns true if the variable was indicated as "dynamic" by its constructor, indicating that its name was dynamically generated, possibly from a large pool, and it should not be listed along with the other variables. More...
 
bool is_used () const
 Returns true if the variable has been referenced by a ConfigVariable somewhere in code, false otherwise. More...
 
ConfigDeclarationmake_local_value ()
 Creates a new local value for this variable, if there is not already one specified. More...
 
 MAKE_SEQ (get_declarations, get_num_declarations, get_declaration)
 
 MAKE_SEQ (get_references, get_num_references, get_reference)
 
 MAKE_SEQ (get_trusted_references, get_num_trusted_references, get_trusted_reference)
 
 MAKE_SEQ (get_unique_references, get_num_unique_references, get_unique_reference)
 
void output (ostream &out) const
 
void set_default_value (const string &default_value)
 Specifies the default value for this variable if it is not defined in any prc file. More...
 
void set_description (const string &description)
 Specifies the one-line description of this variable. More...
 
void set_flags (int flags)
 Specifies the trust level of this variable. More...
 
void set_used ()
 Marks that the variable has been "declared" by a ConfigVariable. More...
 
void set_value_type (ValueType value_type)
 Specifies the type of this variable. More...
 
void write (ostream &out) const
 

Friends

class ConfigDeclaration
 
class ConfigVariableManager
 

Additional Inherited Members

- Public Types inherited from ConfigFlags
enum  ValueType {
  VT_undefined, VT_list, VT_string, VT_filename,
  VT_bool, VT_int, VT_double, VT_enum,
  VT_search_path, VT_int64, VT_color
}
 
enum  VariableFlags {
  F_trust_level_mask = 0x00000fff, F_open = 0x00001000, F_closed = 0x00002000, F_dynamic = 0x00004000,
  F_dconfig = 0x00008000
}
 

Detailed Description

The internal definition of a ConfigVariable.

This object is shared between all instances of a ConfigVariable that use the same variable name.

You cannot create a ConfigVariableCore instance directly; instead, use the make() method, which may return a shared instance. Once created, these objects are never destructed.

Definition at line 38 of file configVariableCore.h.

Member Function Documentation

◆ clear_local_value()

bool ConfigVariableCore::clear_local_value ( )

Removes the local value defined for this variable, and allows its value to be once again retrieved from the .prc files.

Returns true if the value was successfully removed, false if it did not exist in the first place.

Definition at line 286 of file configVariableCore.cxx.

References ConfigPage::delete_declaration(), ConfigPage::get_local_page(), and has_value().

Referenced by ConfigVariableBase::clear_local_value(), and make_local_value().

◆ get_declaration()

const ConfigDeclaration * ConfigVariableCore::get_declaration ( int  n) const

Returns the nth declarations that contributes to this variable's value.

The declarations are arranged in order such that earlier declarations shadow later declarations; thus, get_declaration(0) is always defined and always returns the current value of the variable.

Definition at line 346 of file configVariableCore.cxx.

References ConfigVariableBase::get_name(), and ConfigVariableBase::has_local_value().

Referenced by get_num_declarations(), and ConfigVariableManager::list_dynamic_variables().

◆ get_default_value()

const ConfigDeclaration * ConfigVariableCore::get_default_value ( ) const
inline

Returns the default variable specified for this variable.

If the variable has not yet been defined, this will return NULL.

Definition at line 135 of file configVariableCore.I.

References set_used().

Referenced by is_dynamic(), ConfigVariableManager::list_dynamic_variables(), and ConfigVariableManager::make_variable_template().

◆ get_description()

const string & ConfigVariableCore::get_description ( ) const
inline

Returns the brief description of this variable, if it has been defined.

Definition at line 56 of file configVariableCore.I.

References get_flags().

Referenced by ConfigVariableBase::get_description(), get_value_type(), and ConfigVariableManager::list_dynamic_variables().

◆ get_flags()

int ConfigVariableCore::get_flags ( ) const
inline

Returns the flags value as set by set_flags().

This includes the trust level and some other settings. See the individual methods is_closed(), get_trust_level(), etc. to pull out the semantic meaning of these flags individually.

Definition at line 70 of file configVariableCore.I.

References is_closed().

Referenced by get_description(), and ConfigVariableBase::get_flags().

◆ get_name()

const string & ConfigVariableCore::get_name ( ) const
inline

◆ get_num_declarations()

int ConfigVariableCore::get_num_declarations ( ) const

Returns the number of declarations that contribute to this variable's value.

If the variable has been defined, this will always be at least 1 (for the default value, at least).

Definition at line 322 of file configVariableCore.cxx.

References get_declaration(), and ConfigVariableBase::has_local_value().

Referenced by has_value().

◆ get_num_references()

int ConfigVariableCore::get_num_references ( ) const
inline

Returns the number of prc files that reference this variable.

This is not exactly the same as the number of declarations; see get_reference().

Definition at line 170 of file configVariableCore.I.

References get_reference().

Referenced by has_local_value(), ConfigVariableManager::list_dynamic_variables(), and ConfigVariableManager::list_unused_variables().

◆ get_num_trusted_references()

int ConfigVariableCore::get_num_trusted_references ( ) const
inline

Returns the number of trusted prc files that reference this variable.

See also get_num_references().

Definition at line 201 of file configVariableCore.I.

References get_trusted_reference().

Referenced by get_reference(), ConfigVariableManager::is_variable_used(), ConfigVariableManager::list_dynamic_variables(), and ConfigVariableManager::write_prc_variables().

◆ get_num_unique_references()

int ConfigVariableCore::get_num_unique_references ( ) const
inline

Returns the number of trusted, unique (by string value) values there exist for this variable.

Definition at line 234 of file configVariableCore.I.

References get_unique_reference().

Referenced by get_trusted_reference().

◆ get_reference()

const ConfigDeclaration * ConfigVariableCore::get_reference ( int  n) const
inline

Returns the nth declaration in a prc file that references this variable.

This is similar, but not identical to, get_declaration(). The difference is that this will list *only* true references in a prc file, and will not list default values or locally-assigned values; it also will list even the untrusted files.

Definition at line 187 of file configVariableCore.I.

References get_num_trusted_references().

Referenced by get_num_references(), ConfigVariableManager::list_dynamic_variables(), and ConfigVariableManager::list_unused_variables().

◆ get_trust_level()

int ConfigVariableCore::get_trust_level ( ) const
inline

Returns the minimum trust_level a prc file must demonstrate in order to redefine the value for this variable.

Arguably, this should be called the "mistrust level", since the larger the value, the more suspicious we are of prc files. This value is not used if is_closed() returns true, which indicates no file may be trusted.

This value only has effect in a release build (specifically, when PRC_RESPECT_TRUST_LEVEL is defined true in Config.pp).

Definition at line 109 of file configVariableCore.I.

References is_dynamic().

Referenced by ConfigVariableBase::get_trust_level(), and is_closed().

◆ get_trusted_reference()

const ConfigDeclaration * ConfigVariableCore::get_trusted_reference ( int  n) const
inline

Returns the nth declaration in a trusted prc file that references this variable.

This is similar, but not identical to, get_declaration(). The difference is that this will list *only* true references in a prc file, and will not list default values or locally-assigned values.

This is also similar to get_reference(), except that it only lists the trusted declarations, omitting the untrusted ones.

Definition at line 221 of file configVariableCore.I.

References get_num_unique_references().

Referenced by get_num_trusted_references(), ConfigVariableManager::list_dynamic_variables(), and ConfigVariableManager::write_prc_variables().

◆ get_unique_reference()

const ConfigDeclaration * ConfigVariableCore::get_unique_reference ( int  n) const
inline

Returns the nth trusted, unique value for this variable.

This is similar to get_trusted_reference(), except that duplicate values are removed.

Definition at line 248 of file configVariableCore.I.

References ConfigPageManager::load_implicit_pages().

Referenced by get_num_unique_references().

◆ get_value_type()

ConfigVariableCore::ValueType ConfigVariableCore::get_value_type ( ) const
inline

Returns the stated type of this variable.

If the variable has not yet been defined, this will be VT_undefined.

Definition at line 45 of file configVariableCore.I.

References get_description().

Referenced by ConfigVariableBase::get_value_type(), is_used(), ConfigVariableManager::list_dynamic_variables(), and ConfigVariableManager::write_prc_variables().

◆ has_local_value()

bool ConfigVariableCore::has_local_value ( ) const
inline

Returns true if this variable's value has been shadowed by a local assignment (as created via make_local_value()), or false otherwise.

Definition at line 158 of file configVariableCore.I.

References get_num_references().

Referenced by ConfigVariableBase::has_local_value(), ConfigVariableManager::is_variable_used(), and set_used().

◆ has_value()

bool ConfigVariableCore::has_value ( ) const

Returns true if this variable has an explicit value, either from a prc file or locally set, or false if variable has its default value.

Definition at line 305 of file configVariableCore.cxx.

References get_num_declarations(), and ConfigVariableBase::has_local_value().

Referenced by clear_local_value(), and ConfigVariableBase::has_value().

◆ is_closed()

bool ConfigVariableCore::is_closed ( ) const
inline

Returns true if the variable is not trusted by any prc file (and hence cannot be modified from its compiled-in default value), or false for the normal case, in which the variable can be modified by any prc file at or above its trust level (see get_trust_level()).

This value only has effect in a release build (specifically, when PRC_RESPECT_TRUST_LEVEL is defined true in Config.pp).

Definition at line 89 of file configVariableCore.I.

References get_trust_level().

Referenced by get_flags(), and ConfigVariableBase::is_closed().

◆ is_dynamic()

bool ConfigVariableCore::is_dynamic ( ) const
inline

Returns true if the variable was indicated as "dynamic" by its constructor, indicating that its name was dynamically generated, possibly from a large pool, and it should not be listed along with the other variables.

Definition at line 123 of file configVariableCore.I.

References get_default_value().

Referenced by get_trust_level(), ConfigVariableBase::is_dynamic(), ConfigVariableManager::list_dynamic_variables(), and ConfigVariableManager::list_variables().

◆ is_used()

bool ConfigVariableCore::is_used ( ) const
inline

Returns true if the variable has been referenced by a ConfigVariable somewhere in code, false otherwise.

Definition at line 33 of file configVariableCore.I.

References get_value_type().

Referenced by get_name(), ConfigVariableManager::list_dynamic_variables(), ConfigVariableManager::list_unused_variables(), and ConfigVariableManager::list_variables().

◆ make_local_value()

ConfigDeclaration * ConfigVariableCore::make_local_value ( )

Creates a new local value for this variable, if there is not already one specified.

This will shadow any values defined in the various .prc files.

If there is already a local value defined for this variable, simply returns that one.

Use clear_local_value() to remove the local value definition.

Definition at line 258 of file configVariableCore.cxx.

References clear_local_value(), ConfigPage::get_local_page(), ConfigVariableBase::is_closed(), and ConfigPage::make_declaration().

Referenced by set_default_value().

◆ set_default_value()

void ConfigVariableCore::set_default_value ( const string &  default_value)

Specifies the default value for this variable if it is not defined in any prc file.

Definition at line 211 of file configVariableCore.cxx.

References ConfigPage::get_default_page(), ConfigVariableBase::get_name(), ConfigDeclaration::get_string_value(), ConfigPage::make_declaration(), and make_local_value().

Referenced by ConfigVariableManager::make_variable_template(), and set_description().

◆ set_description()

void ConfigVariableCore::set_description ( const string &  description)

Specifies the one-line description of this variable.

See get_description(). It is not an error to call this multiple times, but if the value changes once get_declaration() has been called, a warning is printed.

Definition at line 167 of file configVariableCore.cxx.

References ConfigVariableBase::get_name(), and set_default_value().

Referenced by ConfigVariableManager::make_variable_template(), and set_flags().

◆ set_flags()

void ConfigVariableCore::set_flags ( int  flags)

Specifies the trust level of this variable.

See get_flags(). It is not an error to call this multiple times, but if the value changes once get_declaration() has been called, a warning is printed.

Definition at line 125 of file configVariableCore.cxx.

References ConfigVariableBase::get_name(), and set_description().

Referenced by ConfigVariableManager::make_variable_template(), and set_value_type().

◆ set_used()

void ConfigVariableCore::set_used ( )
inline

Marks that the variable has been "declared" by a ConfigVariable.

Definition at line 146 of file configVariableCore.I.

References has_local_value().

Referenced by get_default_value(), and ConfigVariableManager::make_variable_template().

◆ set_value_type()

void ConfigVariableCore::set_value_type ( ConfigVariableCore::ValueType  value_type)

Specifies the type of this variable.

See get_value_type(). It is not an error to call this multiple times, but if the value changes once get_declaration() has been called, a warning is printed.

Definition at line 96 of file configVariableCore.cxx.

References ConfigVariableBase::get_name(), and set_flags().

Referenced by ConfigVariableManager::make_variable_template().


The documentation for this class was generated from the following files: