The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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  recursion_error
 

Public Types

typedef std::vector< vconfigchild_list
 

Public Member Functions

 vconfig (const config &cfg)
 Constructor from a config. More...
 
 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
 
void make_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
 
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
 
all_children_iterator ordered_begin () const
 In-order iteration over all children. More...
 
all_children_iterator ordered_end () const
 
std::pair
< all_children_iterator,
all_children_iterator
all_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 boost::shared_ptr< const config > &cache)
 
bool memory_managed () const
 Returns true if *this has made a copy of its config. More...
 

Private Attributes

boost::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 36 of file variable.hpp.

Member Typedef Documentation

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

Definition at line 71 of file variable.hpp.

Constructor & Destructor Documentation

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

Definition at line 68 of file variable.cpp.

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 56 of file variable.hpp.

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 83 of file variable.cpp.

vconfig::~vconfig ( )

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

Definition at line 93 of file variable.cpp.

Referenced by lua_common::impl_vconfig_collect().

Member Function Documentation

std::pair<all_children_iterator,all_children_iterator> vconfig::all_ordered ( ) const
inline

Definition at line 146 of file variable.hpp.

References ordered_begin(), and ordered_end().

vconfig vconfig::child ( const std::string key) const
size_t vconfig::count_children ( const std::string key) const
bool vconfig::empty ( ) const
inline
vconfig vconfig::empty_vconfig ( )
static
config::attribute_value vconfig::expand ( const std::string key) const
vconfig::child_list vconfig::get_children ( const std::string key) const
const config& vconfig::get_config ( ) const
inline
config vconfig::get_parsed_config ( ) const
bool vconfig::has_attribute ( const std::string key) const
inline
bool vconfig::has_child ( const std::string key) const
void 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 119 of file variable.cpp.

References cache_, cfg_, and memory_managed().

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

bool vconfig::memory_managed ( ) const
inlineprivate

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

Definition at line 152 of file variable.hpp.

References cache_.

Referenced by make_safe().

bool vconfig::null ( ) const
inline
vconfig::operator bool ( ) const
inlineexplicit

A vconfig evaluates to true iff it can be dereferenced.

Definition at line 64 of file variable.hpp.

References null().

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 89 of file variable.hpp.

References expand().

vconfig::all_children_iterator vconfig::ordered_begin ( ) const
vconfig::all_children_iterator vconfig::ordered_end ( ) const
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 108 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

boost::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 156 of file variable.hpp.

Referenced by child(), vconfig::all_children_iterator::get_child(), get_children(), make_safe(), memory_managed(), ordered_begin(), and ordered_end().

const config* vconfig::cfg_
mutableprivate

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

Definition at line 158 of file variable.hpp.

Referenced by child(), count_children(), empty(), get_children(), get_config(), get_parsed_config(), has_attribute(), has_child(), make_safe(), null(), ordered_begin(), and ordered_end().

const config vconfig::default_empty_config = config()
staticprivate

Definition at line 159 of file variable.hpp.

Referenced by null().


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