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

#include <schema_validator.hpp>

Inheritance diagram for schema_validation::schema_self_validator:

Classes

struct  reference
 

Public Member Functions

 schema_self_validator ()
 
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 schema_validation::schema_validator
virtual ~schema_validator ()
 
 schema_validator (const std::string &filename, bool validate_schema=false)
 Initializes validator from file. More...
 
void set_create_exceptions (bool value)
 
- Public Member Functions inherited from abstract_validator
 abstract_validator (const std::string &name)
 Constructor of validator can throw validator::error. More...
 
virtual ~abstract_validator ()
 

Private Types

enum  {
  WRONG_TYPE = NEXT_ERROR, WRONG_PATH, DUPLICATE_TAG, DUPLICATE_KEY,
  NEXT_ERROR
}
 

Private Member Functions

std::string current_path () const
 
bool tag_path_exists (const config &cfg, const reference &ref)
 
void check_for_duplicates (const std::string &name, std::vector< std::string > &seen, const config &cfg, message_type type, const std::string &file, int line, const std::string &tag)
 
void print (message_info &message) override
 

Static Private Member Functions

static bool name_matches (const std::string &pattern, const std::string &name)
 

Private Attributes

std::set< std::string > defined_types_
 
std::set< std::string > defined_tag_paths_
 
std::vector< referencereferenced_types_
 
std::vector< referencereferenced_tag_paths_
 
std::stack< std::string > tag_stack_
 
std::map< std::string, std::string > links_
 
std::multimap< std::string, std::string > derivations_
 
int type_nesting_
 
int condition_nesting_
 

Additional Inherited Members

- Public Attributes inherited from abstract_validator
const std::string name_
 
- Protected Types inherited from schema_validation::schema_validator
enum  {
  WRONG_TAG, EXTRA_TAG, MISSING_TAG, EXTRA_KEY,
  MISSING_KEY, WRONG_VALUE, NEXT_ERROR
}
 
using message_type = int
 
- Protected Member Functions inherited from schema_validation::schema_validator
template<typename... T>
void queue_message (const config &cfg, T &&... args)
 
const wml_tagactive_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 inherited from schema_validation::schema_validator
bool create_exceptions_
 Controls the way to print errors. More...
 

Detailed Description

Definition at line 164 of file schema_validator.hpp.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private
Enumerator
WRONG_TYPE 
WRONG_PATH 
DUPLICATE_TAG 
DUPLICATE_KEY 
NEXT_ERROR 

Definition at line 198 of file schema_validator.hpp.

Constructor & Destructor Documentation

◆ schema_self_validator()

schema_validation::schema_self_validator::schema_self_validator ( )

Definition at line 409 of file schema_validator.cpp.

References defined_types_.

Member Function Documentation

◆ check_for_duplicates()

void schema_validation::schema_self_validator::check_for_duplicates ( const std::string &  name,
std::vector< std::string > &  seen,
const config cfg,
message_type  type,
const std::string &  file,
int  line,
const std::string &  tag 
)
private

◆ close_tag()

void schema_validation::schema_self_validator::close_tag ( )
overridevirtual

As far as parser is built on stack, some realizations can store stack too.

So they need to know if tag was closed.

Reimplemented from schema_validation::schema_validator.

Definition at line 435 of file schema_validator.cpp.

References schema_validation::schema_validator::active_tag(), schema_validation::schema_validator::close_tag(), condition_nesting_, schema_validation::wml_tag::get_name(), schema_validation::schema_validator::have_active_tag(), tag_stack_, and type_nesting_.

◆ current_path()

std::string schema_validation::schema_self_validator::current_path ( ) const
private

Definition at line 600 of file schema_validator.cpp.

References utils::join(), game_config::path, and tag_stack_.

Referenced by validate_key().

◆ name_matches()

bool schema_validation::schema_self_validator::name_matches ( const std::string &  pattern,
const std::string &  name 
)
staticprivate

Definition at line 488 of file schema_validator.cpp.

References utils::split(), and utils::wildcard_string_match().

Referenced by check_for_duplicates().

◆ open_tag()

void schema_validation::schema_self_validator::open_tag ( const std::string &  name,
const config parent,
int  start_line = 0,
const std::string &  file = "",
bool  addition = false 
)
overridevirtual

Is called when parser opens tag.

Parameters
nameName of tag
parentThe parent config
start_lineLine in file
fileName of file
addition

Reimplemented from schema_validation::schema_validator.

Definition at line 418 of file schema_validator.cpp.

References condition_nesting_, schema_validation::schema_validator::open_tag(), tag_stack_, and type_nesting_.

◆ print()

void schema_validation::schema_self_validator::print ( message_info message)
overrideprivatevirtual

◆ tag_path_exists()

bool schema_validation::schema_self_validator::tag_path_exists ( const config cfg,
const reference ref 
)
private

◆ validate()

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

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

Reimplemented from schema_validation::schema_validator.

Definition at line 509 of file schema_validator.cpp.

References config::all_children_range(), check_for_duplicates(), defined_tag_paths_, defined_types_, dummy, DUPLICATE_KEY, DUPLICATE_TAG, schema_validation::schema_self_validator::reference::match(), schema_validation::schema_validator::queue_message(), referenced_tag_paths_, referenced_types_, sort(), tag_path_exists(), type_nesting_, schema_validation::schema_validator::validate(), WRONG_PATH, and WRONG_TYPE.

◆ validate_key()

void schema_validation::schema_self_validator::validate_key ( const config cfg,
const std::string &  name,
const config_attribute_value value,
int  start_line,
const std::string &  file 
)
overridevirtual

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
valueThe key's value
start_lineLine in file
fileName of file

Reimplemented from schema_validation::schema_validator.

Definition at line 573 of file schema_validator.cpp.

References schema_validation::schema_validator::active_tag(), condition_nesting_, current_path(), defined_tag_paths_, derivations_, schema_validation::wml_tag::get_name(), schema_validation::schema_validator::have_active_tag(), schema_validation::schema_validator::is_valid(), links_, referenced_tag_paths_, referenced_types_, utils::split(), config_attribute_value::str(), tag_stack_, and schema_validation::schema_validator::validate_key().

Member Data Documentation

◆ condition_nesting_

int schema_validation::schema_self_validator::condition_nesting_
private

Definition at line 192 of file schema_validator.hpp.

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

◆ defined_tag_paths_

std::set<std::string> schema_validation::schema_self_validator::defined_tag_paths_
private

Definition at line 187 of file schema_validator.hpp.

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

◆ defined_types_

std::set<std::string> schema_validation::schema_self_validator::defined_types_
private

Definition at line 187 of file schema_validator.hpp.

Referenced by schema_self_validator(), and validate().

◆ derivations_

std::multimap<std::string, std::string> schema_validation::schema_self_validator::derivations_
private

Definition at line 191 of file schema_validator.hpp.

Referenced by tag_path_exists(), and validate_key().

◆ links_

std::map<std::string, std::string> schema_validation::schema_self_validator::links_
private

Definition at line 190 of file schema_validator.hpp.

Referenced by tag_path_exists(), and validate_key().

◆ referenced_tag_paths_

std::vector<reference> schema_validation::schema_self_validator::referenced_tag_paths_
private

Definition at line 188 of file schema_validator.hpp.

Referenced by validate(), and validate_key().

◆ referenced_types_

std::vector<reference> schema_validation::schema_self_validator::referenced_types_
private

Definition at line 188 of file schema_validator.hpp.

Referenced by validate(), and validate_key().

◆ tag_stack_

std::stack<std::string> schema_validation::schema_self_validator::tag_stack_
private

Definition at line 189 of file schema_validator.hpp.

Referenced by close_tag(), current_path(), open_tag(), and validate_key().

◆ type_nesting_

int schema_validation::schema_self_validator::type_nesting_
private

Definition at line 192 of file schema_validator.hpp.

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


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