aGrUM 3.1.1
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#include <agrum/PRM/o3prm/cocoR/Parser.h>
63#include <agrum/PRM/o3prm/cocoR/Scanner.h>
68
69#include <string_view>
70
71namespace gum {
72 namespace prm {
73 namespace o3prm {
74
85 template < GUM_Numeric GUM_SCALAR >
87 public:
90 O3prmReader(const O3prmReader& src);
95
98 Size readFile(std::string_view file, std::string_view module = "");
99
102 Size readString(const std::string& string);
103
104 void parseStream(std::istream& input, std::ostream& output, std::string module = "");
113 void setClassPath(std::string_view class_path);
114
123 void addClassPath(std::string_view class_path);
124
126
127 const gum::prm::PRM< GUM_SCALAR >* prm() const;
128
131
133 Size errors() const;
135 Size warnings() const;
136
138 const ErrorsContainer& errorsContainer() const;
139
141 Idx errLine(Idx i) const;
143 Idx errCol(Idx i) const;
145 std::wstring errFilename(Idx i) const;
147 bool errIsError(Idx i) const;
149 std::string errMsg(Idx i) const;
150
152 void showElegantErrors(std::ostream& o = std::cerr) const;
153
155 void showElegantErrorsAndWarnings(std::ostream& o = std::cerr) const;
156
158 void showErrorCounts(std::ostream& o = std::cerr) const;
160
161 private:
163 std::unique_ptr< O3PRM > _o3_prm_;
164 std::vector< std::string > _class_path_;
166
167 // Needed when file can't be parse (can not open it for exemple)
169
170 void _readStream_(std::istream& input, const std::string& file, std::string module = "");
171
172 void _parseImport_(const O3Import& i, const std::string& module_path);
173
174 void _parseStream_(std::istream& input,
175 const std::string& filename,
176 const std::string& module);
177
178 std::vector< const O3Import* > _copyImports_();
179
180 std::string _clean_(std::string text) const;
181 std::string _print_(const ParseError& err) const;
182 std::string _readStream_(std::istream& input);
183 };
184
185 } // namespace o3prm
186 } // namespace prm
187} // namespace gum
188
189// always include the implementation of the templates
191
192
193#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
194extern template class gum::prm::o3prm::O3prmReader< double >;
195#endif
196
197
198#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
namespace for all probabilistic relational models entities
Definition agrum.h:68
gum is the global namespace for all aGrUM entities
Definition agrum.h:46