36 #ifdef CONFIG_USE_STL_RANGES
37 #undef CONFIG_USE_STL_RANGES
40 #ifdef __cpp_lib_ranges
41 #define CONFIG_USE_STL_RANGES
44 #ifdef CONFIG_USE_STL_RANGES
47 #include <boost/range/adaptor/map.hpp>
48 #include <boost/range/adaptor/transformed.hpp>
56 #include <string_view>
60 #include <boost/range/iterator_range.hpp>
90 throw std::runtime_error(
"Optional reference has no value");
105 return opt_ !=
nullptr;
109 explicit operator bool()
const
162 mutable bool tested_;
194 template<
typename... Args>
206 typedef std::map<std::string, child_list, std::less<>>
child_map;
258 typedef child_list::const_iterator
Itor;
349 typedef attribute_map::const_iterator
Itor;
373 typedef boost::iterator_range<attribute_iterator>
attr_itors;
550 template<
typename... T>
559 template<
typename... T>
562 for(
const auto& key : {keys...}) {
563 auto* attr = from.
get(key);
565 (*this)[key] = *attr;
579 template<
typename... T>
582 for(
const auto& key : {keys...}) {
584 (*this)[key] = from[key];
599 const std::string &value);
602 const std::string &value)
const
606 const std::string &value);
609 const std::string &value)
const;
615 template<
typename... T>
638 std::string
debug()
const;
639 std::string
hash()
const;
657 const child_map::key_type &
key;
662 struct const_all_children_iterator;
729 typedef std::vector<child_pos>::const_iterator
Itor;
792 template<
typename Res>
795 const auto& [key, list] = *elem.pos;
796 return { key, *list[elem.index] };
800 #ifdef __cpp_explicit_this_parameter
803 template<
typename Self>
805 {
return self.ordered_children | std::views::transform(&config::any_tag_view<Self>); }
811 #ifdef CONFIG_USE_STL_RANGES
812 {
return ordered_children | std::views::transform(&config::any_tag_view<const config&>); }
814 {
return ordered_children | boost::adaptors::transformed(&config::any_tag_view<const config&>); }
819 #ifdef CONFIG_USE_STL_RANGES
820 {
return ordered_children | std::views::transform(&config::any_tag_view<config&>); }
822 {
return ordered_children | boost::adaptors::transformed(&config::any_tag_view<config&>); }
929 #ifdef __cpp_lib_ranges
932 return children_ | boost::adaptors::map_keys;
959 template<
typename Key,
typename Value,
typename... Rest>
962 if constexpr(std::is_same_v<std::decay_t<Value>,
config>) {
963 cfg.
add_child(std::forward<Key>(key), std::forward<Value>(val));
965 cfg.
insert(std::forward<Key>(key), std::forward<Value>(val));
968 if constexpr(
sizeof...(Rest) > 0) {
974 template<
typename... 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.
void merge_children_by_attribute(config_key_type key, config_key_type attribute)
All children with the given key and with equal values of the specified attribute will be merged into ...
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
static auto any_tag_view(const child_pos &elem) -> std::pair< const child_map::key_type &, Res >
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
void remove_child(config_key_type key, std::size_t index)
void merge_children(config_key_type key)
All children with the given key will be merged into the first element with that key.
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.
auto all_children_view() const
In-order iteration over all children.
void merge_attributes(const config &)
const_all_children_iterator ordered_end() const
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)
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.
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 range 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)
void remove_children(config_key_type key, std::function< bool(const config &)> p={})
Removes all children with tag key for which p returns true.
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
auto child_name_view() const
A non-owning view over all child tag names.
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
void append_children_by_move(config &cfg, config_key_type key)
Moves children with the given name from the given config to this one.
boost::iterator_range< const_child_iterator > const_child_itors
void append_children(const config &cfg)
Adds children from cfg.
auto all_children_view()
In-order iteration over all children.
void insert(config_key_type key, T &&value)
Inserts an attribute into the config.
void splice_children(config &src, config_key_type 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)
Equivalent 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
optional_config_impl(utils::nullopt_t)
utils::const_clone_t< config_attribute_value, T > & operator[](config_key_type key)
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.
void config_construct_unpack(config &cfg, Key &&key, Value &&val, Rest... fwd)
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
rect src
Non-transparent portion of the surface to compose.
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)
Base class for all the errors encountered by the engine.
static map_location::direction n