Realization of serialization/validator.hpp abstract validator. More...
#include <schema_validator.hpp>
Classes | |
struct | counter |
struct | message_info |
Messages are cached. More... | |
Public Member Functions | |
virtual | ~schema_validator () |
schema_validator (const std::string &filename, bool validate_schema=false) | |
Initializes validator from file. More... | |
void | set_create_exceptions (bool value) |
const std::vector< std::string > & | get_errors () const |
virtual void | open_tag (const std::string &name, const config &parent, int start_line=0, const std::string &file="", bool addition=false) override |
Is called when parser opens tag. More... | |
virtual void | close_tag () override |
As far as parser is built on stack, some realizations can store stack too. More... | |
virtual void | validate (const config &cfg, const std::string &name, int start_line, const std::string &file) override |
Validates config. More... | |
virtual void | validate_key (const config &cfg, const std::string &name, const config_attribute_value &value, int start_line, const std::string &file) override |
Checks if key is allowed and if its value is valid What exactly is validated depends on validator realization. More... | |
Public Member Functions inherited from abstract_validator | |
abstract_validator (const std::string &name) | |
Constructor of validator can throw validator::error. More... | |
virtual | ~abstract_validator () |
Protected Types | |
enum | { WRONG_TAG , EXTRA_TAG , MISSING_TAG , EXTRA_KEY , MISSING_KEY , WRONG_VALUE , MISSING_SUPER , SUPER_CYCLE , NEXT_ERROR } |
using | message_type = int |
Protected Member Functions | |
virtual void | print (message_info &) |
template<typename... T> | |
void | queue_message (const config &cfg, T &&... args) |
const wml_tag & | active_tag () const |
std::string | active_tag_path () const |
bool | have_active_tag () const |
bool | is_valid () const |
wml_type::ptr | find_type (const std::string &type) const |
Protected Attributes | |
bool | create_exceptions_ |
Controls the way to print errors. More... | |
Private Types | |
typedef std::map< std::string, counter > | cnt_map |
Counters are mapped by tag name. More... | |
typedef std::stack< cnt_map > | cnt_stack |
And counter maps are organize in stack. More... | |
typedef std::deque< message_info > | message_list |
typedef std::map< const config *, message_list > | message_map |
using | derivation_graph_t = boost::adjacency_list< boost::vecS, boost::vecS, boost::directedS, std::pair< const wml_tag *, std::string >, std::tuple< config, std::string, int > > |
using | link_graph_t = boost::adjacency_list< boost::vecS, boost::vecS, boost::directedS, std::string > |
using | link_graph_map_t = std::map< const wml_type_alias *, link_graph_t::vertex_descriptor > |
Private Member Functions | |
void | print_cache () |
bool | read_config_file (const std::string &filename) |
Reads config from input. More... | |
void | detect_derivation_cycles () |
utils::optional< std::map< std::string, wml_key > > | find_mandatory_keys (const wml_tag *tag, const config &cfg) const |
Collects all mandatory keys for a tag, including the super keys and overrides. More... | |
utils::optional< std::map< std::string, wml_key > > | find_mandatory_keys (const wml_tag *tag, const config &cfg, std::vector< const wml_tag * > &visited) const |
void | validate_mandatory_keys (const wml_tag *tag, const config &cfg, const std::string &name, int start_line, const std::string &file) |
Validates that all mandatory keys for a tag are present. More... | |
void | validate_mandatory_keys (const std::map< std::string, wml_key > &mandatory_keys, const wml_tag *tag, const config &cfg, const std::string &name, int start_line, const std::string &file, std::vector< const wml_tag * > &visited) |
void | detect_link_cycles (const std::string &filename) |
void | collect_link_source (link_graph_t &link_graph, link_graph_map_t &link_map, const std::string &type_name, const wml_type *type) |
void | collect_link_target (link_graph_t &link_graph, link_graph_map_t &link_map, const std::string &type_name, const wml_type *type, const wml_type_alias *alias) |
Private Attributes | |
bool | config_read_ |
Shows, if validator is initialized with schema file. More... | |
wml_tag | root_ |
Root of schema information. More... | |
std::stack< const wml_tag * > | stack_ |
cnt_stack | counter_ |
Contains number of children. More... | |
std::stack< message_map > | cache_ |
Caches error messages. More... | |
wml_type::map | types_ |
Type validators. More... | |
bool | validate_schema_ |
std::vector< std::string > | errors_ |
derivation_graph_t | derivation_graph_ |
std::map< const wml_tag *, derivation_graph_t::vertex_descriptor > | derivation_map_ |
Additional Inherited Members | |
Public Attributes inherited from abstract_validator | |
const std::string | name_ |
Realization of serialization/validator.hpp abstract validator.
Based on stack. Uses some stacks to store different info.
Definition at line 39 of file schema_validator.hpp.
|
private |
Counters are mapped by tag name.
Definition at line 78 of file schema_validator.hpp.
|
private |
And counter maps are organize in stack.
Definition at line 81 of file schema_validator.hpp.
|
private |
Definition at line 168 of file schema_validator.hpp.
|
private |
Definition at line 206 of file schema_validator.hpp.
|
private |
Definition at line 201 of file schema_validator.hpp.
|
private |
Definition at line 127 of file schema_validator.hpp.
|
private |
Definition at line 128 of file schema_validator.hpp.
|
protected |
Definition at line 84 of file schema_validator.hpp.
|
protected |
Enumerator | |
---|---|
WRONG_TAG | |
EXTRA_TAG | |
MISSING_TAG | |
EXTRA_KEY | |
MISSING_KEY | |
WRONG_VALUE | |
MISSING_SUPER | |
SUPER_CYCLE | |
NEXT_ERROR |
Definition at line 85 of file schema_validator.hpp.
|
virtual |
Definition at line 247 of file schema_validator.cpp.
schema_validation::schema_validator::schema_validator | ( | const std::string & | filename, |
bool | validate_schema = false |
||
) |
Initializes validator from file.
Throws abstract_validator::error if any error.
Definition at line 251 of file schema_validator.cpp.
References cache_, counter_, ERR_VL, schema_validation::wml_tag::expand_all(), LOG_VL, read_config_file(), root_, and stack_.
|
protected |
Definition at line 639 of file schema_validator.cpp.
References have_active_tag(), and stack_.
Referenced by schema_validation::schema_self_validator::close_tag(), open_tag(), validate(), validate_key(), and schema_validation::schema_self_validator::validate_key().
|
protected |
Definition at line 659 of file schema_validator.cpp.
References utils::join(), game_config::path, and stack_.
Referenced by validate().
|
overridevirtual |
As far as parser is built on stack, some realizations can store stack too.
So they need to know if tag was closed.
Implements abstract_validator.
Reimplemented in schema_validation::schema_self_validator.
Definition at line 409 of file schema_validator.cpp.
References counter_, print_cache(), and stack_.
Referenced by schema_validation::schema_self_validator::close_tag().
|
private |
Definition at line 337 of file schema_validator.cpp.
References collect_link_target(), and types_.
Referenced by detect_link_cycles().
|
private |
Definition at line 351 of file schema_validator.cpp.
References schema_validation::wml_type_alias::link().
Referenced by collect_link_source().
|
private |
Definition at line 591 of file schema_validator.cpp.
References derivation_graph_, derivation_map_, draw::line(), abstract_validator::name_, queue_message(), and SUPER_CYCLE.
Referenced by validate().
|
private |
Definition at line 310 of file schema_validator.cpp.
References collect_link_source(), filename, schema_validation::link_cycle_error(), and types_.
Referenced by read_config_file().
|
private |
Collects all mandatory keys for a tag, including the super keys and overrides.
The returned map can contain non-mandatory keys if they are overriden, please check the is_mandatory() result.
Definition at line 510 of file schema_validator.cpp.
References markup::tag().
Referenced by find_mandatory_keys(), and validate_mandatory_keys().
|
private |
Definition at line 517 of file schema_validator.cpp.
References _(), find_mandatory_keys(), and markup::tag().
|
protected |
Definition at line 645 of file schema_validator.cpp.
References types_.
Referenced by validate_key().
|
inline |
Definition at line 55 of file schema_validator.hpp.
References errors_.
|
protected |
Definition at line 654 of file schema_validator.cpp.
References stack_.
Referenced by active_tag(), schema_validation::schema_self_validator::close_tag(), validate(), validate_key(), and schema_validation::schema_self_validator::validate_key().
|
inlineprotected |
Definition at line 164 of file schema_validator.hpp.
References config_read_.
Referenced by validate(), validate_key(), and schema_validation::schema_self_validator::validate_key().
|
overridevirtual |
Is called when parser opens tag.
name | Name of tag |
parent | The parent config |
start_line | Line in file |
file | Name of file |
addition |
Implements abstract_validator.
Reimplemented in schema_validation::schema_self_validator.
Definition at line 378 of file schema_validator.cpp.
References active_tag(), cache_, schema_validation::schema_validator::counter::cnt, counter_, create_exceptions_, errors_, schema_validation::wml_tag::find_tag(), root_, stack_, markup::tag(), and schema_validation::wrong_tag_error().
Referenced by schema_validation::schema_self_validator::open_tag().
|
protectedvirtual |
Reimplemented in schema_validation::schema_self_validator.
Definition at line 672 of file schema_validator.cpp.
References create_exceptions_, errors_, schema_validation::schema_validator::message_info::expected, EXTRA_KEY, schema_validation::extra_key_error(), EXTRA_TAG, schema_validation::extra_tag_error(), schema_validation::schema_validator::message_info::file, schema_validation::inheritance_cycle_error(), schema_validation::schema_validator::message_info::key, schema_validation::schema_validator::message_info::line, MISSING_KEY, schema_validation::missing_key_error(), MISSING_SUPER, schema_validation::missing_super_error(), MISSING_TAG, schema_validation::missing_tag_error(), schema_validation::schema_validator::message_info::n, SUPER_CYCLE, schema_validation::schema_validator::message_info::tag, schema_validation::schema_validator::message_info::type, schema_validation::schema_validator::message_info::value, WRONG_TAG, schema_validation::wrong_tag_error(), WRONG_VALUE, and schema_validation::wrong_value_error().
Referenced by schema_validation::schema_self_validator::print(), and print_cache().
|
private |
Definition at line 420 of file schema_validator.cpp.
References cache_, and print().
Referenced by close_tag(), and validate().
|
inlineprotected |
Definition at line 156 of file schema_validator.hpp.
References cache_.
Referenced by schema_validation::schema_self_validator::check_for_duplicates(), detect_derivation_cycles(), schema_validation::schema_self_validator::detect_schema_derivation_cycles(), validate(), schema_validation::schema_self_validator::validate(), validate_key(), schema_validation::schema_self_validator::validate_key(), and validate_mandatory_keys().
|
private |
Reads config from input.
Definition at line 271 of file schema_validator.cpp.
References config::child_range(), config_read_, detect_link_cycles(), e, ERR_VL, filename, schema_validation::wml_type::from_config(), g, game_config::config_cache::instance(), preprocess_file(), read(), root_, types_, validate_schema_, and validator.
Referenced by schema_validator().
|
inline |
Definition at line 50 of file schema_validator.hpp.
References create_exceptions_.
|
overridevirtual |
Validates config.
Checks if all mandatory elements are present. What exactly is validated depends on validator realization
cfg | Config to be validated. |
name | Name of tag |
start_line | Line in file |
file | Name of file |
Implements abstract_validator.
Reimplemented in schema_validation::schema_self_validator.
Definition at line 435 of file schema_validator.cpp.
References active_tag(), active_tag_path(), cache_, counter_, derivation_graph_, derivation_map_, detect_derivation_cycles(), EXTRA_TAG, schema_validation::wml_tag::get_max_children(), schema_validation::wml_tag::get_min_children(), schema_validation::wml_tag::get_name(), schema_validation::wml_tag::get_super(), have_active_tag(), is_valid(), MISSING_SUPER, MISSING_TAG, abstract_validator::name_, print_cache(), queue_message(), root_, utils::split(), schema_validation::wml_tag::super(), markup::tag(), schema_validation::wml_tag::tags(), and validate_mandatory_keys().
Referenced by schema_validation::schema_self_validator::validate().
|
overridevirtual |
Checks if key is allowed and if its value is valid What exactly is validated depends on validator realization.
cfg | Config to be validated. |
name | Name of tag |
value | The key's value |
start_line | Line in file |
file | Name of file |
Implements abstract_validator.
Reimplemented in schema_validation::schema_self_validator.
Definition at line 614 of file schema_validator.cpp.
References active_tag(), EXTRA_KEY, schema_validation::wml_tag::find_key(), find_type(), schema_validation::wml_key::get_type(), have_active_tag(), is_valid(), queue_message(), utils::split(), types_, and WRONG_VALUE.
Referenced by schema_validation::schema_self_validator::validate_key().
|
private |
Definition at line 566 of file schema_validator.cpp.
References config::get(), MISSING_KEY, queue_message(), and markup::tag().
|
private |
Validates that all mandatory keys for a tag are present.
Definition at line 552 of file schema_validator.cpp.
References find_mandatory_keys(), and markup::tag().
Referenced by validate().
|
private |
Caches error messages.
Definition at line 145 of file schema_validator.hpp.
Referenced by open_tag(), print_cache(), queue_message(), schema_validator(), and validate().
|
private |
Shows, if validator is initialized with schema file.
Definition at line 134 of file schema_validator.hpp.
Referenced by is_valid(), and read_config_file().
|
private |
Contains number of children.
Definition at line 142 of file schema_validator.hpp.
Referenced by close_tag(), open_tag(), schema_validator(), and validate().
|
protected |
Controls the way to print errors.
Definition at line 121 of file schema_validator.hpp.
Referenced by open_tag(), print(), schema_validation::schema_self_validator::print(), and set_create_exceptions().
|
private |
Definition at line 174 of file schema_validator.hpp.
Referenced by detect_derivation_cycles(), and validate().
|
private |
Definition at line 175 of file schema_validator.hpp.
Referenced by detect_derivation_cycles(), and validate().
|
private |
Definition at line 152 of file schema_validator.hpp.
Referenced by get_errors(), open_tag(), and print().
|
private |
Root of schema information.
Definition at line 137 of file schema_validator.hpp.
Referenced by open_tag(), read_config_file(), schema_validator(), and validate().
|
private |
Definition at line 139 of file schema_validator.hpp.
Referenced by active_tag(), active_tag_path(), close_tag(), have_active_tag(), open_tag(), and schema_validator().
|
private |
Type validators.
Definition at line 148 of file schema_validator.hpp.
Referenced by collect_link_source(), detect_link_cycles(), find_type(), read_config_file(), and validate_key().
|
private |
Definition at line 150 of file schema_validator.hpp.
Referenced by read_config_file().