32 return str.empty() ?
empty :
false;
52 std::shared_ptr<wml_type> wml_type::from_config(
const config& cfg)
54 std::optional<config::const_child_itors> composite_range;
55 std::shared_ptr<wml_type>
type;
57 type = std::make_shared<wml_type_union>(cfg[
"name"]);
59 }
else if(cfg.
has_child(
"intersection")) {
60 type = std::make_shared<wml_type_intersection>(cfg[
"name"]);
64 int list_min = list_cfg[
"min"].to_int();
65 int list_max = list_cfg[
"max"].str() ==
"infinite" ? -1 : list_cfg[
"max"].to_int(-1);
66 if(list_max < 0) list_max = INT_MAX;
67 type = std::make_shared<wml_type_list>(cfg[
"name"], list_cfg[
"split"].str(
"\\s*,\\s*"), list_min, list_max);
68 composite_range.emplace(list_cfg.
child_range(
"element"));
70 auto t = std::make_shared<wml_type_simple>(cfg[
"name"], cfg[
"value"]);
71 if(cfg[
"allow_translatable"].to_bool())
t->allow_translatable();
74 type = std::make_shared<wml_type_alias>(cfg[
"name"], cfg[
"link"]);
78 for(
const config& elem : *composite_range) {
79 composite_type->
add_type(wml_type::from_config(elem));
89 return boost::regex_match(value.
str(), sub, pattern_);
95 auto it = type_map.find(link_);
96 if(it == type_map.end()) {
100 cached_ = it->second;
102 return cached_->matches(value, type_map);
107 for(
const auto&
type : subtypes_) {
108 if(
type->matches(value, type_map)) {
117 for(
const auto&
type : subtypes_) {
118 if(!
type->matches(value, type_map)) {
127 auto value = value_attr.
str();
128 boost::sregex_token_iterator it(value.begin(), value.end(), split_, -1), end;
130 bool result = std::all_of(it, end, [
this, &type_map, &n](
const boost::ssub_match& match){
132 if(!match.matched)
return true;
135 elem = std::string(match.first, match.second);
136 return this->wml_type_union::matches(elem, type_map);
138 return result && n >= min_ && n <= max_;
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...
bool operator()(const t_string &) const
This file contains object "type", which is used to store information about types while annotation par...
Variant for storing WML attributes.
bool has_attribute(config_key_type key) const
bool has_child(config_key_type key) const
Determine whether a config has a child or not.
child_itors child_range(config_key_type key)
Definitions for the interface to Wesnoth Markup Language (WML).
std::map< std::string, ptr > map
bool operator()(const std::string &str) const
bool operator()(const std::monostate &) const
auto apply_visitor(const V &visitor) const
Visitor support: Applies a visitor to the underlying variant.
A config object defines a single node in a WML file, with access to child nodes.
bool operator()(const T &) const
static map_location::DIRECTION n
Stores information about a schema type.
void add_type(std::shared_ptr< wml_type > type)
std::string str(const std::string &fallback="") const