00001 /* $Id: validator.hpp 52533 2012-01-07 02:35:17Z shadowmaster $ */ 00002 /* 00003 Copyright (C) 2011 - 2012 by Sytyi Nick <nsytyi@gmail.com> 00004 Part of the Battle for Wesnoth Project http://www.wesnoth.org/ 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY. 00012 00013 See the COPYING file for more details. 00014 */ 00015 /** 00016 * @file validator.hpp 00017 * This file contains information about validation abstract level interface. 00018 */ 00019 00020 #ifndef SERIALIZATION_VALIDATOR_HPP_INCLUDED 00021 #define SERIALIZATION_VALIDATOR_HPP_INCLUDED 00022 00023 #include "game_errors.hpp" 00024 00025 #include <string> 00026 00027 class config; 00028 00029 extern bool strict_validation_enabled; 00030 00031 /** 00032 * @class abstract_validator 00033 * Used in parsing config file. @ref parser.cpp 00034 * Contains virtual methods, which are called by parser 00035 * and take information about config to be validated 00036 */ 00037 class abstract_validator 00038 { 00039 public: 00040 /** 00041 * Constructor of validator can throw validator::error 00042 * @throws abstract_validator::error 00043 */ 00044 abstract_validator(){} 00045 00046 virtual ~abstract_validator(){} 00047 /** 00048 * Is called when parser opens tag. 00049 * @param name Name of tag 00050 * @param start_line Line in file 00051 * @param file Name of file 00052 */ 00053 virtual void open_tag(const std::string & name, 00054 int start_line, 00055 const std::string &file, 00056 bool addittion = false) = 0; 00057 /** 00058 * As far as parser is built on stack, some realizations can store stack 00059 * too. So they need to know if tag was closed. 00060 */ 00061 virtual void close_tag() = 0; 00062 /** 00063 * Validates config. Checks if all mandatory elements are present. 00064 * What exactly is validated depends on validator realization 00065 * @param cfg Config to be validated. 00066 * @param name Name of tag 00067 * @param start_line Line in file 00068 * @param file Name of file 00069 */ 00070 virtual void validate(const config & cfg, 00071 const std::string & name, 00072 int start_line, 00073 const std::string &file) = 0; 00074 /** 00075 * Checks if key is allowed and if its value is valid 00076 * What exactly is validated depends on validator realization 00077 * @param cfg Config to be validated. 00078 * @param name Name of tag 00079 * @param start_line Line in file 00080 * @param file Name of file 00081 */ 00082 00083 virtual void validate_key(const config & cfg, 00084 const std::string & name, 00085 const std::string & value, 00086 int start_line, 00087 const std::string &file) = 0; 00088 /** 00089 * @struct error 00090 * Used to manage with not initialized validators 00091 * Supposed to be thrown from the constructor 00092 */ 00093 struct error : public game::error { 00094 error(const std::string& message) : game::error(message) {} 00095 }; 00096 }; 00097 #endif // SERIALIZATION_VALIDATOR_HPP_INCLUDED
| Generated by doxygen 1.7.1 on Fri May 25 2012 01:03:09 for The Battle for Wesnoth | Gna! | Forum | Wiki | CIA | devdocs |