aGrUM 3.2.0
a C++ library for (probabilistic) graphical models
O3prmReader.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2026 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-2026 *
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
49
50#ifndef GUM_PRM_O3PRM_O3PRM_FACTORY_H
51#define GUM_PRM_O3PRM_O3PRM_FACTORY_H
52
53#include <cstdint>
54#include <fstream>
55#include <iostream>
56#include <sstream>
57#include <string>
58#include <vector>
59
60#include <agrum/agrum.h>
61
62// GUM_COCOR_PUBLIC is locally forced to this module's own export macro so
63// the grammar is tagged correctly even in a translation unit (e.g. gumTest)
64// that does not define AGRUM_PRM_EXPORTING.
65#pragma push_macro("GUM_COCOR_PUBLIC")
66#undef GUM_COCOR_PUBLIC
67#define GUM_COCOR_PUBLIC GUM_PUBLIC_PRM
68#include <agrum/PRM/o3prm/cocoR/Parser.h>
69#include <agrum/PRM/o3prm/cocoR/Scanner.h>
70#pragma pop_macro("GUM_COCOR_PUBLIC")
75
76#include <string_view>
77
78namespace gum {
79 namespace prm {
80 namespace o3prm {
81
92 template < GUM_Numeric GUM_SCALAR >
94 public:
97 O3prmReader(const O3prmReader& src);
100 O3prmReader& operator=(const O3prmReader& src);
102
105 Size readFile(std::string_view file, std::string_view module = "");
106
109 Size readString(const std::string& string);
110
111 void parseStream(std::istream& input, std::ostream& output, std::string module = "");
120 void setClassPath(std::string_view class_path);
121
130 void addClassPath(std::string_view class_path);
131
133
134 const gum::prm::PRM< GUM_SCALAR >* prm() const;
135
138
140 Size errors() const;
142 Size warnings() const;
143
145 const ErrorsContainer& errorsContainer() const;
146
148 Idx errLine(Idx i) const;
150 Idx errCol(Idx i) const;
152 std::wstring errFilename(Idx i) const;
154 bool errIsError(Idx i) const;
156 std::string errMsg(Idx i) const;
157
159 void showElegantErrors(std::ostream& o = std::cerr) const;
160
162 void showElegantErrorsAndWarnings(std::ostream& o = std::cerr) const;
163
165 void showErrorCounts(std::ostream& o = std::cerr) const;
167
168 private:
170 std::unique_ptr< O3PRM > _o3_prm_;
171 std::vector< std::string > _class_path_;
173
174 // Needed when file can't be parse (can not open it for exemple)
176
177 void _readStream_(std::istream& input, const std::string& file, std::string module = "");
178
179 void _parseImport_(const O3Import& i, const std::string& module_path);
180
181 void _parseStream_(std::istream& input,
182 const std::string& filename,
183 const std::string& module);
184
185 std::vector< const O3Import* > _copyImports_();
186
187 std::string _clean_(std::string text) const;
188 std::string _print_(const ParseError& err) const;
189 std::string _readStream_(std::istream& input);
190 };
191
192 } // namespace o3prm
193 } // namespace prm
194} // namespace gum
195
196// always include the implementation of the templates
198
199
200#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
201extern template class gum::prm::o3prm::O3prmReader< double >;
202#endif
203
204
205#endif // GUM_PRM_O3PRM_O3PRM_FACTORY_H
Headers for the O3ClassFactory class.
Headers for the O3InterfaceFactory class.
Headers for the O3SystemFactory class.
Headers for the O3TypeFactory class.
Implementation for the O3prmReader class.
This class is used contain and manipulate gum::ParseError.
This class is used to represent parsing errors for the different parser implemented in aGrUM.
This class represents a Probabilistic Relational PRMSystem<GUM_SCALAR>.
Definition PRM.h:74
The O3Import is part of the AST of the O3PRM language.
Definition O3prm.h:891
void setClassPath(std::string_view class_path)
This methods defines the list of paths to look for o3prm files.
Set< std::string > _imported_
void _parseStream_(std::istream &input, const std::string &filename, const std::string &module)
Idx errLine(Idx i) const
line of ith error or warning
Size readString(const std::string &string)
With readString method, you must set the current path to search from import yourself,...
std::wstring errFilename(Idx i) const
filename of ith error or warning
gum::prm::PRM< GUM_SCALAR > * prm()
void parseStream(std::istream &input, std::ostream &output, std::string module="")
Size errors() const
publishing Errors API
O3prmReader & operator=(const O3prmReader &src)
void showErrorCounts(std::ostream &o=std::cerr) const
send on std::cerr the number of errors and the number of warnings
void showElegantErrors(std::ostream &o=std::cerr) const
send on std::cerr the list of errors
const ErrorsContainer & errorsContainer() const
publishing Errors API
bool errIsError(Idx i) const
type of ith error or warning
std::string _clean_(std::string text) const
void _readStream_(std::istream &input, const std::string &file, std::string module="")
Size readFile(std::string_view file, std::string_view module="")
Read file and load its content using a PRMFactory. The package parameter set the file's content packa...
Idx errCol(Idx i) const
col of ith error or warning
std::vector< const O3Import * > _copyImports_()
std::string _print_(const ParseError &err) const
std::unique_ptr< O3PRM > _o3_prm_
void _parseImport_(const O3Import &i, const std::string &module_path)
std::string errMsg(Idx i) const
message of ith error or warning
void showElegantErrorsAndWarnings(std::ostream &o=std::cerr) const
send on std::cerr the list of errors or warnings
PRM< GUM_SCALAR > * _prm_
std::vector< std::string > _class_path_
void addClassPath(std::string_view class_path)
Add a list of paths to look for o3prm files.
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