aGrUM 2.3.2
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-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
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
69namespace gum {
70 namespace prm {
71 namespace o3prm {
72
83 template < typename GUM_SCALAR >
85 public:
88 O3prmReader(const O3prmReader& src);
93
96 Size readFile(const std::string& file, const std::string& module = "");
97
100 Size readString(const std::string& string);
101
102 void parseStream(std::istream& input, std::ostream& output, std::string module = "");
111 void setClassPath(const std::string& class_path);
112
121 void addClassPath(const std::string& class_path);
122
124
125 const gum::prm::PRM< GUM_SCALAR >* prm() const { return _prm_; }
126
129
131 Size errors() const;
133 Size warnings() const;
134
136 const ErrorsContainer& errorsContainer() const;
137
139 Idx errLine(Idx i) const;
141 Idx errCol(Idx i) const;
143 std::wstring errFilename(Idx i) const;
145 bool errIsError(Idx i) const;
147 std::string errMsg(Idx i) const;
148
150 void showElegantErrors(std::ostream& o = std::cerr) const;
151
153 void showElegantErrorsAndWarnings(std::ostream& o = std::cerr) const;
154
156 void showErrorCounts(std::ostream& o = std::cerr) const;
158
159 private:
161 std::unique_ptr< O3PRM > _o3_prm_;
162 std::vector< std::string > _class_path_;
164
165 // Needed when file can't be parse (can not open it for exemple)
167
168 void _readStream_(std::istream& input, const std::string& file, std::string module = "");
169
170 void _parseImport_(const O3Import& i, const std::string& module_path);
171
172 void _parseStream_(std::istream& input,
173 const std::string& filename,
174 const std::string& module);
175
176 std::vector< const O3Import* > _copyImports_();
177
178 std::string _clean_(std::string text) const;
179 std::string _print_(const ParseError& err) const;
180 std::string _readStream_(std::istream& input);
181 };
182
183 } // namespace o3prm
184 } // namespace prm
185} // namespace gum
186
187// always include the implementation of the templates
189
190
191#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
192extern template class gum::prm::o3prm::O3prmReader< double >;
193#endif
194
195
196#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:889
Set< std::string > _imported_
Size errors() const
publishing Errors API
std::vector< const O3Import * > _copyImports_()
Size readString(const std::string &string)
With readString method, you must set the current path to search from import yourself,...
void _parseImport_(const O3Import &i, const std::string &module_path)
const ErrorsContainer & errorsContainer() const
publishing Errors API
std::wstring errFilename(Idx i) const
filename of ith error or warning
void showElegantErrors(std::ostream &o=std::cerr) const
send on std::cerr the list of errors
void addClassPath(const std::string &class_path)
Add a list of paths to look for o3prm files.
Idx errCol(Idx i) const
col of ith error or warning
std::string _print_(const ParseError &err) const
gum::prm::PRM< GUM_SCALAR > * prm()
void setClassPath(const std::string &class_path)
This methods defines the list of paths to look for o3prm files.
void showErrorCounts(std::ostream &o=std::cerr) const
send on std::cerr the number of errors and the number of warnings
void showElegantErrorsAndWarnings(std::ostream &o=std::cerr) const
send on std::cerr the list of errors or warnings
O3prmReader & operator=(const O3prmReader &src)
void _readStream_(std::istream &input, const std::string &file, std::string module="")
const gum::prm::PRM< GUM_SCALAR > * prm() const
void _parseStream_(std::istream &input, const std::string &filename, const std::string &module)
bool errIsError(Idx i) const
type of ith error or warning
Idx errLine(Idx i) const
line of ith error or warning
void parseStream(std::istream &input, std::ostream &output, std::string module="")
std::string errMsg(Idx i) const
message of ith error or warning
Size readFile(const std::string &file, const std::string &module="")
Read file and load its content using a PRMFactory. The package parameter set the file's content packa...
std::string _clean_(std::string text) const
std::unique_ptr< O3PRM > _o3_prm_
PRM< GUM_SCALAR > * _prm_
std::vector< std::string > _class_path_
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