aGrUM  0.14.2
errorsContainer.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
3  * {prenom.nom}_at_lip6.fr *
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  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
20 
27 #ifndef GUM_ERRORS_CONTAINERS_H
28 #define GUM_ERRORS_CONTAINERS_H
29 
30 #include <fstream>
31 #include <iostream>
32 #include <vector>
33 
34 #include <agrum/agrum.h>
35 
36 #include <agrum/core/cocoR/common.h>
37 
38 namespace gum {
39 
48  class ParseError {
49  public:
50  // ============================================================================
52  // ============================================================================
54 
61  ParseError(bool is_error, const std::string& msg, Idx line);
62 
71  ParseError(bool is_error,
72  const std::string& msg,
73  const std::string& filename,
74  Idx line,
75  Idx col = 0);
76 
86  ParseError(bool is_error,
87  const std::string& msg,
88  const std::string& filename,
89  const std::string& code,
90  Idx line,
91  Idx col = 0);
92 
97  ParseError(const ParseError& cont);
98 
100  // ============================================================================
102  // ============================================================================
104 
110  ParseError operator=(const ParseError& cont);
111 
113  // ============================================================================
115  // ============================================================================
117 
119  bool is_error;
120 
123 
126 
128  std::string msg;
129 
131  std::string filename;
132 
134  mutable std::string code; // default ""
135 
140  std::string toString() const;
141 
148  std::string toElegantString() const;
149 
151  };
152 
161  mutable std::vector< ParseError > errors;
162 
163  public:
166 
167  // Number of warnings detected.
169 
170  // ============================================================================
172  // ============================================================================
174 
178  ErrorsContainer();
179 
184  ErrorsContainer(const ErrorsContainer& cont);
185 
187  // ============================================================================
189  // ============================================================================
191 
196  void add(ParseError error);
197 
204  ParseError error(Idx i) const;
205 
211  ParseError last() const;
212 
220  void addError(const std::string& msg,
221  const std::string& filename,
222  Idx line,
223  Idx col);
224 
232  void addWarning(const std::string& msg,
233  const std::string& filename,
234  Idx line,
235  Idx col);
236 
242  void addException(const std::string& msg, const std::string& filename);
243 
248  Size count() const;
249 
254  void syntheticResults(std::ostream& o) const;
255 
260  void simpleErrors(std::ostream& o) const;
261 
266  void simpleErrorsAndWarnings(std::ostream& o) const;
267 
272  void elegantErrors(std::ostream& o) const;
273 
278  void elegantErrorsAndWarnings(std::ostream& o) const;
279 
281  // ============================================================================
283  // ============================================================================
285 
293  void
294  Error(const std::wstring& filename, Idx line, Idx col, const wchar_t* msg);
295 
303  void Warning(const std::wstring& filename,
304  Idx line,
305  Idx col,
306  const wchar_t* msg);
307 
313  void Exception(const std::wstring& filename, const wchar_t* msg);
314 
316  // ============================================================================
318  // ============================================================================
320 
326  ErrorsContainer operator+(const ErrorsContainer& cont) const;
327 
334 
341  ErrorsContainer operator+=(const ErrorsContainer& cont);
342 
344 
345  }; // ErrorsContainer
346 
347 } // namespace gum
348 
350 #ifndef GUM_NO_INLINE
352 #endif /* GUM_NO_INLINE */
353 
354 #endif // GUM_ERRORS_CONTAINERS_H
std::string msg
The gum::ParseError message.
Inlined implementation of the basic methods of ErrorsContainer.
Formula operator+(const Formula &a, const Formula &b)
Definition: formula_inl.h:459
Size error_count
Number of errors detected.
std::string filename
The file of this gum::ParseError, default is "".
std::string code
The code of this gum::ParseError, default is "".
std::vector< ParseError > errors
The list of gum::ParseError contained in this gum::ErrorsContainer.
This class is used to represent parsing errors for the different parser implemented in aGrUM...
ParseError(bool is_error, const std::string &msg, Idx line)
Class constructor.
This class is used contain and manipulate gum::ParseError.
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
std::string toString() const
Return a std::string representation of this gum::ParseError.
std::string toElegantString() const
Return an elegant std::string representation of this gum::ParseError.
bool is_error
If false, this gum::ParseError is a warning.
Idx line
The line of this gum::ParseError.
ParseError operator=(const ParseError &cont)
Copy operator.
Base class for all aGrUM&#39;s exceptions.
Definition: exceptions.h:103
Size Idx
Type for indexes.
Definition: types.h:50
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45
Idx column
The column of this gum::ParseError, default is 0.