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< vconfig > | child_list |
Public Member Functions | |
vconfig (const config &cfg) | |
Constructor from a config. More... | |
vconfig (config &&cfg) | |
vconfig (const config &cfg, const variable_set &variables) | |
vconfig (const config &cfg, bool manage_memory, const variable_set *variables=nullptr) | |
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 vconfig & | make_safe () const |
instruct the vconfig to make a private copy of its underlying data. More... | |
const config & | get_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_iterator > | attribute_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_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 std::shared_ptr< const config > &cache) | |
vconfig (const config &cfg, const std::shared_ptr< const config > &cache, const variable_set &variables) | |
bool | memory_managed () const |
Returns true if *this has made a copy of its config. More... | |
Private Attributes | |
std::shared_ptr< const config > | cache_ |
Keeps a copy of our config alive when we manage our own memory. More... | |
const config * | cfg_ |
Used to access our config (original or copy, as appropriate). More... | |
const variable_set * | variables_ |
Static Private Attributes | |
static const config | default_empty_config = config() |
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 44 of file variable.hpp.
typedef std::vector<vconfig> vconfig::child_list |
Definition at line 78 of file variable.hpp.
|
private |
Definition at line 89 of file variable.cpp.
Referenced by child(), empty_vconfig(), vconfig::all_children_iterator::get_child(), get_children(), vconfig::all_children_iterator::get_key(), get_parsed_config(), vconfig::all_children_iterator::operator++(), and unconstructed_vconfig().
Definition at line 94 of file variable.cpp.
|
private |
Definition at line 125 of file variable.cpp.
|
explicit |
Constructor from a config.
Equivalent to vconfig(cfg, false). Do not use if the vconfig will persist after cfg is destroyed!
Definition at line 117 of file variable.cpp.
|
explicit |
Definition at line 121 of file variable.cpp.
vconfig::vconfig | ( | const config & | cfg, |
const variable_set & | variables | ||
) |
Definition at line 129 of file variable.cpp.
vconfig::vconfig | ( | const config & | cfg, |
bool | manage_memory, | ||
const variable_set * | vars = nullptr |
||
) |
Constructor from a config, with an option to manage memory.
[in] | cfg | The "WML source" of the vconfig being constructed. |
[in] | manage_memory | If 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. |
[in] | vars | See also make_safe(). |
Definition at line 110 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 137 of file variable.cpp.
Referenced by lua_common::impl_vconfig_collect().
|
inline |
Definition at line 190 of file variable.hpp.
References ordered_begin(), and ordered_end().
Referenced by game_events::conditional_passed(), terrain_filter::get_locs_impl(), side_filter::match(), terrain_filter::match_impl(), and storyscreen::story_parser::resolve_wml().
|
inline |
Definition at line 131 of file variable.hpp.
References config::attribute_range(), cfg_, and variables_.
vconfig vconfig::child | ( | const std::string & | key | ) | const |
Returns a child of *this whose key is key.
If no such child exists, returns an unconstructed vconfig (use null() to test for this).
Definition at line 288 of file variable.cpp.
References cache_, cfg_, config::child_range(), empty_vconfig(), config::optional_child(), unconstructed_vconfig(), variables_, and vconfig().
Referenced by terrain_filter::get_locs_impl(), game_lua_kernel::get_sides_vector(), unit::init(), game_lua_kernel::intf_add_tile_overlay(), terrain_filter::match_impl(), terrain_filter::match_internal(), side_filter::match_internal(), game_events::wml_menu_item::update(), and game_events::WML_HANDLER_FUNCTION().
std::size_t vconfig::count_children | ( | const std::string & | key | ) | const |
Definition at line 256 of file variable.cpp.
References config::all_children_view(), cfg_, n, and variables_.
|
inline |
Definition at line 100 of file variable.hpp.
References cfg_, and config::empty().
Referenced by game_events::wml_menu_item::can_show(), game_events::filter_attack::operator()(), storyscreen::controller::resolve_wml_helper(), game_events::wml_menu_item::to_config(), and game_events::WML_HANDLER_FUNCTION().
|
static |
Definition at line 141 of file variable.cpp.
References vconfig().
Referenced by child(), events::console_handler::do_inspect(), vconfig::all_children_iterator::get_child(), get_children(), and game_events::event_handler::read_filters().
config::attribute_value vconfig::expand | ( | const std::string & | key | ) | const |
Definition at line 352 of file variable.cpp.
References config_attribute_value::apply_visitor(), and variables_.
Referenced by get_parsed_config(), lua_common::impl_vconfig_get(), and operator[]().
vconfig::child_list vconfig::get_children | ( | const std::string & | key | ) | const |
Definition at line 226 of file variable.cpp.
References config::all_children_view(), cache_, cfg_, empty_vconfig(), variables_, and vconfig().
Referenced by terrain_filter::get_locs_impl(), unit::init(), game_lua_kernel::intf_replace_schedule(), and terrain_filter::match_internal().
|
inline |
Definition at line 75 of file variable.hpp.
References cfg_.
Referenced by unit_filter::empty(), unit_filter_impl::unit_filter_compound::fill(), side_filter::get_config(), get_parsed_config(), lua_common::impl_vconfig_dir(), lua_common::impl_vconfig_get(), lua_common::impl_vconfig_pairs(), unit::init(), game_lua_kernel::intf_add_event_wml(), game_lua_kernel::intf_add_label(), lua_wml::intf_clone_wml(), game_events::filter_condition::serialize(), game_events::filter_attack::serialize(), terrain_filter::to_config(), unit_filter::to_config(), game_events::wml_menu_item::to_config(), game_events::builtin_conditions::variable_matches(), and game_events::WML_HANDLER_FUNCTION().
config vconfig::get_parsed_config | ( | ) | const |
Definition at line 176 of file variable.cpp.
References _(), config::add_child(), config::all_children_view(), config::attribute_range(), cfg_, config::erase(), lg::err(), expand(), get_config(), variables_, vconfig(), and WRN_NG.
Referenced by lua_common::impl_vconfig_get(), game_lua_kernel::intf_add_event_wml(), game_lua_kernel::intf_add_time_area(), game_lua_kernel::intf_replace_schedule(), lua_wml::intf_wml_interpolate(), luaW_tofaivariant(), game_events::filter_attack::operator()(), and storyscreen::part::resolve_wml_helper().
|
inline |
< Synonym for operator[]
Definition at line 99 of file variable.hpp.
References cfg_, and config::has_attribute().
Referenced by terrain_filter::get_locs_impl(), game_events::builtin_conditions::have_location(), game_events::builtin_conditions::have_unit(), lua_common::impl_vconfig_get(), terrain_filter::match_internal(), side_filter::match_internal(), storyscreen::part::resolve_wml(), game_events::wml_menu_item::update(), verify_and_clear_global_variable(), verify_and_get_global_variable(), and verify_and_set_global_variable().
bool vconfig::has_child | ( | const std::string & | key | ) | const |
Returns whether or not *this has a child whose key is key.
Definition at line 315 of file variable.cpp.
References cfg_, config::child_range(), config::has_child(), and variables_.
Referenced by terrain_filter::get_locs_impl(), terrain_filter::match_impl(), terrain_filter::match_internal(), and side_filter::match_internal().
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 163 of file variable.cpp.
References cache_, cfg_, and memory_managed().
Referenced by ai::ai_default_rca::aspect_attacks::aspect_attacks(), ai::candidate_action::candidate_action(), terrain_filter::match_internal(), side_filter::match_internal(), and game_events::wml_menu_item::update().
|
inlineprivate |
Returns true if *this has made a copy of its config.
Definition at line 196 of file variable.hpp.
References cache_.
Referenced by make_safe().
|
inline |
Definition at line 72 of file variable.hpp.
References cfg_, and default_empty_config.
Referenced by game_lua_kernel::get_sides_vector(), lua_common::impl_vconfig_get(), lua_common::impl_vconfig_size(), unit::init(), game_lua_kernel::intf_add_tile_overlay(), game_lua_kernel::intf_find_cost_map(), game_lua_kernel::intf_get_recall_units(), game_lua_kernel::intf_get_sides(), game_lua_kernel::intf_match_location(), game_lua_kernel::intf_match_side(), game_lua_kernel::intf_match_unit(), luaW_checkvconfig(), terrain_filter::match_internal(), side_filter::match_internal(), and storyscreen::part::resolve_wml().
|
inlineexplicit |
A vconfig evaluates to true iff it can be dereferenced.
Definition at line 70 of file variable.hpp.
|
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.
References expand().
vconfig::all_children_iterator vconfig::ordered_begin | ( | ) | const |
In-order iteration over all children.
Definition at line 480 of file variable.cpp.
References cache_, cfg_, config::ordered_begin(), and variables_.
Referenced by all_ordered(), terrain_filter::get_locs_impl(), lua_common::impl_vconfig_get(), lua_common::impl_vconfig_ipairs(), and lua_common::impl_vconfig_size().
vconfig::all_children_iterator vconfig::ordered_end | ( | ) | const |
Definition at line 485 of file variable.cpp.
References cache_, cfg_, config::ordered_end(), and variables_.
Referenced by all_ordered(), terrain_filter::get_locs_impl(), lua_common::impl_vconfig_get(), lua_common::impl_vconfig_ipairs(), and lua_common::impl_vconfig_size().
|
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 152 of file variable.cpp.
References vconfig().
Referenced by child(), game_lua_kernel::intf_find_cost_map(), game_lua_kernel::intf_gamestate_inspector(), lua_check_impl::lua_to_or_default(), luaW_checkvconfig(), luaW_tofaivariant(), and luaW_tolocation().
|
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 202 of file variable.hpp.
Referenced by child(), vconfig::all_children_iterator::get_child(), get_children(), make_safe(), memory_managed(), ordered_begin(), and ordered_end().
|
mutableprivate |
Used to access our config (original or copy, as appropriate).
Definition at line 204 of file variable.hpp.
Referenced by attribute_range(), child(), count_children(), empty(), get_children(), get_config(), get_parsed_config(), has_attribute(), has_child(), make_safe(), null(), ordered_begin(), and ordered_end().
Definition at line 206 of file variable.hpp.
Referenced by null().
|
private |
Definition at line 205 of file variable.hpp.
Referenced by attribute_range(), child(), count_children(), expand(), vconfig::all_children_iterator::get_child(), get_children(), vconfig::all_children_iterator::get_key(), get_parsed_config(), has_child(), vconfig::all_children_iterator::operator++(), vconfig::attribute_iterator::operator->(), ordered_begin(), and ordered_end().