The Battle for Wesnoth  1.15.0-dev
Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
schema_validation::schema_validator Class Reference

Realization of serialization/validator.hpp abstract validator. More...

#include <schema_validator.hpp>

Inheritance diagram for schema_validation::schema_validator:
Inheritance graph

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, countercnt_map
 Counters are mapped by tag name. More...
 
typedef std::stack< cnt_mapcnt_stack
 And counter maps are organize in stack. More...
 
typedef std::deque< message_infomessage_list
 
typedef std::map< const config *, message_listmessage_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 initialized 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_mapcache_
 Caches error messages. More...
 
std::map< std::string, boost::regex > types_
 Type validators. More...
 

Detailed Description

Realization of serialization/validator.hpp abstract validator.

Based on stack. Uses some stacks to store different info.

Definition at line 40 of file schema_validator.hpp.

Member Typedef Documentation

◆ cnt_map

typedef std::map<std::string, counter> schema_validation::schema_validator::cnt_map
private

Counters are mapped by tag name.

Definition at line 79 of file schema_validator.hpp.

◆ cnt_stack

And counter maps are organize in stack.

Definition at line 82 of file schema_validator.hpp.

◆ message_list

Definition at line 124 of file schema_validator.hpp.

◆ message_map

Definition at line 125 of file schema_validator.hpp.

Member Enumeration Documentation

◆ message_type

Enumerator
WRONG_TAG 
EXTRA_TAG 
MISSING_TAG 
EXTRA_KEY 
MISSING_KEY 
WRONG_VALUE 

Definition at line 84 of file schema_validator.hpp.

Constructor & Destructor Documentation

◆ ~schema_validator()

schema_validation::schema_validator::~schema_validator ( )
virtual

Definition at line 118 of file schema_validator.cpp.

◆ schema_validator()

schema_validation::schema_validator::schema_validator ( const std::string &  filename)

Initializes validator from file.

Throws abstract_validator::error if any error.

Definition at line 122 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_.

Member Function Documentation

◆ close_tag()

void schema_validation::schema_validator::close_tag ( )
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 209 of file schema_validator.cpp.

References counter_, and stack_.

Referenced by set_create_exceptions().

◆ open_tag()

void schema_validation::schema_validator::open_tag ( const std::string &  name,
int  start_line = 0,
const std::string &  file = "",
bool  addittion = false 
)
virtual

Is called when parser opens tag.

Parameters
nameName of tag
start_lineLine in file
fileName of file

Implements abstract_validator.

Definition at line 182 of file schema_validator.cpp.

References cache_, schema_validation::schema_validator::counter::cnt, counter_, create_exceptions_, root_, stack_, and schema_validation::wrong_tag_error().

Referenced by set_create_exceptions().

◆ print()

void schema_validation::schema_validator::print ( message_info el)
private

◆ read_config_file()

bool schema_validation::schema_validator::read_config_file ( const std::string &  filename)
private

◆ set_create_exceptions()

void schema_validation::schema_validator::set_create_exceptions ( bool  value)
inline

◆ validate()

void schema_validation::schema_validator::validate ( const config cfg,
const std::string &  name,
int  start_line,
const std::string &  file 
)
virtual

Validates config.

Checks if all mandatory elements are present. What exactly is validated depends on validator realization

Parameters
cfgConfig to be validated.
nameName of tag
start_lineLine in file
fileName of file

Implements abstract_validator.

Definition at line 216 of file schema_validator.cpp.

References cache_, config_read_, counter_, EXTRA_TAG, config::get(), MISSING_KEY, MISSING_TAG, print(), and stack_.

Referenced by set_create_exceptions().

◆ validate_key()

void schema_validation::schema_validator::validate_key ( const config cfg,
const std::string &  name,
const std::string &  value,
int  start_line,
const std::string &  file 
)
virtual

Checks if key is allowed and if its value is valid What exactly is validated depends on validator realization.

Parameters
cfgConfig to be validated.
nameName of tag
start_lineLine in file
fileName of file

Implements abstract_validator.

Definition at line 262 of file schema_validator.cpp.

References cache_, config_read_, EXTRA_KEY, schema_validation::class_key::get_type(), stack_, types_, and WRONG_VALUE.

Referenced by set_create_exceptions().

Member Data Documentation

◆ cache_

std::stack<message_map> schema_validation::schema_validator::cache_
private

Caches error messages.

Definition at line 147 of file schema_validator.hpp.

Referenced by open_tag(), schema_validator(), validate(), and validate_key().

◆ config_read_

bool schema_validation::schema_validator::config_read_
private

Shows, if validator is initialized with schema file.

Definition at line 133 of file schema_validator.hpp.

Referenced by read_config_file(), validate(), and validate_key().

◆ counter_

cnt_stack schema_validation::schema_validator::counter_
private

Contains number of children.

Definition at line 144 of file schema_validator.hpp.

Referenced by close_tag(), open_tag(), schema_validator(), and validate().

◆ create_exceptions_

bool schema_validation::schema_validator::create_exceptions_
private

Controls the way to print errors.

Definition at line 136 of file schema_validator.hpp.

Referenced by open_tag(), print(), and set_create_exceptions().

◆ root_

class_tag schema_validation::schema_validator::root_
private

Root of schema information.

Definition at line 139 of file schema_validator.hpp.

Referenced by open_tag(), read_config_file(), and schema_validator().

◆ stack_

std::stack<const class_tag*> schema_validation::schema_validator::stack_
private

Definition at line 141 of file schema_validator.hpp.

Referenced by close_tag(), open_tag(), schema_validator(), validate(), and validate_key().

◆ types_

std::map<std::string, boost::regex> schema_validation::schema_validator::types_
private

Type validators.

Definition at line 150 of file schema_validator.hpp.

Referenced by read_config_file(), and validate_key().


The documentation for this class was generated from the following files: