44 #include <string_view>
45 #include <type_traits>
49 #include <boost/range/iterator_range.hpp>
79 throw std::runtime_error(
"Optional reference has no value");
94 return opt_ !=
nullptr;
98 explicit operator bool()
const
151 mutable bool tested_;
183 template<
typename... T>
195 typedef std::map<std::string, child_list, std::less<>>
child_map;
247 typedef child_list::const_iterator
Itor;
338 typedef attribute_map::const_iterator
Itor;
362 typedef boost::iterator_range<attribute_iterator>
attr_itors;
574 template<
typename... T>
576 for(
const auto& key : {keys...}) {
587 template<
typename... T>
590 for(
const auto& key : {keys...}) {
591 auto* attr = from.
get(key);
593 (*this)[key] = *attr;
607 template<
typename... T>
610 for(
const auto& key : {keys...}) {
612 (*this)[key] = from[key];
627 const std::string &value);
630 const std::string &value)
const
634 const std::string &value);
637 const std::string &value)
const;
643 template<
typename... T>
645 for(
auto key : {keys...}) {
667 std::string
debug()
const;
668 std::string
hash()
const;
686 const child_map::key_type &
key;
691 struct const_all_children_iterator;
758 typedef std::vector<child_pos>::const_iterator
Itor;
941 template<
typename... T>
950 template<
typename K,
typename V,
typename... Rest>
953 template<
typename K2 = K,
typename V2 = V>
956 cfg.
insert(std::forward<K>(key), std::forward<V>(val));
958 unpack.visit(cfg, std::forward<Rest>(fwd)...);
962 template<
typename T,
typename... Rest>
965 template<
typename T2 = T,
typename C = config>
968 cfg.
add_child(std::forward<T>(tag), std::forward<config>(child));
970 unpack.visit(cfg, std::forward<Rest>(fwd)...);
974 template<
typename T,
typename... Rest>
977 template<
typename T2 = T>
980 cfg.
add_child(std::forward<T>(tag), std::forward<config>(child));
982 unpack.visit(cfg, std::forward<Rest>(fwd)...);
987 template<
typename... T>
991 unpack.visit(*
this, first, std::forward<T>(args)...);
Variant for storing WML attributes.
A config object defines a single node in a WML file, with access to child nodes.
void copy_or_remove_attributes(const config &from, T... keys)
Copies or deletes attributes to match the source config.
const attribute_value & get_old_attribute(config_key_type key, const std::string &old_key, const std::string &in_tag, const std::string &message="") const
Function to handle backward compatibility Get the value of key and if missing try old_key and log a d...
optional_config_impl< const config > find_child(config_key_type key, const std::string &name, const std::string &value) const
void append(const config &cfg)
Append data from another config object to this one.
const attribute_value & get_or(const config_key_type key, const config_key_type default_key) const
Chooses a value.
void remove_attributes(T... keys)
all_children_iterator erase(const all_children_iterator &i)
const_all_children_iterator ordered_begin() const
boost::iterator_range< const_all_children_iterator > const_all_children_itors
const config & child_or_empty(config_key_type key) const
Returns the first child with the given key, or an empty config if there is none.
std::size_t attribute_count() const
Count the number of non-blank attributes.
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 copy_attributes(const config &from, T... keys)
Copies attributes that exist in the source config.
attribute_value & operator[](config_key_type key)
Returns a reference to the attribute with the given key.
void recursive_clear_value(config_key_type key)
bool matches(const config &filter) const
attribute_value & operator[](const std::string &key)
Returns a reference to the attribute with the given key.
const attribute_value & operator[](const char *key) const
Returns a reference to the attribute with the given key or to a dummy empty attribute if it does not ...
void remove_child(config_key_type key, std::size_t index)
const_attr_itors attribute_range() const
config_attribute_value attribute_value
Variant for storing WML attributes.
std::size_t child_count(config_key_type key) const
attribute_map values_
All the attributes of this node.
bool validate_wml() const
Returns true if this object represents valid WML, i.e.
optional_config_impl< const config > get_deprecated_child(config_key_type old_key, const std::string &in_tag, DEP_LEVEL level, const std::string &message) const
Get a deprecated child and log a deprecation message.
void merge_attributes(const config &)
const_all_children_iterator ordered_end() const
void merge_children(const std::string &key)
All children with the given key will be merged into the first element with that key.
boost::iterator_range< child_iterator > child_itors
config & add_child_at(config_key_type key, const config &val, std::size_t index)
config & find_mandatory_child(config_key_type key, const std::string &name, const std::string &value)
void append_children_by_move(config &cfg, const std::string &key)
Moves children with the given name from the given config to this one.
const attribute_value & get_deprecated_attribute(config_key_type old_key, const std::string &in_tag, DEP_LEVEL level, const std::string &message) const
Get a deprecated attribute without a direct substitute, and log a deprecation message.
void merge_children_by_attribute(const std::string &key, const std::string &attribute)
All children with the given key and with equal values of the specified attribute will be merged into ...
attribute_value & operator[](const char *key)
Returns a reference to the attribute with the given key.
std::vector< std::unique_ptr< config > > child_list
optional_config_impl< config > find_child(config_key_type key, const std::string &name, const std::string &value)
Returns the first child of tag key with a name attribute containing value.
static bool valid_tag(config_key_type name)
boost::iterator_range< attribute_iterator > attr_itors
const_all_children_iterator ordered_cbegin() const
void clear_children(T... keys)
bool has_child(config_key_type key) const
Determine whether a config has a child or not.
bool has_attribute(config_key_type key) const
void merge_with(const config &c)
Merge config 'c' into this config, overwriting this config's values.
void clear_children_impl(config_key_type key)
std::map< std::string, child_list, std::less<> > child_map
const_child_itors get_deprecated_child_range(config_key_type old_key, const std::string &in_tag, DEP_LEVEL level, const std::string &message) const
Get a deprecated child rangw and log a deprecation message.
void clear_all_children()
void inherit_from(const config &c)
Merge config 'c' into this config, preserving this config's values.
const_all_children_itors all_children_range() const
In-order iteration over all children.
static const char * diff_track_attribute
The name of the attribute used for tracking diff changes.
boost::iterator_range< all_children_iterator > all_children_itors
child_itors child_range(config_key_type key)
void append_attributes(const config &cfg)
Adds attributes from cfg.
config & child_or_add(config_key_type key)
Returns a reference to the first child with the given key.
boost::iterator_range< const_attribute_iterator > const_attr_itors
void apply_diff(const config &diff, bool track=false)
A function to apply a diff config onto this config object.
std::size_t all_children_count() const
child_map children_
A list of all children of this node.
const_all_children_iterator ordered_cend() const
config & add_child_at_total(config_key_type key, const config &val, std::size_t pos)
void remove_attribute(config_key_type key)
static bool valid_attribute(config_key_type name)
config get_diff(const config &c) const
A function to get the differences between this object, and 'c', as another config object.
std::string debug() const
attribute_map::value_type attribute
void inherit_attributes(const config &c)
Merge the attributes of config 'c' into this config, preserving this config's values.
std::size_t find_total_first_of(config_key_type key, std::size_t start=0)
std::vector< child_pos > ordered_children
void remove_children(config_key_type key, std::function< bool(const config &)> p=[](config){return true;})
Removes all children with tag key for which p returns true.
void clear_diff_track(const config &diff)
Clear any tracking info from a previous apply_diff call with tracking.
std::map< std::string, attribute_value, std::less<> > attribute_map
boost::iterator_range< const_child_iterator > const_child_itors
void append_children(const config &cfg)
Adds children from cfg.
const attribute_value & operator[](const std::string &key) const
Returns a reference to the attribute with the given key or to a dummy empty attribute if it does not ...
void insert(config_key_type key, T &&value)
Inserts an attribute into the config.
void splice_children(config &src, const std::string &key)
Moves all the children with tag key from src to this.
const attribute_value * get(config_key_type key) const
Returns a pointer to the attribute with the given key or nullptr if it does not exist.
friend bool operator==(const config &a, const config &b)
optional_config_impl< config > optional_child(config_key_type key, int n=0)
Euivalent to mandatory_child, but returns an empty optional if the nth child was not found.
config & operator=(const config &)
config & add_child(config_key_type key)
optional_config_impl()=default
utils::const_clone_t< config_attribute_value, T > & operator[](config_key_type key)
optional_config_impl(std::nullopt_t)
optional_config_impl< T > & operator=(T &new_ref)
T * ptr() const
Returns a pointer to the referenced object or nullptr if no reference is held.
optional_config_impl(T &ref)
A simple wrapper class for optional reference types.
std::string_view config_key_type
bool operator!=(const config &a, const config &b)
std::ostream & operator<<(std::ostream &, const config &)
void swap(config &lhs, config &rhs)
Implement non-member swap function for std::swap (calls config::swap).
bool operator==(const config &, const config &)
Definitions for the interface to Wesnoth Markup Language (WML).
DEP_LEVEL
See https://wiki.wesnoth.org/CompatibilityStandards for more info.
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.
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.
typename const_clone< D, S >::type const_clone_t
std::string::const_iterator iterator
const any_child * operator->() const
arrow_helper(const all_children_iterator &i)
friend difference_type operator-(const this_type &a, const this_type &b)
all_children_iterator this_type
pointer operator->() const
std::vector< child_pos >::iterator Itor
all_children_iterator & operator++()
reference operator[](difference_type n) const
reference operator*() const
bool operator==(const all_children_iterator &i) const
friend this_type operator-(const this_type &a, difference_type n)
this_type operator--(int)
this_type & operator-=(difference_type n)
bool operator==(const const_all_children_iterator &i) const
std::random_access_iterator_tag iterator_category
friend bool operator>=(const this_type &a, const this_type &b)
friend bool operator>(const this_type &a, const this_type &b)
friend this_type operator+(const this_type &a, difference_type n)
this_type & operator+=(difference_type n)
friend bool operator<=(const this_type &a, const this_type &b)
friend bool operator<(const this_type &a, const this_type &b)
bool operator!=(const all_children_iterator &i) const
all_children_iterator(const Itor &i)
bool operator!=(const const_all_children_iterator &i) const
all_children_iterator operator++(int)
friend this_type operator+(difference_type n, const this_type &a)
Itor::difference_type difference_type
any_child(const child_map::key_type *k, config *c)
const child_map::key_type & key
attribute_iterator & operator--()
bool operator!=(const attribute_iterator &i) const
attribute_iterator operator--(int)
std::bidirectional_iterator_tag iterator_category
bool operator==(const attribute_iterator &i) const
bool operator!=(const const_attribute_iterator &i) const
reference operator*() const
Itor::difference_type difference_type
pointer operator->() const
bool operator==(const const_attribute_iterator &i) const
attribute_map::iterator Itor
attribute_iterator operator++(int)
attribute_iterator(const Itor &i)
attribute_iterator & operator++()
friend Itor::difference_type operator-(const this_type &a, const this_type &b)
std::random_access_iterator_tag iterator_category
friend this_type operator-(const this_type &a, Itor::difference_type n)
child_iterator & operator++()
bool operator==(const const_child_iterator &i) const
Itor::difference_type difference_type
bool operator==(const child_iterator &i) const
this_type & operator-=(Itor::difference_type n)
child_list::iterator Itor
child_iterator(const Itor &i)
reference operator*() const
bool operator!=(const const_child_iterator &i) const
pointer operator->() const
child_iterator operator--(int)
config & operator[](Itor::difference_type n) const
friend this_type operator+(Itor::difference_type n, const this_type &a)
friend this_type operator+(const this_type &a, Itor::difference_type n)
child_iterator operator++(int)
friend bool operator>=(const this_type &a, const this_type &b)
friend bool operator>(const this_type &a, const this_type &b)
this_type & operator+=(Itor::difference_type n)
bool operator!=(const child_iterator &i) const
friend bool operator<=(const this_type &a, const this_type &b)
friend bool operator<(const this_type &a, const this_type &b)
child_iterator & operator--()
bool operator==(const child_pos &o) const
bool operator!=(const child_pos &o) const
child_pos(child_map::iterator p, std::size_t i)
const any_child * operator->() const
arrow_helper(const const_all_children_iterator &i)
const any_child reference
const_all_children_iterator this_type
friend difference_type operator-(const this_type &a, const this_type &b)
const_all_children_iterator(const all_children_iterator &i)
const any_child value_type
reference operator*() const
const_all_children_iterator(const Itor &i)
const_all_children_iterator operator++(int)
this_type operator--(int)
Itor::difference_type difference_type
reference operator[](difference_type n) const
std::vector< child_pos >::const_iterator Itor
bool operator==(const const_all_children_iterator &i) const
friend this_type operator-(const this_type &a, difference_type n)
std::random_access_iterator_tag iterator_category
bool operator!=(const const_all_children_iterator &i) const
this_type & operator+=(difference_type n)
bool operator!=(const all_children_iterator &i) const
bool operator==(const all_children_iterator &i) const
friend bool operator>=(const this_type &a, const this_type &b)
friend bool operator>(const this_type &a, const this_type &b)
pointer operator->() const
friend this_type operator+(const this_type &a, difference_type n)
friend bool operator<=(const this_type &a, const this_type &b)
friend bool operator<(const this_type &a, const this_type &b)
const arrow_helper pointer
const_all_children_iterator & operator++()
friend this_type operator+(difference_type n, const this_type &a)
this_type & operator-=(difference_type n)
const attribute value_type
bool operator==(const attribute_iterator &i) const
pointer operator->() const
const_attribute_iterator & operator++()
const_attribute_iterator operator--(int)
const_attribute_iterator operator++(int)
Itor::difference_type difference_type
const_attribute_iterator & operator--()
const attribute & reference
const_attribute_iterator(const Itor &i)
const_attribute_iterator(attribute_iterator &i)
const attribute * pointer
reference operator*() const
attribute_map::const_iterator Itor
std::bidirectional_iterator_tag iterator_category
bool operator!=(const attribute_iterator &i) const
bool operator!=(const const_attribute_iterator &i) const
bool operator==(const const_attribute_iterator &i) const
this_type & operator-=(Itor::difference_type n)
friend Itor::difference_type operator-(const this_type &a, const this_type &b)
const_child_iterator(const Itor &i)
friend this_type operator-(const this_type &a, Itor::difference_type n)
bool operator==(const const_child_iterator &i) const
std::random_access_iterator_tag iterator_category
pointer operator->() const
const_child_iterator operator++(int)
const_child_iterator this_type
bool operator==(const child_iterator &i) const
const_child_iterator operator--(int)
const config & operator[](Itor::difference_type n) const
Itor::difference_type difference_type
const_child_iterator(const child_iterator &i)
const_child_iterator & operator++()
const_child_iterator & operator--()
friend this_type operator+(Itor::difference_type n, const this_type &a)
friend this_type operator+(const this_type &a, Itor::difference_type n)
bool operator!=(const child_iterator &i) const
friend bool operator>=(const this_type &a, const this_type &b)
friend bool operator>(const this_type &a, const this_type &b)
reference operator*() const
bool operator!=(const const_child_iterator &i) const
friend bool operator<=(const this_type &a, const this_type &b)
this_type & operator+=(Itor::difference_type n)
friend bool operator<(const this_type &a, const this_type &b)
child_list::const_iterator Itor
error(const std::string &message)
void visit(config &cfg, K2 &&key, V2 &&val, Rest... fwd)
void visit(config &cfg, T2 &&tag, C &&child, Rest... fwd)
void visit(config &cfg, T2 &&tag, config &child, Rest... fwd)
Base class for all the errors encountered by the engine.
static map_location::DIRECTION n