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< vconfig > | child_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 config & | get_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 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... | |
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 36 of file variable.hpp.
typedef std::vector<vconfig> vconfig::child_list |
Definition at line 71 of file variable.hpp.
|
private |
Definition at line 63 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().
|
private |
Definition at line 68 of file variable.cpp.
|
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.
[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. 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().
|
inline |
Definition at line 146 of file variable.hpp.
References ordered_begin(), and ordered_end().
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 243 of file variable.cpp.
References cache_, cfg_, config::child(), config::child_range(), empty_vconfig(), unconstructed_vconfig(), and vconfig().
Referenced by count_children(), get_children(), terrain_filter::get_locations(), get_parsed_config(), game_lua_kernel::get_sides_vector(), basic_unit_filter_impl::internal_matches_filter(), game_lua_kernel::intf_heal_unit(), game_lua_kernel::intf_kill(), terrain_filter::match(), side_filter::match_internal(), terrain_filter::match_internal(), storyscreen::controller::resolve_wml(), storyscreen::part::resolve_wml(), unit::unit(), game_events::wml_menu_item::update(), unit_display::wml_animation_internal(), and game_events::WML_HANDLER_FUNCTION().
size_t vconfig::count_children | ( | const std::string & | key | ) | const |
Definition at line 211 of file variable.cpp.
References config::all_children_range(), cfg_, and child().
Referenced by basic_unit_filter_impl::internal_matches_filter().
|
inline |
Definition at line 93 of file variable.hpp.
References cfg_, config::empty(), and null().
Referenced by game_events::wml_menu_item::can_show(), construct(), basic_unit_filter_impl::internal_matches_filter(), game_events::entity_location::matches_unit_filter(), storyscreen::controller::resolve_wml(), game_events::wml_menu_item::to_config(), unit_display::wml_animation_internal(), and game_events::WML_HANDLER_FUNCTION().
|
static |
Definition at line 97 of file variable.cpp.
References vconfig().
Referenced by child(), events::console_handler::do_inspect(), vconfig::all_children_iterator::get_child(), and get_children().
config::attribute_value vconfig::expand | ( | const std::string & | key | ) | const |
Definition at line 303 of file variable.cpp.
References config::attribute_value::apply_visitor(), and resources::gamedata.
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 181 of file variable.cpp.
References config::all_children_range(), cache_, cfg_, child(), empty_vconfig(), and vconfig().
Referenced by terrain_filter::get_locations(), basic_unit_filter_impl::internal_matches_filter(), game_lua_kernel::intf_replace_schedule(), terrain_filter::match_internal(), storyscreen::controller::resolve_wml(), storyscreen::part::resolve_wml(), unit::unit(), and unit_display::wml_animation_internal().
|
inline |
Definition at line 68 of file variable.hpp.
References cfg_.
Referenced by construct(), get_parsed_config(), lua_common::impl_vconfig_get(), lua_common::impl_vconfig_pairs(), game_lua_kernel::intf_add_event(), game_lua_kernel::intf_label(), game_events::wml_menu_item::to_config(), terrain_filter::to_config(), basic_unit_filter_impl::to_config(), unit::unit(), and unit_display::wml_animation_internal().
config vconfig::get_parsed_config | ( | ) | const |
Definition at line 131 of file variable.cpp.
References config::add_child(), config::all_children_range(), config::attribute_range(), cfg_, child(), lg::err(), expand(), get_config(), get_parsed_config(), i, game::error::message, vconfig(), and WRN_NG.
Referenced by get_parsed_config(), lua_common::impl_vconfig_get(), basic_unit_filter_impl::internal_matches_filter(), game_lua_kernel::intf_add_event(), game_lua_kernel::intf_add_time_area(), game_lua_kernel::intf_modify_ai_wml(), game_lua_kernel::intf_modify_side(), game_lua_kernel::intf_replace_schedule(), luaW_tofaivariant(), game_events::matches_special_filter(), storyscreen::part::resolve_wml(), and unit_display::wml_animation_internal().
|
inline |
< Synonym for operator[]
Definition at line 92 of file variable.hpp.
References cfg_, and config::has_attribute().
Referenced by construct(), terrain_filterimpl::filter_area(), terrain_filterimpl::filter_special_loc(), terrain_filterimpl::filter_xy(), terrain_filter::get_locations(), lua_common::impl_vconfig_get(), game_lua_kernel::intf_print(), side_filter::match_internal(), terrain_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 270 of file variable.cpp.
References cfg_, config::child(), and config::child_range().
Referenced by terrain_filter::get_locations(), basic_unit_filter_impl::internal_matches_filter(), game_lua_kernel::intf_kill(), game_lua_kernel::intf_scroll(), terrain_filter::match(), side_filter::match_internal(), terrain_filter::match_internal(), storyscreen::controller::resolve_wml(), and storyscreen::part::resolve_wml().
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().
|
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().
|
inline |
Definition at line 66 of file variable.hpp.
References cfg_, and default_empty_config.
Referenced by empty(), game_lua_kernel::get_sides_vector(), lua_common::impl_vconfig_get(), lua_common::impl_vconfig_size(), game_lua_kernel::intf_find_cost_map(), game_lua_kernel::intf_get_recall_units(), game_lua_kernel::intf_get_sides(), game_lua_kernel::intf_heal_unit(), game_lua_kernel::intf_match_location(), game_lua_kernel::intf_match_side(), game_lua_kernel::intf_match_unit(), luaW_checkvconfig(), side_filter::match_internal(), terrain_filter::match_internal(), operator bool(), storyscreen::part::resolve_wml(), unit::unit(), and unit_display::wml_animation_internal().
|
inlineexplicit |
A vconfig evaluates to true iff it can be dereferenced.
Definition at line 64 of file variable.hpp.
References null().
|
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 |
In-order iteration over all children.
Definition at line 398 of file variable.cpp.
References cache_, cfg_, and config::ordered_begin().
Referenced by all_ordered(), basic_unit_filter_impl::basic_unit_filter_impl(), game_events::conditional_passed(), terrain_filter::get_locations(), lua_common::impl_vconfig_get(), lua_common::impl_vconfig_ipairs(), lua_common::impl_vconfig_size(), side_filter::match(), terrain_filter::match(), storyscreen::controller::resolve_wml(), and storyscreen::part::resolve_wml().
vconfig::all_children_iterator vconfig::ordered_end | ( | ) | const |
Definition at line 403 of file variable.cpp.
References cache_, cfg_, and config::ordered_end().
Referenced by all_ordered(), basic_unit_filter_impl::basic_unit_filter_impl(), game_events::conditional_passed(), terrain_filter::get_locations(), lua_common::impl_vconfig_get(), lua_common::impl_vconfig_ipairs(), lua_common::impl_vconfig_size(), side_filter::match(), terrain_filter::match(), storyscreen::controller::resolve_wml(), and storyscreen::part::resolve_wml().
|
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().
|
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().
|
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().
Definition at line 159 of file variable.hpp.
Referenced by null().