The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
validator.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2011 - 2016 by Sytyi Nick <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 /**
15  * @file validator.hpp
16  * This file contains information about validation abstract level interface.
17  */
18 
19 #ifndef SERIALIZATION_VALIDATOR_HPP_INCLUDED
20 #define SERIALIZATION_VALIDATOR_HPP_INCLUDED
21 
22 #include "game_errors.hpp"
23 
24 #include <string>
25 
26 class config;
27 
28 extern bool strict_validation_enabled;
29 
30 /**
31  * @class abstract_validator
32  * Used in parsing config file. @ref parser.cpp
33  * Contains virtual methods, which are called by parser
34  * and take information about config to be validated
35  */
37 {
38 public:
39  /**
40  * Constructor of validator can throw validator::error
41  * @throws abstract_validator::error
42  */
44 
45  virtual ~abstract_validator(){}
46  /**
47  * Is called when parser opens tag.
48  * @param name Name of tag
49  * @param start_line Line in file
50  * @param file Name of file
51  */
52  virtual void open_tag(const std::string & name,
53  int start_line,
54  const std::string &file,
55  bool addittion = false) = 0;
56  /**
57  * As far as parser is built on stack, some realizations can store stack
58  * too. So they need to know if tag was closed.
59  */
60  virtual void close_tag() = 0;
61  /**
62  * Validates config. Checks if all mandatory elements are present.
63  * What exactly is validated depends on validator realization
64  * @param cfg Config to be validated.
65  * @param name Name of tag
66  * @param start_line Line in file
67  * @param file Name of file
68  */
69  virtual void validate(const config & cfg,
70  const std::string & name,
71  int start_line,
72  const std::string &file) = 0;
73  /**
74  * Checks if key is allowed and if its value is valid
75  * What exactly is validated depends on validator realization
76  * @param cfg Config to be validated.
77  * @param name Name of tag
78  * @param start_line Line in file
79  * @param file Name of file
80  */
81 
82  virtual void validate_key(const config & cfg,
83  const std::string & name,
84  const std::string & value,
85  int start_line,
86  const std::string &file) = 0;
87  /**
88  * @struct error
89  * Used to manage with not initialized validators
90  * Supposed to be thrown from the constructor
91  */
92  struct error : public game::error {
93  error(const std::string& message) : game::error(message) {}
94  };
95 };
96 #endif // SERIALIZATION_VALIDATOR_HPP_INCLUDED
abstract_validator()
Constructor of validator can throw validator::error.
Definition: validator.hpp:43
bool strict_validation_enabled
Definition: validator.cpp:19
virtual void open_tag(const std::string &name, int start_line, const std::string &file, bool addittion=false)=0
Is called when parser opens tag.
virtual void close_tag()=0
As far as parser is built on stack, some realizations can store stack too.
Used in parsing config file.
Definition: validator.hpp:36
virtual ~abstract_validator()
Definition: validator.hpp:45
Used to manage with not initialized validators Supposed to be thrown from the constructor.
Definition: validator.hpp:92
GLsizei const GLfloat * value
Definition: glew.h:1817
virtual void validate_key(const config &cfg, const std::string &name, const std::string &value, int start_line, const std::string &file)=0
Checks if key is allowed and if its value is valid What exactly is validated depends on validator rea...
GLuint const GLchar * name
Definition: glew.h:1782
Base class for all the errors encountered by the engine.
Definition: exceptions.hpp:27
virtual void validate(const config &cfg, const std::string &name, int start_line, const std::string &file)=0
Validates config.
GLsizei GLenum GLuint GLuint GLsizei char * message
Definition: glew.h:2499
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
GLsizei const GLcharARB ** string
Definition: glew.h:4503
error(const std::string &message)
Definition: validator.hpp:93