aGrUM  0.14.2
errorsContainer_inl.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  ***************************************************************************/
26 // to ease automatic parsers
28 
29 namespace gum {
30 
31  INLINE
32  void ErrorsContainer::Error(const std::wstring& filename,
33  Idx line,
34  Idx col,
35  const wchar_t* msg) {
36  add(ParseError(true, narrow(std::wstring(msg)), narrow(filename), line, col));
37  }
38 
39  INLINE
40  void ErrorsContainer::Warning(const std::wstring& filename,
41  Idx line,
42  Idx col,
43  const wchar_t* msg) {
44  add(ParseError(false, narrow(std::wstring(msg)), narrow(filename), line, col));
45  }
46 
47  INLINE
48  void ErrorsContainer::Exception(const std::wstring& filename,
49  const wchar_t* msg) {
51  true, "Exception : " + narrow(std::wstring(msg)), narrow(filename), 0, 0));
52  }
53 
54  INLINE
56  errors.push_back(error);
57 
58  if (error.is_error)
59  error_count++;
60  else
61  warning_count++;
62  }
63 
64  INLINE
65  void ErrorsContainer::addError(const std::string& msg,
66  const std::string& filename,
67  Idx line,
68  Idx col) {
69  add(ParseError(true, msg, filename, line, col));
70  }
71 
72  INLINE
73  void ErrorsContainer::addWarning(const std::string& msg,
74  const std::string& filename,
75  Idx line,
76  Idx col) {
77  add(ParseError(false, msg, filename, line, col));
78  }
79 
80  INLINE
81  void ErrorsContainer::addException(const std::string& msg,
82  const std::string& filename) {
83  add(ParseError(true, msg, filename, 0, 0));
84  }
85 
86  INLINE
88 
89  INLINE
90  void ErrorsContainer::syntheticResults(std::ostream& o) const {
91  o << "Errors : " << error_count << std::endl;
92  o << "Warnings : " << warning_count << std::endl;
93  }
94 
95 } // namespace gum
Errors container (at least) for parser.
void addWarning(const std::string &msg, const std::string &filename, Idx line, Idx col)
Adds a warning.
Size count() const
Returns the number of errors and warnings.
Size error_count
Number of errors detected.
void Exception(const std::wstring &filename, const wchar_t *msg)
For adding exceptions.
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...
void syntheticResults(std::ostream &o) const
Print errors on output stream.
void add(ParseError error)
Add an error object to the container.
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
bool is_error
If false, this gum::ParseError is a warning.
std::string narrow(const std::wstring &str)
Cast a std::wstring into a std::string.
void Error(const std::wstring &filename, Idx line, Idx col, const wchar_t *msg)
For adding errors.
Size Idx
Type for indexes.
Definition: types.h:50
ParseError error(Idx i) const
Returns the i-th error.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45
void Warning(const std::wstring &filename, Idx line, Idx col, const wchar_t *msg)
For adding warnings.
void addError(const std::string &msg, const std::string &filename, Idx line, Idx col)
Adds an error.
void addException(const std::string &msg, const std::string &filename)
Add an exception.