43 #include <string_view> 44 #include <type_traits> 48 #include <boost/range/iterator_range.hpp> 55 bool operator==(const config &, const config &);
56 inline bool operator!=(const config &a, const config &b) {
return !
operator==(
a,
b); }
70 void check_valid()
const;
75 void check_valid(
const config &cfg)
const;
97 template<
typename... T>
108 explicit operator bool()
const 109 {
return this != &invalid; }
115 typedef std::map<std::string, child_list, std::less<>>
child_map;
143 friend bool operator<(
const this_type& a,
const this_type& b) {
return a.
i_ < b.
i_; }
144 friend bool operator<=(
const this_type& a,
const this_type& b) {
return a.
i_ <= b.
i_; }
145 friend bool operator>=(
const this_type& a,
const this_type& b) {
return a.
i_ >= b.
i_; }
146 friend bool operator>(
const this_type& a,
const this_type& b) {
return a.
i_ > b.
i_; }
148 this_type&
operator+=(Itor::difference_type
n) { i_ +=
n;
return *
this; }
149 this_type&
operator-=(Itor::difference_type
n) { i_ -=
n;
return *
this; }
152 friend Itor::difference_type
operator-(
const this_type& a,
const this_type& b) {
return a.
i_ - b.
i_; }
153 friend this_type
operator-(
const this_type& a, Itor::difference_type
n) {
return this_type(a.
i_ - n); }
154 friend this_type
operator+(
const this_type& a, Itor::difference_type
n) {
return this_type(a.
i_ + n); }
155 friend this_type
operator+(Itor::difference_type
n,
const this_type& a) {
return this_type(a.
i_ + n); }
168 typedef child_list::const_iterator
Itor;
186 friend bool operator<(
const this_type& a,
const this_type& b) {
return a.
i_ < b.
i_; }
187 friend bool operator<=(
const this_type& a,
const this_type& b) {
return a.
i_ <= b.
i_; }
188 friend bool operator>=(
const this_type& a,
const this_type& b) {
return a.
i_ >= b.
i_; }
189 friend bool operator>(
const this_type& a,
const this_type& b) {
return a.
i_ > b.
i_; }
191 this_type&
operator+=(Itor::difference_type
n) { i_ +=
n;
return *
this; }
192 this_type&
operator-=(Itor::difference_type
n) { i_ -=
n;
return *
this; }
195 friend Itor::difference_type
operator-(
const this_type& a,
const this_type& b) {
return a.
i_ - b.
i_; }
196 friend this_type
operator-(
const this_type& a, Itor::difference_type
n) {
return this_type(a.
i_ - n); }
197 friend this_type
operator+(
const this_type& a, Itor::difference_type
n) {
return this_type(a.
i_ + n); }
198 friend this_type
operator+(Itor::difference_type
n,
const this_type& a) {
return this_type(a.
i_ + n); }
259 typedef attribute_map::const_iterator
Itor;
282 typedef boost::iterator_range<attribute_iterator>
attr_itors;
287 unsigned all_children_count()
const;
289 unsigned attribute_count()
const;
330 return instances > 0;
334 static inline unsigned instances = 0;
448 const attribute_value&
operator[](
const std::string& key)
const 487 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;
520 template<
typename... T>
522 for(
const auto& key : {keys...}) {
533 template<
typename... T>
536 for(
const auto& key : {keys...}) {
537 auto* attr = from.
get(key);
539 (*this)[key] = *attr;
553 template<
typename... T>
556 for(
const auto& key : {keys...}) {
558 (*this)[key] = from[key];
573 const std::string &value);
576 const std::string &value)
const 582 template<
typename... T>
584 for(
auto key : {keys...}) {
606 std::string
debug()
const;
607 std::string
hash()
const;
625 const child_map::key_type &
key;
655 reference operator*()
const;
663 friend bool operator<(
const this_type& a,
const this_type& b) {
return a.
i_ < b.
i_; }
664 friend bool operator<=(
const this_type& a,
const this_type& b) {
return a.
i_ <= b.
i_; }
665 friend bool operator>=(
const this_type& a,
const this_type& b) {
return a.
i_ >= b.
i_; }
666 friend bool operator>(
const this_type& a,
const this_type& b) {
return a.
i_ > b.
i_; }
671 reference
operator[](difference_type
n)
const {
return any_child(&i_[n].pos->first, i_[n].pos->second[i_->index].get()); }
672 friend difference_type
operator-(
const this_type& a,
const this_type& b) {
return a.
i_ - b.
i_; }
673 friend this_type
operator-(
const this_type& a, difference_type
n) {
return this_type(a.
i_ - n); }
674 friend this_type
operator+(
const this_type& a, difference_type
n) {
return this_type(a.
i_ + n); }
675 friend this_type
operator+(difference_type
n,
const this_type& a) {
return this_type(a.
i_ + n); }
698 typedef std::vector<child_pos>::const_iterator
Itor;
708 reference operator*()
const;
716 friend bool operator<(
const this_type& a,
const this_type& b) {
return a.
i_ < b.
i_; }
717 friend bool operator<=(
const this_type& a,
const this_type& b) {
return a.
i_ <= b.
i_; }
718 friend bool operator>=(
const this_type& a,
const this_type& b) {
return a.
i_ >= b.
i_; }
719 friend bool operator>(
const this_type& a,
const this_type& b) {
return a.
i_ > b.
i_; }
724 reference
operator[](difference_type
n)
const {
return any_child(&i_[n].pos->first, i_[n].pos->second[i_->index].get()); }
725 friend difference_type
operator-(
const this_type& a,
const this_type& b) {
return a.
i_ - b.
i_; }
726 friend this_type
operator-(
const this_type& a, difference_type
n) {
return this_type(a.
i_ - n); }
727 friend this_type
operator+(
const this_type& a, difference_type
n) {
return this_type(a.
i_ + n); }
728 friend this_type
operator+(difference_type
n,
const this_type& a) {
return this_type(a.
i_ + n); }
877 template<
typename... T>
886 template<
typename K,
typename V,
typename... Rest>
889 template<
typename K2 = K,
typename V2 = V>
892 cfg.
insert(std::forward<K>(key), std::forward<V>(val));
894 unpack.visit(cfg, std::forward<Rest>(fwd)...);
898 template<
typename T,
typename... Rest>
901 template<
typename T2 = T,
typename C = config>
904 cfg.
add_child(std::forward<T>(tag), std::forward<config>(child));
906 unpack.visit(cfg, std::forward<Rest>(fwd)...);
910 template<
typename T,
typename... Rest>
913 template<
typename T2 = T>
916 cfg.
add_child(std::forward<T>(tag), std::forward<config>(child));
918 unpack.visit(cfg, std::forward<Rest>(fwd)...);
923 template<
typename... T>
927 unpack.visit(*
this, first, std::forward<T>(args)...);
friend this_type operator+(const this_type &a, Itor::difference_type n)
void copy_or_remove_attributes(const config &from, T... keys)
Copies or deletes attributes to match the source config.
reference operator*() const
std::bidirectional_iterator_tag iterator_category
std::vector< child_pos >::iterator Itor
friend this_type operator-(const this_type &a, Itor::difference_type n)
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...
const_child_iterator & operator--()
bool matches(const config &filter) const
An object of this type will cause the following functions to throw a config::error instead of returni...
error(const std::string &message)
const_all_children_iterator operator++(int)
friend bool operator>=(const this_type &a, const this_type &b)
attribute_iterator & operator++()
const_all_children_iterator ordered_cbegin() const
const_all_children_itors all_children_range() const
In-order iteration over all children.
bool operator==(const const_child_iterator &i) const
const any_child * operator->() const
bool operator==(const all_children_iterator &i) const
void append_attributes(const config &cfg)
Adds attributes from cfg.
void visit(config &cfg, T2 &&tag, C &&child, Rest... fwd)
friend bool operator<=(const this_type &a, const this_type &b)
reference operator*() const
friend bool operator>(const this_type &a, const this_type &b)
void clear_children(T... keys)
void recursive_clear_value(config_key_type key)
bool operator==(const config &, const config &)
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 ...
const_child_iterator(const Itor &i)
void append(const config &cfg)
Append data from another config object to this one.
friend Itor::difference_type operator-(const this_type &a, const this_type &b)
void append_children_by_move(config &cfg, const std::string &key)
Moves children with the given name from the given config to this one.
boost::iterator_range< const_all_children_iterator > const_all_children_itors
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.
const_attribute_iterator operator--(int)
Variant for storing WML attributes.
attribute_iterator & operator--()
friend this_type operator+(difference_type n, const this_type &a)
bool operator!=(const attribute_iterator &i) const
friend this_type operator-(const this_type &a, difference_type n)
std::map< std::string, child_list, std::less<> > child_map
void merge_children(const std::string &key)
All children with the given key will be merged into the first element with that key.
bool has_attribute(config_key_type key) const
friend bool operator>(const this_type &a, const this_type &b)
bool operator!=(const child_iterator &i) const
attribute_iterator operator++(int)
friend bool operator<=(const this_type &a, const this_type &b)
attribute_value & operator[](const std::string &key)
Returns a reference to the attribute with the given key.
~throw_when_child_not_found()
config & add_child_at_total(config_key_type key, const config &val, size_t pos)
friend bool operator==(const config &a, const config &b)
void remove_attributes(T... keys)
reference operator[](difference_type n) const
friend this_type operator+(const this_type &a, Itor::difference_type n)
attribute_map::value_type attribute
config & operator[](Itor::difference_type n) const
child_iterator(const Itor &i)
void clear(const std::string &key)
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.
this_type operator--(int)
const_child_iterator operator++(int)
std::random_access_iterator_tag iterator_category
child_list::iterator Itor
friend bool operator>(const this_type &a, const this_type &b)
size_t find_total_first_of(config_key_type key, size_t start=0)
const_all_children_iterator this_type
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...
void insert(config_key_type key, T &&value)
Inserts an attribute into the config.
friend this_type operator+(Itor::difference_type n, const this_type &a)
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 ...
config & child_or_add(config_key_type key)
Returns a reference to the first child with the given key.
DEP_LEVEL
See https://wiki.wesnoth.org/CompatibilityStandards for more info.
attribute_map::const_iterator Itor
void append_children(const config &cfg)
Adds children from cfg.
bool operator==(const const_all_children_iterator &i) const
void clear_diff_track(const config &diff)
Clear any tracking info from a previous apply_diff call with tracking.
friend this_type operator-(const this_type &a, difference_type n)
void remove_attribute(config_key_type key)
this_type operator--(int)
pointer operator->() const
bool operator==(const child_iterator &i) const
const_attribute_iterator & operator++()
const_attr_itors attribute_range() const
void visit(config &cfg, T2 &&tag, config &child, Rest... fwd)
bool operator!=(const attribute_iterator &i) const
std::string_view config_key_type
const_attribute_iterator(const Itor &i)
bool operator!=(const const_attribute_iterator &i) const
this_type & operator-=(difference_type n)
config get_diff(const config &c) const
A function to get the differences between this object, and 'c', as another config object...
friend bool operator>=(const this_type &a, const this_type &b)
void merge_with(const config &c)
Merge config 'c' into this config, overwriting this config's values.
void inherit_from(const config &c)
Merge config 'c' into this config, preserving this config's values.
child_list::const_iterator Itor
this_type & operator-=(Itor::difference_type n)
bool operator!=(const const_child_iterator &i) const
const_all_children_iterator ordered_end() const
Definitions for the interface to Wesnoth Markup Language (WML).
std::random_access_iterator_tag iterator_category
all_children_iterator(const Itor &i)
const_child_iterator(const child_iterator &i)
child_iterator & operator++()
bool operator==(const child_iterator &i) const
friend this_type operator+(difference_type n, const this_type &a)
pointer operator->() const
void splice_children(config &src, const std::string &key)
Moves all the children with tag key from src to this.
const_attribute_iterator(attribute_iterator &i)
this_type & operator+=(Itor::difference_type n)
void clear_children_impl(config_key_type key)
bool operator==(const attribute_iterator &i) const
pointer operator->() const
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.
arrow_helper(const const_all_children_iterator &i)
bool operator==(const const_all_children_iterator &i) const
friend bool operator<=(const this_type &a, const this_type &b)
std::bidirectional_iterator_tag iterator_category
bool operator!=(const const_all_children_iterator &i) const
child_iterator & operator--()
const_child_iterator this_type
bool operator==(const const_attribute_iterator &i) const
config & add_child_at(config_key_type key, const config &val, unsigned index)
pointer operator->() const
const child_map::key_type & key
const any_child value_type
bool validate_wml() const
Returns true if this object represents valid WML, i.e.
bool operator!=(const child_iterator &i) const
reference operator[](difference_type n) const
this_type & operator-=(Itor::difference_type n)
const_child_iterator & operator++()
void erase(const std::string &key)
bool operator==(const attribute_iterator &i) const
friend bool operator<(const this_type &a, const this_type &b)
bool operator!=(const const_child_iterator &i) const
std::vector< child_pos > ordered_children
void visit(config &cfg, K2 &&key, V2 &&val, Rest... fwd)
bool operator==(const all_children_iterator &i) const
this_type & operator+=(difference_type n)
bool operator==(const child_pos &o) const
friend Itor::difference_type operator-(const this_type &a, const this_type &b)
const any_child * operator->() const
utils::optional_reference< config > optional_child(config_key_type key, int n=0)
Euivalent to child, but returns an empty optional if the nth child was not found. ...
boost::iterator_range< const_attribute_iterator > const_attr_itors
const_attribute_iterator operator++(int)
void apply_diff(const config &diff, bool track=false)
A function to apply a diff config onto this config object.
pointer operator->() const
std::map< std::string, attribute_value, std::less<> > attribute_map
const arrow_helper pointer
bool operator!=(const all_children_iterator &i) const
all_children_iterator operator++(int)
attribute_value & operator[](const char *key)
Returns a reference to the attribute with the given key.
void inherit_attributes(const config &c)
Merge the attributes of config 'c' into this config, preserving this config's values.
boost::iterator_range< const_child_iterator > const_child_itors
friend this_type operator+(const this_type &a, difference_type n)
const_all_children_iterator & operator++()
attribute_value & operator[](config_key_type key)
Returns a reference to the attribute with the given key.
const config & find_child(config_key_type key, const std::string &name, const std::string &value) const
static config & get_invalid()
bool operator!=(const child_pos &o) const
this_type & operator-=(difference_type n)
reference operator*() const
this_type & operator+=(Itor::difference_type n)
attribute_map values_
All the attributes of this node.
utils::optional_reference< 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.
child_iterator operator--(int)
bool operator==(const const_child_iterator &i) const
boost::iterator_range< attribute_iterator > attr_itors
boost::iterator_range< all_children_iterator > all_children_itors
void copy_attributes(const config &from, T... keys)
Copies attributes that exist in the source config.
friend bool operator>=(const this_type &a, const this_type &b)
const attribute & reference
friend difference_type operator-(const this_type &a, const this_type &b)
child_pos(child_map::iterator p, unsigned i)
friend this_type operator-(const this_type &a, Itor::difference_type n)
friend bool operator<(const this_type &a, const this_type &b)
bool operator!=(const const_all_children_iterator &i) const
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.
std::vector< std::unique_ptr< config > > child_list
bool operator!=(const all_children_iterator &i) const
const config & child(config_key_type key, int n=0) const
Returns the nth child with the given key, or a reference to an invalid config if there is none...
config & add_child(config_key_type key)
any_child(const child_map::key_type *k, config *c)
void merge_attributes(const config &)
this_type & operator+=(difference_type n)
void swap(config &lhs, config &rhs)
Implement non-member swap function for std::swap (calls config::swap).
const_all_children_iterator ordered_begin() const
const config & operator[](Itor::difference_type n) const
std::vector< child_pos >::const_iterator Itor
static const char * diff_track_attribute
The name of the attribute used for tracking diff changes.
attribute_iterator operator--(int)
arrow_helper(const all_children_iterator &i)
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.
friend bool operator>(const this_type &a, const this_type &b)
Base class for all the errors encountered by the engine.
void clear_all_children()
boost::iterator_range< child_iterator > child_itors
friend bool operator<(const this_type &a, const this_type &b)
const_all_children_iterator(const all_children_iterator &i)
friend difference_type operator-(const this_type &a, const this_type &b)
reference operator*() const
const any_child reference
std::random_access_iterator_tag iterator_category
const_child_iterator operator--(int)
friend bool operator>=(const this_type &a, const this_type &b)
const attribute * pointer
throw_when_child_not_found()
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.
pointer operator->() const
const_all_children_iterator(const Itor &i)
child_iterator operator++(int)
std::random_access_iterator_tag iterator_category
friend bool operator<=(const this_type &a, const this_type &b)
A config object defines a single node in a WML file, with access to child nodes.
std::ostream & operator<<(std::ostream &, const config &)
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.
static map_location::DIRECTION n
attribute_iterator(const Itor &i)
void remove_child(config_key_type key, unsigned index)
friend bool operator<(const this_type &a, const this_type &b)
friend this_type operator+(const this_type &a, difference_type n)
const_all_children_iterator ordered_cend() const
bool operator==(const const_attribute_iterator &i) const
const attribute value_type
std::string::const_iterator iterator
child_map children_
A list of all children of this node.
A simple wrapper class for optional reference types.
static utils::const_clone_ref< config, T > child(T config, config_key_type key, const std::string &parent)
Implementation for the wrappers for [const] config& child(const std::string& key, const std::string& ...
attribute_map::iterator Itor
const_attribute_iterator & operator--()
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 ...
bool operator!=(const const_attribute_iterator &i) const
all_children_iterator & operator++()
friend this_type operator+(Itor::difference_type n, const this_type &a)
all_children_iterator this_type