The Battle for Wesnoth  1.15.2+dev
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
vconfig Class Reference

A variable-expanding proxy for the config class. More...

#include <variable.hpp>

Classes

struct  all_children_iterator
 
struct  attribute_iterator
 
struct  recursion_error
 

Public Types

typedef std::vector< vconfigchild_list
 

Public Member Functions

 vconfig (const config &cfg)
 Constructor from a config. More...
 
 vconfig (config &&cfg)
 
 vconfig (const config &cfg, bool manage_memory)
 Constructor from a config, with an option to manage memory. More...
 
 ~vconfig ()
 Default destructor, but defined here for possibly faster compiles (templates sometimes can be rough on the compiler). More...
 
 operator bool () const
 A vconfig evaluates to true iff it can be dereferenced. More...
 
bool null () const
 
const vconfigmake_safe () const
 instruct the vconfig to make a private copy of its underlying data. More...
 
const configget_config () const
 
config get_parsed_config () const
 
child_list get_children (const std::string &key) const
 
std::size_t count_children (const std::string &key) const
 
vconfig child (const std::string &key) const
 Returns a child of *this whose key is key. More...
 
bool has_child (const std::string &key) const
 Returns whether or not *this has a child whose key is key. More...
 
const config::attribute_value operator[] (const std::string &key) const
 Note: vconfig::operator[] returns const, and this should not be changed because vconfig is often used as a drop-in replacement for config, and this const will properly warn you if you try to assign vcfg["key"]=val;. More...
 
config::attribute_value expand (const std::string &) const
 
bool has_attribute (const std::string &key) const
 < Synonym for operator[] More...
 
bool empty () const
 
boost::iterator_range< attribute_iteratorattribute_range ()
 
all_children_iterator ordered_begin () const
 In-order iteration over all children. More...
 
all_children_iterator ordered_end () const
 
boost::iterator_range< all_children_iteratorall_ordered () const
 

Static Public Member Functions

static vconfig empty_vconfig ()
 
static vconfig unconstructed_vconfig ()
 This is just a wrapper for the default constructor; it exists for historical reasons and to make it clear that default construction cannot be dereferenced (in contrast to an empty vconfig). More...
 

Private Member Functions

 vconfig ()
 
 vconfig (const config &cfg, const std::shared_ptr< const config > &cache)
 
bool memory_managed () const
 Returns true if *this has made a copy of its config. More...
 

Private Attributes

std::shared_ptr< const configcache_
 Keeps a copy of our config alive when we manage our own memory. More...
 
const configcfg_
 Used to access our config (original or copy, as appropriate). More...
 

Static Private Attributes

static const config default_empty_config = config()
 

Detailed Description

A variable-expanding proxy for the config class.

This class roughly behaves as a constant config object, but automatically expands variables.

When dealing with a vconfig, keep in mind its lifetime. By default, vconfigs do not maintain a copy their data; if you need a vconfig to stick around, either construct it with manage_memory=true or call make_safe(). This will cause the vconfig to make a copy of the underlying config object.

Definition at line 42 of file variable.hpp.

Member Typedef Documentation

◆ child_list

typedef std::vector<vconfig> vconfig::child_list

Definition at line 78 of file variable.hpp.

Constructor & Destructor Documentation

◆ vconfig() [1/5]

vconfig::vconfig ( )
private

◆ vconfig() [2/5]

vconfig::vconfig ( const config cfg,
const std::shared_ptr< const config > &  cache 
)
private

Definition at line 76 of file variable.cpp.

◆ vconfig() [3/5]

vconfig::vconfig ( const config cfg)
inlineexplicit

Constructor from a config.

Equivalent to vconfig(cfg, false). Do not use if the vconfig will persist after cfg is destroyed!

Definition at line 62 of file variable.hpp.

◆ vconfig() [4/5]

vconfig::vconfig ( config &&  cfg)
inlineexplicit

Definition at line 63 of file variable.hpp.

◆ vconfig() [5/5]

vconfig::vconfig ( const config cfg,
bool  manage_memory 
)

Constructor from a config, with an option to manage memory.

Parameters
[in]cfgThe "WML source" of the vconfig being constructed.
[in]manage_memoryIf true, a copy of cfg will be made, allowing the vconfig to safely persist after cfg is destroyed. If false, no copy is made, so cfg must be guaranteed to persist as long as the vconfig will. If in doubt, set to true; it is less efficient, but safe. See also make_safe().

Definition at line 91 of file variable.cpp.

◆ ~vconfig()

vconfig::~vconfig ( )

Default destructor, but defined here for possibly faster compiles (templates sometimes can be rough on the compiler).

Definition at line 101 of file variable.cpp.

Referenced by lua_common::impl_vconfig_collect().

Member Function Documentation

◆ all_ordered()

boost::iterator_range<all_children_iterator> vconfig::all_ordered ( ) const
inline

Definition at line 188 of file variable.hpp.

Referenced by unit_filter_impl::unit_filter_compound::fill().

◆ attribute_range()

boost::iterator_range<attribute_iterator> vconfig::attribute_range ( )
inline

Definition at line 130 of file variable.hpp.

References config::attribute_range(), and config_variable_set::cfg_.

◆ child()

vconfig vconfig::child ( const std::string &  key) const

◆ count_children()

std::size_t vconfig::count_children ( const std::string &  key) const

Definition at line 220 of file variable.cpp.

References config::all_children_range(), cfg_, child(), and n.

◆ empty()

bool vconfig::empty ( ) const
inline

◆ empty_vconfig()

vconfig vconfig::empty_vconfig ( )
static

◆ expand()

config::attribute_value vconfig::expand ( const std::string &  key) const

◆ get_children()

vconfig::child_list vconfig::get_children ( const std::string &  key) const

◆ get_config()

const config& vconfig::get_config ( ) const
inline

◆ get_parsed_config()

config vconfig::get_parsed_config ( ) const

◆ has_attribute()

bool vconfig::has_attribute ( const std::string &  key) const
inline

◆ has_child()

bool vconfig::has_child ( const std::string &  key) const

◆ make_safe()

const vconfig & vconfig::make_safe ( ) const

instruct the vconfig to make a private copy of its underlying data.

Ensures that *this manages its own memory, making it safe for *this to outlive the config it was ultimately constructed from.

It is perfectly safe to call this for a vconfig that already manages its memory. This does not work on a null() vconfig.

Definition at line 127 of file variable.cpp.

References cache_, cfg_, and memory_managed().

Referenced by ai::ai_default_rca::aspect_attacks::aspect_attacks(), side_filter::match_internal(), and game_events::wml_menu_item::update().

◆ memory_managed()

bool vconfig::memory_managed ( ) const
inlineprivate

Returns true if *this has made a copy of its config.

Definition at line 194 of file variable.hpp.

Referenced by make_safe().

◆ null()

bool vconfig::null ( ) const
inline

◆ operator bool()

vconfig::operator bool ( ) const
inlineexplicit

A vconfig evaluates to true iff it can be dereferenced.

Definition at line 71 of file variable.hpp.

◆ operator[]()

const config::attribute_value vconfig::operator[] ( const std::string &  key) const
inline

Note: vconfig::operator[] returns const, and this should not be changed because vconfig is often used as a drop-in replacement for config, and this const will properly warn you if you try to assign vcfg["key"]=val;.

Note: The following construction is unsafe: const std::string& temp = vcfg["foo"]; This binds temp to a member of a temporary t_string. The lifetime of the temporary is not extended by this reference binding and the temporary's lifetime ends which causes UB. Instead use: const std::string temp = vcfg["foo"];

Definition at line 96 of file variable.hpp.

◆ ordered_begin()

vconfig::all_children_iterator vconfig::ordered_begin ( ) const

◆ ordered_end()

vconfig::all_children_iterator vconfig::ordered_end ( ) const

◆ unconstructed_vconfig()

vconfig vconfig::unconstructed_vconfig ( )
static

This is just a wrapper for the default constructor; it exists for historical reasons and to make it clear that default construction cannot be dereferenced (in contrast to an empty vconfig).

Definition at line 116 of file variable.cpp.

References vconfig().

Referenced by child(), game_lua_kernel::intf_find_cost_map(), luaW_checkvconfig(), luaW_tofaivariant(), and luaW_tolocation().

Member Data Documentation

◆ cache_

std::shared_ptr<const config> vconfig::cache_
mutableprivate

Keeps a copy of our config alive when we manage our own memory.

If this is not null, then cfg_ points to *cache_ or a child of *cache_.

Definition at line 198 of file variable.hpp.

Referenced by child(), get_children(), and make_safe().

◆ cfg_

const config* vconfig::cfg_
mutableprivate

Used to access our config (original or copy, as appropriate).

Definition at line 200 of file variable.hpp.

Referenced by child(), count_children(), get_children(), get_parsed_config(), has_child(), make_safe(), ordered_begin(), and ordered_end().

◆ default_empty_config

const config vconfig::default_empty_config = config()
staticprivate

Definition at line 201 of file variable.hpp.

Referenced by config_variable_set::get_variable_const().


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