00001 /* $Id: error_container.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 /** 00017 * @file 00018 * This file contains object "error_container", which are used to store error 00019 * messages while annotation parsing. 00020 * Also the another part of his job is to create GCC:styled error messages. 00021 */ 00022 00023 #ifndef TOOLS_ERROR_CONTAINER_HPP_INCLUDED 00024 #define TOOLS_ERROR_CONTAINER_HPP_INCLUDED 00025 00026 #include <iostream> 00027 #include <map> 00028 #include <sstream> 00029 #include <string> 00030 #include <vector> 00031 00032 namespace schema_validation{ 00033 /** 00034 * Container of errors, which are generated while schema generator tool 00035 * is parsing source files. 00036 * These errors are collected here, to be print on screen after parsing. 00037 */ 00038 class class_error_container{ 00039 public: 00040 class_error_container() 00041 : list_(),types_(),links_() 00042 { 00043 } 00044 00045 /** 00046 *Puts simple error message in container 00047 * @param message Message to print. 00048 */ 00049 void add_simple_error(const std::string & message); 00050 00051 /** 00052 * Generate and put GCC-style error message about error read file error 00053 * @param file Filename 00054 * @param line Number of line with error 00055 */ 00056 void add_read_error(const std::string & file,int line); 00057 00058 /** 00059 * Generate and put GCC-style error message about annotation block 00060 * somebody missed to close 00061 * @param file Filename 00062 * @param line Number of line with error 00063 * @param name Name of open block 00064 */ 00065 void add_opened_entity_error(const std::string & file,int line, 00066 const std::string & name); 00067 00068 /** 00069 * Generate and put GCC-style error message about closing block 00070 * that wasn't opened 00071 * @param file Filename 00072 * @param line Number of line with error 00073 * @param name of block 00074 */ 00075 void add_unopened_entity_error(const std::string & file,int line, 00076 const std::string & name); 00077 00078 /** 00079 * Generate and put GCC-style error message about opening parent block 00080 * before before closing previous block 00081 * @param file Filename 00082 * @param line Number with error 00083 * @param first Name of open parent 00084 * @param second Name of parent is opening 00085 */ 00086 void add_second_parent_error( 00087 const std::string & file,int line, const std::string & first, 00088 const std::string & second); 00089 00090 /** 00091 * Generate and put GCC-style error message about tag without parent 00092 * @param file Filename 00093 * @param line Number with error 00094 * @param name Name of tag 00095 */ 00096 void add_orphan_error(const std::string & file,int line, 00097 const std::string & name); 00098 /** 00099 * Generate and put GCC-style error message about wrong type value 00100 * @param file Filename 00101 * @param line Number with error 00102 * @param name Name of type 00103 * @param value Name of value 00104 */ 00105 void wrong_type_error(const std::string & file,int line, 00106 const std::string & name,const std::string & value); 00107 /** 00108 * Generate and put GCC-style error message about unknown type to type cache 00109 * @param file Filename 00110 * @param line Number with error 00111 * @param name Name of type 00112 */ 00113 void add_type_error(const std::string & file,int line, 00114 const std::string & type); 00115 /** 00116 * Clears type cache 00117 * @param name Name of type 00118 */ 00119 void remove_type_errors(const std::string & type); 00120 /** 00121 * Generate and put GCC-style error message about overriding type 00122 * Overriding means that that type was defined somewhere else, 00123 * and it's old value is lost. 00124 * @param file Filename 00125 * @param line Number of line with error 00126 * @param name Name of type 00127 */ 00128 void overriding_type_error(const std::string & file,int line, 00129 const std::string & type); 00130 00131 /** 00132 * Generate and put GCC-style error message about failed link to link cache 00133 * @param file Filename 00134 * @param line Number of line with error 00135 * @param name Name of link 00136 */ 00137 void add_link_error(const std::string & file,int line, 00138 const std::string & link); 00139 /** 00140 * Clears link cache 00141 * @param name Name of link 00142 */ 00143 void remove_link_errors(const std::string & link); 00144 00145 /** 00146 * Prints errors to output stream 00147 * @param s Output 00148 */ 00149 void print_errors(std::ostream & s) const; 00150 00151 /** Checks, if container is empty.*/ 00152 bool is_empty() const { 00153 return list_.empty() && types_.empty() && links_.empty(); 00154 } 00155 private: 00156 /** Container to store error messages.*/ 00157 std::vector<std::string> list_; 00158 /** 00159 * Container to cache type errors. 00160 * Types are checked while keys are read. 00161 * There is a possibility to have unknown type error just because file with 00162 * it desription haven't been parsed yet. 00163 * So every type warning adds to cache. 00164 * When sourseparser finds new type, it clears that warning list 00165 */ 00166 struct error_cache_element{ 00167 std::string file; 00168 int line; 00169 std::string name; 00170 error_cache_element(const std::string &f,int l,const std::string &n): 00171 file(f),line(l),name(n){} 00172 }; 00173 00174 typedef std::map<std::string, 00175 std::vector<error_cache_element> > error_cache_map; 00176 error_cache_map types_; 00177 error_cache_map links_; 00178 }; 00179 00180 00181 }//namespace schema_generator 00182 #endif // TOOLS_ERROR_CONTAINER_HPP_INCLUDED
| Generated by doxygen 1.7.1 on Thu May 24 2012 01:02:54 for The Battle for Wesnoth | Gna! | Forum | Wiki | CIA | devdocs |