30 template<
typename TConfig>
31 auto get_child_range(TConfig& cfg,
const std::string& key,
int start,
int count) -> decltype(cfg.child_range(key))
33 auto res = cfg.child_range(key);
34 return {res.begin() +
start, res.begin() +
start + count};
60 int res = strtol(index_str, &endptr, 10);
86 template<
typename R,
typename P>
93 #define DEFAULTHANDLER(name) \
94 result_t name(param_t) const \
96 throw invalid_variablename_exception(); \
111 #undef DEFAULTHANDLER
114 template<
typename V,
typename TResult>
117 template<
typename V,
typename TResult>
138 if(
key_ ==
"length") {
139 state.temp_val_ = state.child_->child_count(state.key_);
144 return do_from_config(V::get_child_at(*state.child_, state.key_, 0), state);
155 return do_from_config(V::get_child_at(*state.child_, state.key_, state.index_), state);
204 return (*state.child_)[state.key_];
224 return state.temp_val_;
241 return V::get_child_at(*state.child_, state.key_, 0);
246 return *state.child_;
251 return V::get_child_at(*state.child_, state.key_, state.index_);
269 return get_child_range(*state.child_, state.key_, 0, state.child_->child_count(state.key_));
275 V::get_child_at(*state.child_, state.key_, state.index_);
283 if(
static_cast<int>(state.child_->child_count(state.key_)) <= state.index_) {
298 template<
typename V,
typename THandler,
typename... T>
307 :
handler_(std::forward<T>(args)...)
313 return handler_(*state.child_, state.key_, 0, state.child_->child_count(state.key_));
318 return handler_(*state.child_, state.key_, state.index_, state.index_ + 1);
340 state.child_->remove_attribute(state.key_);
343 state.child_->clear_children(state.key_);
348 state.child_->remove_child(state.key_, state.index_);
364 return state.child_->has_child(state.key_);
369 return state.child_->child_count(state.key_) >
static_cast<std::size_t
>(state.index_);
402 assert(endindex - startindex >= 0);
410 int size_diff =
datasource_.size() - (endindex - startindex);
413 while(size_diff < 0) {
418 std::size_t
index = 0;
419 for(
index = 0; index < static_cast<std::size_t>(size_diff); ++
index) {
Variant for storing WML attributes.
A config object defines a single node in a WML file, with access to child nodes.
config & mandatory_child(config_key_type key, int n=0)
Returns the nth child with the given key, or throws an error if there is none.
void remove_child(config_key_type key, std::size_t index)
std::size_t child_count(config_key_type key) const
boost::iterator_range< child_iterator > child_itors
config & add_child_at(config_key_type key, const config &val, std::size_t index)
void merge_with(const config &c)
Merge config 'c' into this config, overwriting this config's values.
static bool valid_attribute(config_key_type name)
boost::iterator_range< const_child_iterator > const_child_itors
config & add_child(config_key_type key)
config::child_itors result_t
result_t operator()(config &child, const std::string &key, int, int) const
append_range_h(std::vector< config > &source)
This currently isn't implemented as a range-based operation because doing it on something like range ...
result_t from_indexed(param_t state) const
result_t from_named(param_t state) const
typename as_array_visitor::result_t result_t
typename as_array_visitor::param_t param_t
Tries to convert to a [const] config&.
result_t from_named(param_t state) const
typename as_container_visitor::result_t result_t
typename as_container_visitor::param_t param_t
result_t from_indexed(param_t state) const
result_t from_start(param_t state) const
typename as_range_visitor_base::param_t param_t
typename as_range_visitor_base::result_t result_t
result_t from_indexed(param_t state) const
as_range_visitor_base(T &&... args)
result_t from_named(param_t state) const
Tries to convert it to an (maybe const) attribute value.
result_t from_temporary(param_t) const
Only implemented for read-only variable_info.
result_t from_named(param_t state) const
typename as_scalar_visitor::result_t result_t
typename as_scalar_visitor::param_t param_t
clear_value_visitor(bool only_tables)
void from_named(param_t state) const
typename clear_value_visitor::param_t param_t
void from_indexed(param_t state) const
bool from_indexed(param_t state) const
bool from_start(param_t) const
bool from_temporary(param_t) const
typename exists_as_container_visitor::param_t param_t
bool from_named(param_t state) const
Appends an [index] to the variable.
get_variable_index_visitor(int n)
void from_named(typename get_variable_index_visitor::param_t state) const
void from_start(param_t state) const
void from_named(param_t state) const
void do_from_config(maybe_const_t< config, V > &cfg, param_t state) const
get_variable_key_visitor(const std::string &key)
void from_indexed(param_t state) const
typename get_variable_key_visitor::param_t param_t
insert_range_h(std::vector< config > &source)
config::child_itors result_t
result_t operator()(config &child, const std::string &key, int startindex, int) const
void operator()(config &child, const std::string &key, int startindex, int) const
merge_range_h(std::vector< config > &source)
std::vector< config > & datasource_
Replaces the child in [startindex, endindex) with 'source' 'insert' and 'append' are subcases of this...
replace_range_h(std::vector< config > &source)
std::vector< config > & datasource_
result_t operator()(config &child, const std::string &key, int startindex, int endindex) const
config::child_itors result_t
static config & get_child_at(config &cfg, const std::string &key, int index)
void swap(config &lhs, config &rhs)
Implement non-member swap function for std::swap (calls config::swap).
EXIT_STATUS start(bool clear_id, const std::string &filename, bool take_screenshot, const std::string &screenshot_filename)
Main interface for launching the editor from the title screen.
const std::size_t max_loop
The maximum number of hexes on a map and items in an array and also used as maximum in wml loops.
std::size_t size(std::string_view str)
Length in characters of a UTF-8 string.
std::size_t index(std::string_view str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
const config non_empty_const_cfg("_")
int parse_index(const char *index_str)
Parses a ']' terminated string.
@ state_named
The result of .someval.
@ state_indexed
The result of .someval[index].
@ state_temporary
The result of .length.
void resolve_negative_value(int size, int &val)
auto get_child_range(TConfig &cfg, const std::string &key, int start, int count) -> decltype(cfg.child_range(key))
static map_location::direction n
typename variable_info_implementation::maybe_const< T, V >::type maybe_const_t
Helper template alias for maybe_const, defined at global scope for convenience.
#define DEFAULTHANDLER(name)