aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
errorsContainer.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2025 by *
5 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
6 * - Christophe GONZALES(_at_AMU) *
7 * *
8 * The aGrUM/pyAgrum library is free software; you can redistribute it *
9 * and/or modify it under the terms of either : *
10 * *
11 * - the GNU Lesser General Public License as published by *
12 * the Free Software Foundation, either version 3 of the License, *
13 * or (at your option) any later version, *
14 * - the MIT license (MIT), *
15 * - or both in dual license, as here. *
16 * *
17 * (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18 * *
19 * This aGrUM/pyAgrum library is distributed in the hope that it will be *
20 * useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26 * OTHER DEALINGS IN THE SOFTWARE. *
27 * *
28 * See LICENCES for more details. *
29 * *
30 * SPDX-FileCopyrightText: Copyright 2005-2025 *
31 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
32 * - Christophe GONZALES(_at_AMU) *
33 * SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34 * *
35 * Contact : info_at_agrum_dot_org *
36 * homepage : http://agrum.gitlab.io *
37 * gitlab : https://gitlab.com/agrumery/agrum *
38 * *
39 ****************************************************************************/
40
41
48#ifndef GUM_ERRORS_CONTAINERS_H
49#define GUM_ERRORS_CONTAINERS_H
50
51#include <fstream>
52#include <iostream>
53#include <vector>
54
55#include <agrum/agrum.h>
56
57#include <agrum/base/core/cocoR/common.h>
58
59namespace gum {
60
69 class ParseError {
70 public:
71 // ============================================================================
73 // ============================================================================
75
82 ParseError(bool is_error, const std::string& msg, Idx line);
83
93 const std::string& msg,
94 const std::string& filename,
95 Idx line,
96 Idx col = 0);
97
108 const std::string& msg,
109 const std::string& filename,
110 const std::string& code,
111 Idx line,
112 Idx col = 0);
113
118 ParseError(const ParseError& cont);
119
121 // ============================================================================
123 // ============================================================================
125
132
134 // ============================================================================
136 // ============================================================================
138
141
144
147
149 std::string msg;
150
152 std::string filename;
153
155 mutable std::string code; // default ""
156
161 std::string toString() const;
162
169 std::string toElegantString() const;
170
172 };
173
182 mutable std::vector< ParseError > errors;
183
184 public:
187
188 // Number of warnings detected.
190
191 // ============================================================================
193 // ============================================================================
195
200
206
208 // ============================================================================
210 // ============================================================================
212
217 void add(ParseError error);
218
226
233
241 void addError(const std::string& msg, const std::string& filename, Idx line, Idx col);
242
250 void addWarning(const std::string& msg, const std::string& filename, Idx line, Idx col);
251
257 void addException(const std::string& msg, const std::string& filename);
258
263 Size count() const;
264
269 void syntheticResults(std::ostream& o) const;
270
275 void simpleErrors(std::ostream& o) const;
276
281 void simpleErrorsAndWarnings(std::ostream& o) const;
282
287 void elegantErrors(std::ostream& o) const;
288
293 void elegantErrorsAndWarnings(std::ostream& o) const;
294
296 // ============================================================================
298 // ============================================================================
300
308 void Error(const std::wstring& filename, Idx line, Idx col, const wchar_t* msg);
309
317 void Warning(const std::wstring& filename, Idx line, Idx col, const wchar_t* msg);
318
324 void Exception(const std::wstring& filename, const wchar_t* msg);
325
327 // ============================================================================
329 // ============================================================================
331
338
345
353
355
356 }; // ErrorsContainer
357
358} // namespace gum
359
361#ifndef GUM_NO_INLINE
363#endif /* GUM_NO_INLINE */
364
365#endif // GUM_ERRORS_CONTAINERS_H
ParseError last() const
Returns the last added error.
Size count() const
Returns the number of errors and warnings.
ParseError error(Idx i) const
Returns the i-th error.
void addException(const std::string &msg, const std::string &filename)
Add an exception.
ErrorsContainer(const ErrorsContainer &cont)
Copy constructor.
ErrorsContainer()
Class Constructor.
ErrorsContainer operator+=(const ErrorsContainer &cont)
Add the content of a gum::ErrorsContainer to this gum::ErrorsContainer.
ErrorsContainer operator+(const ErrorsContainer &cont) const
Return the sum of two gum::ErrorsContainer.
void add(ParseError error)
Add an error object to the container.
void Error(const std::wstring &filename, Idx line, Idx col, const wchar_t *msg)
For adding errors.
Size error_count
Number of errors detected.
void addWarning(const std::string &msg, const std::string &filename, Idx line, Idx col)
Adds a warning.
void simpleErrorsAndWarnings(std::ostream &o) const
Print errors on output stream.
void Warning(const std::wstring &filename, Idx line, Idx col, const wchar_t *msg)
For adding warnings.
void Exception(const std::wstring &filename, const wchar_t *msg)
For adding exceptions.
void simpleErrors(std::ostream &o) const
Print errors on output stream.
void elegantErrorsAndWarnings(std::ostream &o) const
Print errors on output stream.
void addError(const std::string &msg, const std::string &filename, Idx line, Idx col)
Adds an error.
void syntheticResults(std::ostream &o) const
Print errors on output stream.
void elegantErrors(std::ostream &o) const
Print errors on output stream.
ErrorsContainer operator=(const ErrorsContainer &cont)
Copy Operator.
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.
std::string filename
The file of this gum::ParseError, default is "".
Idx column
The column of this gum::ParseError, default is 0.
std::string msg
The gum::ParseError message.
Idx line
The line of this gum::ParseError.
bool is_error
If false, this gum::ParseError is a warning.
std::string code
The code of this gum::ParseError, default is "".
ParseError operator=(const ParseError &cont)
Copy operator.
std::string toString() const
Return a std::string representation of this gum::ParseError.
ParseError(const ParseError &cont)
Copy constructor.
ParseError(bool is_error, const std::string &msg, const std::string &filename, Idx line, Idx col=0)
Class constructor.
ParseError(bool is_error, const std::string &msg, const std::string &filename, const std::string &code, Idx line, Idx col=0)
Class constructor.
std::string toElegantString() const
Return an elegant std::string representation of this gum::ParseError.
Inlined implementation of the basic methods of ErrorsContainer.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74
Size Idx
Type for indexes.
Definition types.h:79
gum is the global namespace for all aGrUM entities
Definition agrum.h:46