The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
error_container.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 /**
16  * @file
17  * This file contains object "error_container", which are used to store error
18  * messages while annotation parsing.
19  * Also the another part of his job is to create GCC:styled error messages.
20  */
21 
22 #ifndef TOOLS_ERROR_CONTAINER_HPP_INCLUDED
23 #define TOOLS_ERROR_CONTAINER_HPP_INCLUDED
24 
25 #include <iostream>
26 #include <map>
27 #include <sstream>
28 #include <string>
29 #include <vector>
30 
31 namespace schema_validation{
32 /**
33  * Container of errors, which are generated while schema generator tool
34  * is parsing source files.
35  * These errors are collected here, to be print on screen after parsing.
36  */
38 public:
40  : list_(),types_(),links_()
41  {
42  }
43 
44  /**
45  *Puts simple error message in container
46  * @param message Message to print.
47  */
48  void add_simple_error(const std::string & message);
49 
50  /**
51  * Generate and put GCC-style error message about error read file error
52  * @param file Filename
53  * @param line Number of line with error
54  */
55  void add_read_error(const std::string & file,int line);
56 
57  /**
58  * Generate and put GCC-style error message about annotation block
59  * somebody missed to close
60  * @param file Filename
61  * @param line Number of line with error
62  * @param name Name of open block
63  */
64  void add_opened_entity_error(const std::string & file,int line,
65  const std::string & name);
66 
67  /**
68  * Generate and put GCC-style error message about closing block
69  * that wasn't opened
70  * @param file Filename
71  * @param line Number of line with error
72  * @param name of block
73  */
74  void add_unopened_entity_error(const std::string & file,int line,
75  const std::string & name);
76 
77  /**
78  * Generate and put GCC-style error message about opening parent block
79  * before before closing previous block
80  * @param file Filename
81  * @param line Number with error
82  * @param first Name of open parent
83  * @param second Name of parent is opening
84  */
86  const std::string & file,int line, const std::string & first,
87  const std::string & second);
88 
89  /**
90  * Generate and put GCC-style error message about tag without parent
91  * @param file Filename
92  * @param line Number with error
93  * @param name Name of tag
94  */
95  void add_orphan_error(const std::string & file,int line,
96  const std::string & name);
97  /**
98  * Generate and put GCC-style error message about wrong type value
99  * @param file Filename
100  * @param line Number with error
101  * @param name Name of type
102  * @param value Name of value
103  */
104  void wrong_type_error(const std::string & file,int line,
105  const std::string & name,const std::string & value);
106  /**
107  * Generate and put GCC-style error message about unknown type to type cache
108  * @param file Filename
109  * @param line Number with error
110  * @param type Name of type
111  */
112  void add_type_error(const std::string & file,int line,
113  const std::string & type);
114  /**
115  * Clears type cache
116  * @param type Name of type
117  */
118  void remove_type_errors(const std::string & type);
119  /**
120  * Generate and put GCC-style error message about overriding type
121  * Overriding means that that type was defined somewhere else,
122  * and it's old value is lost.
123  * @param file Filename
124  * @param line Number of line with error
125  * @param type Name of type
126  */
127  void overriding_type_error(const std::string & file,int line,
128  const std::string & type);
129 
130  /**
131  * Generate and put GCC-style error message about failed link to link cache
132  * @param file Filename
133  * @param line Number of line with error
134  * @param link Name of link
135  */
136  void add_link_error(const std::string & file,int line,
137  const std::string & link);
138  /**
139  * Clears link cache
140  * @param link Name of link
141  */
142  void remove_link_errors(const std::string & link);
143 
144  /**
145  * Prints errors to output stream
146  * @param s Output
147  */
148  void print_errors(std::ostream & s) const;
149 
150  /** Checks, if container is empty.*/
151  bool is_empty() const {
152  return list_.empty() && types_.empty() && links_.empty();
153  }
154 private:
155  /** Container to store error messages.*/
156  std::vector<std::string> list_;
157  /**
158  * Container to cache type errors.
159  * Types are checked while keys are read.
160  * There is a possibility to have unknown type error just because file with
161  * it desription haven't been parsed yet.
162  * So every type warning adds to cache.
163  * When sourseparser finds new type, it clears that warning list
164  */
167  int line;
170  file(f),line(l),name(n){}
171  };
172 
173  typedef std::map<std::string,
174  std::vector<error_cache_element> > error_cache_map;
175  error_cache_map types_;
176  error_cache_map links_;
177 };
178 
179 
180 }//namespace schema_generator
181 #endif // TOOLS_ERROR_CONTAINER_HPP_INCLUDED
void remove_link_errors(const std::string &link)
Clears link cache.
void add_orphan_error(const std::string &file, int line, const std::string &name)
Generate and put GCC-style error message about tag without parent.
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1221
void add_second_parent_error(const std::string &file, int line, const std::string &first, const std::string &second)
Generate and put GCC-style error message about opening parent block before before closing previous bl...
GLdouble l
Definition: glew.h:6966
GLsizei const GLfloat * value
Definition: glew.h:1817
void add_link_error(const std::string &file, int line, const std::string &link)
Generate and put GCC-style error message about failed link to link cache.
void add_opened_entity_error(const std::string &file, int line, const std::string &name)
Generate and put GCC-style error message about annotation block somebody missed to close...
void add_type_error(const std::string &file, int line, const std::string &type)
Generate and put GCC-style error message about unknown type to type cache.
void overriding_type_error(const std::string &file, int line, const std::string &type)
Generate and put GCC-style error message about overriding type Overriding means that that type was de...
void add_simple_error(const std::string &message)
Puts simple error message in container.
std::map< std::string, std::vector< error_cache_element > > error_cache_map
void remove_type_errors(const std::string &type)
Clears type cache.
bool is_empty() const
Checks, if container is empty.
Container of errors, which are generated while schema generator tool is parsing source files...
void print_errors(std::ostream &s) const
Prints errors to output stream.
GLuint const GLchar * name
Definition: glew.h:1782
std::vector< std::string > list_
Container to store error messages.
GLclampd n
Definition: glew.h:5903
GLint * first
Definition: glew.h:1496
GLsizei GLenum GLuint GLuint GLsizei char * message
Definition: glew.h:2499
void wrong_type_error(const std::string &file, int line, const std::string &name, const std::string &value)
Generate and put GCC-style error message about wrong type value.
GLdouble s
Definition: glew.h:1358
void add_unopened_entity_error(const std::string &file, int line, const std::string &name)
Generate and put GCC-style error message about closing block that wasn't opened.
GLsizei const GLcharARB ** string
Definition: glew.h:4503
error_cache_element(const std::string &f, int l, const std::string &n)
GLclampf f
Definition: glew.h:3024
void add_read_error(const std::string &file, int line)
Generate and put GCC-style error message about error read file error.