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) | |
Initializes validator from file. More... | |
void | set_create_exceptions (bool value) |
virtual void | open_tag (const std::string &name, int start_line=0, const std::string &file="", bool addittion=false) |
Is called when parser opens tag. More... | |
virtual void | close_tag () |
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) |
Validates config. More... | |
virtual void | validate_key (const config &cfg, const std::string &name, const std::string &value, int start_line, const std::string &file) |
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 () | |
Constructor of validator can throw validator::error. More... | |
virtual | ~abstract_validator () |
Private Types | |
enum | message_type { WRONG_TAG, EXTRA_TAG, MISSING_TAG, EXTRA_KEY, MISSING_KEY, WRONG_VALUE } |
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 |
Private Member Functions | |
void | print (message_info &) |
bool | read_config_file (const std::string &filename) |
Reads config from input. More... | |
Private Attributes | |
bool | config_read_ |
Shows, if validator is intialized with schema file;. More... | |
bool | create_exceptions_ |
Controls the way to print errors. More... | |
class_tag | root_ |
Root of schema information. More... | |
std::stack< const class_tag * > | stack_ |
cnt_stack | counter_ |
Contains number of children. More... | |
std::stack< message_map > | cache_ |
Caches error messages. More... | |
std::map< std::string, boost::regex > | types_ |
Type validators. More... | |
Realization of serialization/validator.hpp abstract validator.
Based on stack. Uses some stacks to store different info.
Definition at line 43 of file schema_validator.hpp.
|
private |
Counters are mapped by tag name.
Definition at line 79 of file schema_validator.hpp.
|
private |
And counter maps are organize in stack.
Definition at line 84 of file schema_validator.hpp.
|
private |
Definition at line 116 of file schema_validator.hpp.
|
private |
Definition at line 117 of file schema_validator.hpp.
|
private |
Enumerator | |
---|---|
WRONG_TAG | |
EXTRA_TAG | |
MISSING_TAG | |
EXTRA_KEY | |
MISSING_KEY | |
WRONG_VALUE |
Definition at line 86 of file schema_validator.hpp.
|
virtual |
Definition at line 114 of file schema_validator.cpp.
schema_validation::schema_validator::schema_validator | ( | const std::string & | filename | ) |
Initializes validator from file.
Throws abstract_validator::error if any error.
Definition at line 116 of file schema_validator.cpp.
References cache_, counter_, ERR_VL, error(), schema_validation::class_tag::expand_all(), LOG_VL, read_config_file(), root_, and stack_.
|
virtual |
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.
Definition at line 201 of file schema_validator.cpp.
|
virtual |
Is called when parser opens tag.
name | Name of tag |
start_line | Line in file |
file | Name of file |
Implements abstract_validator.
Definition at line 175 of file schema_validator.cpp.
References cache_, schema_validation::schema_validator::counter::cnt, counter_, create_exceptions_, root_, stack_, and schema_validation::wrong_tag_error().
|
private |
Definition at line 292 of file schema_validator.cpp.
References create_exceptions_, EXTRA_KEY, schema_validation::extra_key_error(), EXTRA_TAG, schema_validation::extra_tag_error(), schema_validation::schema_validator::message_info::file, schema_validation::schema_validator::message_info::key, schema_validation::schema_validator::message_info::line, MISSING_KEY, schema_validation::missing_key_error(), MISSING_TAG, schema_validation::missing_tag_error(), schema_validation::schema_validator::message_info::n, 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 validate().
|
private |
Reads config from input.
Definition at line 139 of file schema_validator.cpp.
References config::child_range(), config_read_, e, ERR_VL, game_config::config_cache::instance(), preprocess_file(), read(), root_, types_, and game::error::what().
Referenced by schema_validator().
|
inline |
Definition at line 51 of file schema_validator.hpp.
References create_exceptions_.
|
virtual |
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.
Definition at line 207 of file schema_validator.cpp.
References cache_, config_read_, counter_, EXTRA_TAG, config::get(), i, MISSING_KEY, MISSING_TAG, print(), and stack_.
|
virtual |
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 |
start_line | Line in file |
file | Name of file |
Implements abstract_validator.
Definition at line 261 of file schema_validator.cpp.
References cache_, config_read_, EXTRA_KEY, schema_validation::class_key::get_type(), stack_, schema_validation::sub(), types_, and WRONG_VALUE.
|
private |
Caches error messages.
Definition at line 145 of file schema_validator.hpp.
Referenced by open_tag(), schema_validator(), validate(), and validate_key().
|
private |
Shows, if validator is intialized with schema file;.
Definition at line 127 of file schema_validator.hpp.
Referenced by read_config_file(), validate(), and validate_key().
|
private |
Contains number of children.
Definition at line 141 of file schema_validator.hpp.
Referenced by close_tag(), open_tag(), schema_validator(), and validate().
|
private |
Controls the way to print errors.
Definition at line 131 of file schema_validator.hpp.
Referenced by open_tag(), print(), and set_create_exceptions().
|
private |
Root of schema information.
Definition at line 135 of file schema_validator.hpp.
Referenced by open_tag(), read_config_file(), and schema_validator().
|
private |
Definition at line 137 of file schema_validator.hpp.
Referenced by close_tag(), open_tag(), schema_validator(), validate(), and validate_key().
|
private |
Type validators.
Definition at line 149 of file schema_validator.hpp.
Referenced by read_config_file(), and validate_key().