28 wml_tag
any_tag(
"", 0, -1,
"",
true);
31 : name_(cfg[
"name"].str())
32 , min_(cfg[
"min"].to_int())
33 , max_(cfg[
"max"].str() ==
"infinite" ? -1 : cfg[
"max"].to_int(1))
34 , min_children_(cfg[
"min_tags"].to_int())
35 , max_children_(cfg[
"max_tags"].str() ==
"infinite" ? -1 : cfg[
"max_tags"].to_int(-1))
42 , fuzzy_(name_.find_first_of(
"*?+") !=
std::string::npos)
43 , any_tag_(cfg[
"any_tag"].to_bool())
53 super_ = cfg[
"super"].str();
67 std::string link_name = link[
"name"].str();
87 std::istringstream
i(s);
95 std::istringstream
i(s);
103 std::string::size_type pos_last = link.rfind(
'/');
105 std::string name_link = link.substr(pos_last + 1, link.length());
106 links_.emplace(name_link, link);
114 if(cond.matches(match)) {
115 if(
auto key = cond.find_key(name, match,
true)) {
121 const auto it_keys =
keys_.find(name);
122 if(it_keys !=
keys_.end()) {
123 return &(it_keys->second);
126 key_map::const_iterator it_fuzzy = std::find_if(
keys_.begin(),
keys_.end(), [&name](
const key_map::value_type& key){
127 if(!key.second.is_fuzzy()) {
132 if(it_fuzzy !=
keys_.end()) {
133 return &(it_fuzzy->second);
137 for(
auto& cond : conditions_) {
138 if(cond.matches(match)) {
140 if(
auto key = cond.find_key(name, match,
false)) {
146 if(
const wml_key* found_key = super_tag->find_key(name, match)) {
157 const auto it_links =
links_.find(name);
158 if(it_links !=
links_.end()) {
159 return &(it_links->second);
167 if(fullpath.empty()) {
171 std::string::size_type pos = fullpath.find(
'/');
173 std::string next_path;
175 if(pos != std::string::npos) {
176 name = fullpath.substr(0, pos);
177 next_path = fullpath.substr(pos + 1, fullpath.length());
185 if(cond.matches(match)) {
186 if(
auto tag = cond.find_tag(fullpath, root, match,
true)) {
192 const auto it_tags =
tags_.find(name);
193 if(it_tags !=
tags_.end()) {
194 if(next_path.empty()) {
195 return &(it_tags->second);
197 return it_tags->second.find_tag(next_path, root, match);
201 const auto it_links =
links_.find(name);
202 if(it_links !=
links_.end()) {
203 return root.
find_tag(it_links->second +
"/" + next_path, root, match);
206 const auto it_fuzzy = std::find_if(
tags_.begin(),
tags_.end(), [&name](
const tag_map::value_type& tag){
207 if(!tag.second.fuzzy_) {
212 if(it_fuzzy !=
tags_.end()) {
213 if(next_path.empty()) {
214 return &(it_fuzzy->second);
216 return it_tags->second.
find_tag(next_path, root, match);
221 for(
auto& cond : conditions_) {
222 if(cond.matches(match)) {
224 if(
auto tag = cond.find_tag(fullpath, root, match,
false)) {
230 if(
const wml_tag* found_tag = super_tag->
find_tag(fullpath, root, match)) {
245 for(
auto& tag :
tags_) {
246 tag.second.expand(root);
247 tag.second.expand_all(root);
251 cond.expand_all(root);
259 if(
i->second.get_type() ==
type) {
266 for(
auto& tag :
tags_) {
267 tag.second.remove_keys_by_type(type);
274 for(
int j = 0; j <
level; j++) {
279 << s <<
" name=\"" <<
name_ <<
"\"\n" 280 << s <<
" min=\"" <<
min_ <<
"\"\n" 281 << s <<
" max=\"" <<
max_ <<
"\"\n";
284 os << s <<
" super=\"" <<
super_ <<
"\"\n";
287 for(
auto& tag :
tags_) {
288 tag.second.printl(os, level + step, step);
291 for(
auto& link :
links_) {
295 <<
" name=\"" << link.second <<
"\"\n" 300 for(
auto& key :
keys_) {
301 key.second.print(os, level + step);
306 os << s <<
"[/tag]\n";
311 if(path.empty() || path ==
"/") {
314 if(it ==
tags_.end()) {
317 it->second.set_min(tag.
min_);
318 it->second.set_max(tag.
max_);
319 it->second.add_tags(tag.
tags_);
320 it->second.add_keys(tag.
keys_);
321 it->second.add_links(tag.
links_);
329 std::string::size_type pos = path.find(
'/');
330 std::string name = path.substr(0, pos);
331 std::string next_path = path.substr(pos + 1, path.length());
333 auto it_links =
links_.find(name);
334 if(it_links !=
links_.end()) {
335 root.
add_tag(it_links->second +
"/" + next_path, tag, root);
338 auto it_tags =
tags_.find(name);
339 if(it_tags ==
tags_.end()) {
342 subtag.
add_tag(next_path, tag, root);
343 tags_.emplace(name, subtag);
347 it_tags->second.add_tag(next_path, tag, root);
360 if(super_tag !=
this) {
374 const std::string key = switch_cfg[
"key"];
375 bool allow_missing =
false;
376 for(
const auto& case_cfg : switch_cfg.
child_range(
"case")) {
377 if(case_cfg.has_attribute(
"value")) {
380 for(
const auto& value : values) {
388 default_cfg.
add_child(
"not")[key] = value;
390 if(!allow_missing && case_cfg[
"trigger_if_missing"].to_bool()) {
392 missing_filter[
"glob_on_" + key] =
"*";
393 allow_missing =
true;
400 const std::string name =
formatter() <<
get_name() <<
'[' << key <<
'=' << case_cfg[
"value"] <<
']';
408 default_cfg.
add_child(
"and")[
"glob_on_" + key] =
"*";
418 config filter = cond_cfg, else_filter;
422 else_filter.add_child(
"not", filter);
429 for(
auto elseif_cfg : cond_cfg.
child_range(
"elseif")) {
430 config elseif_filter = elseif_cfg, old_else_filter = else_filter;
432 else_filter.add_child(
"not", elseif_filter);
435 conditions_.emplace_back(elseif_cfg.child_or_empty(
"then"), elseif_filter);
461 current = base_tag.
tags_.begin();
462 condition_queue.push(&base_tag);
467 while(current == condition_queue.front()->tags_.end()) {
468 condition_queue.pop();
469 if(condition_queue.empty()) {
472 const wml_tag& new_base = *condition_queue.front();
473 current= new_base.
tags_.begin();
481 current = base_tag.
keys_.begin();
482 condition_queue.push(&base_tag);
487 while(current == condition_queue.front()->keys_.end()) {
488 condition_queue.pop();
489 if(condition_queue.empty()) {
492 const wml_tag& new_base = *condition_queue.front();
493 current = new_base.
keys_.begin();
500 if(condition.matches(match)) {
int max_children_
maximum number of children.
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...
void ensure_valid_or_end()
bool matches(const config &filter) const
void clear_children(T... keys)
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)
void add_switch(const config &switch_cfg)
Stores information about tag.
bool wildcard_string_match(const std::string &str, const std::string &match)
Match using '*' as any number of characters (including none), '+' as one or more characters, and '?' as any one character.
void add_filter(const config &cond_cfg)
void remove_keys_by_type(const std::string &type)
Removes all keys with this type.
void append_children(const config &cfg)
Adds children from cfg.
const wml_key * find_key(const std::string &name, const config &match, bool ignore_super=false) const
Returns pointer to child key.
This file contains object "tag", which is used to store information about tags while annotation parsi...
void add_link(const std::string &link)
const wml_tag * find_tag(const std::string &fullpath, const wml_tag &root, const config &match, bool ignore_super=false) const
Returns pointer to tag using full path to it.
bool matches(const config &cfg) const
super_list super_refs_
super-tag references
REMOVE_EMPTY: remove empty elements.
void add_key(const wml_key &new_key)
tag_map tags_
children tags
std::vector< wml_condition > condition_list
std::string name_
name of tag.
static void push_new_tag_conditions(std::queue< const wml_tag *> &q, const config &match, const wml_tag &tag)
void add_tag(const wml_tag &new_tag)
wml_tag any_tag("", 0, -1, "", true)
condition_list conditions_
conditional partial matches
void init(const wml_tag &base_tag)
void printl(std::ostream &os, int level, int step=4)
the same as wml_tag::print(std::ostream&) but indents different levels with step space.
int min_
minimum number of occurrences.
void print(std::ostream &os)
Prints information about tag to outputstream, recursively is used to print tag info the format is nex...
wml_key is used to save the information about one key.
link_map links_
links to possible children.
static map_location::DIRECTION s
int max_
maximum number of occurrences.
bool any_tag_
whether this tag allows arbitrary subtags.
static map_location::DIRECTION sw
config & add_child(config_key_type key)
void set_name(const std::string &name)
void expand(wml_tag &root)
Expands all "super", storing direct references for easier access.
void expand_all(wml_tag &root)
Calls the expansion on each child.
std::vector< std::string > split(const config_attribute_value &val)
const std::string & get_name() const
void add_conditions(const condition_list &list)
std::string super_
name of tag to extend "super-tag" Extension is smth like inheritance and is used in case when you nee...
A config object defines a single node in a WML file, with access to child nodes.
const std::string * find_link(const std::string &name) const
Returns pointer to child link.