28 #define ERR_VL LOG_STREAM(err, log_validation)
29 #define WRN_VL LOG_STREAM(warn, log_validation)
30 #define LOG_VL LOG_STREAM(info, log_validation)
33 std::ostringstream ss;
34 ss << line <<
" " << file;
39 #ifndef VALIDATION_ERRORS_LOG
47 flag_exception =
true;
55 std::ostringstream ss;
56 ss <<
"Extra tag [" << name <<
"]; there may only be "
57 << n <<
" [" << name <<
"] in [" << parent <<
"]\n"
58 <<
at(file, line) <<
"\n";
65 std::ostringstream ss;
66 ss <<
"Tag [" << name <<
"] may not be used in ["
68 <<
at(file, line) <<
"\n";
75 std::ostringstream ss;
76 ss <<
"Missing tag [" << name <<
"]; there must be "
77 << n <<
" [" << name <<
"]s in [" << parent <<
"]\n"
78 <<
at(file, line) <<
"\n";
85 std::ostringstream ss;
86 ss <<
"Invalid key '" << key <<
"=' in tag [" << tag
88 <<
at(file, line) <<
"\n";
95 std::ostringstream ss;
96 ss <<
"Missing key '" << key <<
"=' in tag [" << tag
98 <<
at(file, line) <<
"\n";
105 std::ostringstream ss;
106 ss <<
"Invalid value '" << value <<
"' in key '" << key
107 <<
"=' in tag [" << tag <<
"]\n"
108 <<
at(file, line) <<
"\n";
117 : config_read_(false)
126 ERR_VL <<
"Schema file "<< config_file_name <<
" was not read." << std::endl;
128 +
" was not read.\n");
134 LOG_VL <<
"Schema file "<< config_file_name <<
" was read.\n"
135 <<
"Validator initialized\n";
147 ERR_VL <<
"Failed to read file "<< filename <<
":\n" << e.
what() <<
"\n";
152 if (schema[
"name"].str() ==
"root"){
159 types_[
type[
"name"].str()] = boost::regex( type[
"value"].str());
161 catch (std::exception){
212 for (;cache_it !=
cache_.top().end();++cache_it){
214 i != cache_it->second.end(); ++
i){
220 cache_it =
cache_.top().find(&cfg);
221 if (cache_it !=
cache_.top().end()){
222 cache_it->second.clear();
229 tag != p.second ; ++tag){
230 int cnt =
counter_.top()[tag->first].cnt;
231 if (tag->second.get_min() > cnt){
232 cache_.top()[&cfg].push_back(
234 tag->second.get_min(),tag->first,
"",
238 if (tag->second.get_max() < cnt){
239 cache_.top()[&cfg].push_back(
241 tag->second.get_max(),tag->first,
"",
248 key != k.second ; ++key){
249 if (key->second.is_mandatory()){
250 if (cfg.
get(key->first) ==
nullptr){
251 cache_.top()[&cfg].push_back(
274 bool res = boost::regex_match(value,sub,itt->second);
276 cache_.top()[&cfg].push_back(
284 cache_.top()[&cfg].push_back(
std::string lineno_string(const std::string &lineno)
child_itors child_range(const std::string &key)
bool create_exceptions_
Controls the way to print errors.
static config_cache & instance()
Get reference to the singleton object.
static void wrong_value_error(const std::string &file, int line, const std::string &tag, const std::string &key, const std::string &value, bool flag_exception)
cnt_stack counter_
Contains number of children.
static void wrong_tag_error(const std::string &file, int line, const std::string &name, const std::string &parent, bool flag_exception)
const char * what() const
Add a special kind of assert to validate whether the input from WML doesn't contain any problems that...
GLuint GLuint GLsizei GLenum type
static l_noret error(LoadState *S, const char *why)
virtual void close_tag()
As far as parser is built on stack, some realizations can store stack too.
virtual void validate(const config &cfg, const std::string &name, int start_line, const std::string &file)
Validates config.
std::map< std::string, boost::regex > types_
Type validators.
key_map::const_iterator const_key_iterator
std::map< const config *, message_list > message_map
static void missing_tag_error(const std::string &file, int line, const std::string &name, int n, const std::string &parent, bool flag_exception)
std::pair< const_key_iterator, const_key_iterator > all_const_key_iterators
class_key is used to save the information about one key.
bool config_read_
Shows, if validator is intialized with schema file;.
class_tag root_
Root of schema information.
std::map< std::string, preproc_define > preproc_map
One of the realizations of serialization/validator.hpp abstract validator.
void expand_all(class_tag &root)
Calls the expansion on each child.
static void extra_key_error(const std::string &file, int line, const std::string &tag, const std::string &key, bool flag_exception)
std::stack< message_map > cache_
Caches error messages.
static void missing_key_error(const std::string &file, int line, const std::string &tag, const std::string &key, bool flag_exception)
static std::string at(const std::string &file, int line)
static std::string sub(const std::string &s)
Private function to surround an argument with brackets.
schema_validator(const std::string &filename)
Initializes validator from file.
bool strict_validation_enabled
GLsizei const GLfloat * value
static void print_output(const std::string &message, bool flag_exception=false)
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 rea...
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.
std::map< std::string, counter > cnt_map
Counters are mapped by tag name.
bool read_config_file(const std::string &filename)
Reads config from input.
std::stack< const class_tag * > stack_
Declarations for File-IO.
void read(config &cfg, std::istream &in, abstract_validator *validator)
GLuint const GLchar * name
const attribute_value * get(const std::string &key) const
Returns a pointer to the attribute with the given key or nullptr if it does not exist.
std::istream * preprocess_file(std::string const &fname, preproc_map *defines)
Standard logging facilities (interface).
GLsizei GLenum GLuint GLuint GLsizei char * message
std::pair< const_tag_iterator, const_tag_iterator > all_const_tag_iterators
virtual ~schema_validator()
A config object defines a single node in a WML file, with access to child nodes.
Helper class, don't construct this directly.
static lg::log_domain log_validation("validation")
GLsizei const GLcharARB ** string
void print(message_info &)
Stores information about tag.
tag_map::const_iterator const_tag_iterator
const std::string & get_type() const
static void extra_tag_error(const std::string &file, int line, const std::string &name, int n, const std::string &parent, bool flag_exception)