36 template<
typename V,
typename... T>
37 typename V::result_t
apply_visitor(
typename V::param_t state, T&&... args)
39 static_assert(std::is_base_of<
42 std::remove_reference_t<typename V::param_t>>,
43 V>::value,
"Invalid visitor type.");
46 V visitor(std::forward<T>(args)...);
50 return visitor.from_start(state);
52 return visitor.from_named(state);
54 return visitor.from_indexed(state);
56 return visitor.from_temporary(state);
59 throw std::range_error(
"Failed to convert the TVisitor::param_t type");
81 std::size_t previous_index = 0, name_size = name_.size();
83 for(std::size_t loop_index = 0; loop_index < name_size; loop_index++) {
84 switch(name_[loop_index]) {
93 apply_visitor<get_variable_key_visitor<V>>(
94 state_, name_.substr(previous_index, loop_index - previous_index));
96 previous_index = loop_index + 1;
100 apply_visitor<get_variable_index_visitor<V>>(state_,
parse_index(&name_[previous_index]));
105 if(loop_index < name_.length() && name_[loop_index] !=
'.') {
109 previous_index = loop_index + 1;
116 if(previous_index != name_.length() + 1) {
119 apply_visitor<get_variable_key_visitor<V>>(state_, name_.substr(previous_index));
134 return apply_visitor<as_scalar_visitor<V>>(state_);
141 return apply_visitor<as_container_visitor<V>>(state_);
148 return apply_visitor<as_array_visitor<V>>(state_);
162 return V::error_message(name_);
170 || ((state_.type_ ==
state_named) && state_.child_->has_attribute(state_.key_));
177 return apply_visitor<exists_as_container_visitor<V>>(state_);
183 this->throw_on_invalid();
184 return apply_visitor<clear_value_visitor<V>>(this->state_, only_tables);
194 template<
typename V,
typename T>
200 this->throw_on_invalid();
201 return apply_visitor<range_visitor_wrapper<V, append_range_h>>(this->state_, children);
207 this->throw_on_invalid();
208 return apply_visitor<range_visitor_wrapper<V, insert_range_h>>(this->state_, children);
214 this->throw_on_invalid();
215 return apply_visitor<range_visitor_wrapper<V, replace_range_h>>(this->state_, children);
221 this->throw_on_invalid();
222 apply_visitor<range_visitor_wrapper<V, merge_range_h>>(this->state_, children);
boost::iterator_range< child_iterator > child_itors
Additional functionality for a non-const variable_info.
config::child_itors insert_array(std::vector< config > children) const
void merge_array(std::vector< config > children) const
config::child_itors replace_array(std::vector< config > children) const
void clear(bool only_tables=false) const
Clears the value this object points to.
config::child_itors append_array(std::vector< config > children) const
Information on a WML variable.
maybe_const_t< config::child_itors, V > as_array() const
If instantiated with vi_policy_const, the lifetime of the returned const attribute_value reference mi...
maybe_const_t< config::attribute_value, V > & as_scalar() const
If instantiated with vi_policy_const, the lifetime of the returned const attribute_value reference mi...
std::string get_error_message() const
void throw_on_invalid() const
bool exists_as_container() const
variable_info(const std::string &varname, maybe_const_t< config, V > &vars) noexcept
maybe_const_t< config, V > & as_container() const
If instantiated with vi_policy_const, the lifetime of the returned const attribute_value reference mi...
bool explicit_index() const
bool exists_as_attribute() const
int parse_index(const char *index_str)
Parses a ']' terminated string.
V::result_t apply_visitor(typename V::param_t state, T &&... args)
Helper function to apply the result of a specified visitor to a variable_info object.
@ state_named
The result of .someval.
@ state_start
Represents the initial variable state before processing.
@ state_indexed
The result of .someval[index].
@ state_temporary
The result of .length.
typename variable_info_implementation::maybe_const< T, V >::type maybe_const_t
Helper template alias for maybe_const, defined at global scope for convenience.