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);
149 return do_from_config(*state.child_, 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>
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);
333 : only_tables_(only_tables)
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_);
396 : datasource_(source)
400 result_t
operator()(
config& child,
const std::string& key,
int startindex,
int endindex)
const 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) {
423 for(; index < datasource_.size(); ++
index) {
424 child.
child(key, startindex + index).
swap(datasource_[index]);
472 : datasource_(source)
static std::unique_ptr< class sdl_event_handler > handler_
result_t from_named(param_t state) const
result_t operator()(config &child, const std::string &key, int startindex, int endindex) const
std::vector< config > & datasource_
config & child(config_key_type key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
void from_indexed(param_t state) const
config::child_itors result_t
typename variable_info_implementation::maybe_const< T, V >::type maybe_const_t
Helper template alias for maybe_const, defined at global scope for convenience.
clear_value_visitor(bool only_tables)
void from_start(param_t state) const
Appends an [index] to the variable.
Variant for storing WML attributes.
typename as_container_visitor::result_t result_t
result_t from_named(param_t state) const
unsigned child_count(config_key_type key) const
Tries to convert to a [const] config&.
typename as_array_visitor::result_t result_t
get_variable_index_visitor(int n)
int parse_index(const char *index_str)
Parses a ']' terminated string.
result_t from_indexed(param_t state) const
typename get_variable_key_visitor::param_t param_t
static bool valid_attribute(config_key_type name)
result_t from_start(param_t state) const
The result of .someval[index].
replace_range_h(std::vector< config > &source)
get_variable_key_visitor(const std::string &key)
void from_named(typename get_variable_index_visitor::param_t state) const
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...
result_t from_indexed(param_t state) const
merge_range_h(std::vector< config > &source)
static config & get_child_at(config &cfg, const std::string &key, int index)
config::child_itors result_t
void merge_with(const config &c)
Merge config 'c' into this config, overwriting this config's values.
typename as_scalar_visitor::result_t result_t
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
const config non_empty_const_cfg("_")
EXIT_STATUS start(const std::string &filename, bool take_screenshot, const std::string &screenshot_filename)
Main interface for launching the editor from the title screen.
typename as_container_visitor::param_t param_t
config & add_child_at(config_key_type key, const config &val, unsigned index)
result_t from_indexed(param_t state) const
bool from_indexed(param_t state) const
as_range_visitor_base(T &&... args)
typename exists_as_container_visitor::param_t param_t
void resolve_negative_value(int size, int &val)
result_t operator()(config &child, const std::string &key, int, int) const
append_range_h(std::vector< config > &source)
typename as_range_visitor_base::param_t param_t
boost::iterator_range< const_child_iterator > const_child_itors
bool from_named(param_t state) const
typename clear_value_visitor::param_t param_t
result_t from_named(param_t state) const
std::vector< config > & datasource_
void do_from_config(maybe_const_t< config, V > &cfg, param_t state) const
bool from_start(param_t) const
insert_range_h(std::vector< config > &source)
result_t operator()(config &child, const std::string &key, int startindex, int) const
Replaces the child in [startindex, endindex) with 'source' 'insert' and 'append' are subcases of this...
std::size_t index(const std::string &str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
void from_named(param_t state) const
config & add_child(config_key_type key)
bool from_temporary(param_t) const
void operator()(config &child, const std::string &key, int startindex, int) const
config::child_itors result_t
auto get_child_range(TConfig &cfg, const std::string &key, int start, int count) -> decltype(cfg.child_range(key))
typename as_array_visitor::param_t param_t
boost::iterator_range< child_iterator > child_itors
This currently isn't implemented as a range-based operation because doing it on something like range ...
void from_indexed(param_t state) const
void from_named(param_t state) const
typename as_scalar_visitor::param_t param_t
A config object defines a single node in a WML file, with access to child nodes.
Tries to convert it to an (maybe const) attribute value.
result_t from_named(param_t state) const
static map_location::DIRECTION n
typename as_range_visitor_base::result_t result_t
#define DEFAULTHANDLER(name)
void remove_child(config_key_type key, unsigned index)
result_t from_temporary(param_t) const
Only implemented for read-only variable_info.