aGrUM 3.2.0
a C++ library for (probabilistic) graphical models
BIFReader.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
84#ifndef GUM_BIF_READER_H
85#define GUM_BIF_READER_H
86
87#include <fstream>
88#include <iostream>
89#include <string>
90
92
93#ifndef DOXYGEN_SHOULD_SKIP_THIS
94// including coco-generated PARSER and SCANNER; GUM_COCOR_PUBLIC is locally
95// forced to this module's own export macro so the grammar is tagged
96// correctly even in a translation unit (e.g. gumTest) that does not define
97// AGRUM_BN_EXPORTING.
98# pragma push_macro("GUM_COCOR_PUBLIC")
99# undef GUM_COCOR_PUBLIC
100# define GUM_COCOR_PUBLIC GUM_PUBLIC_BN
101# include <agrum/BN/io/BIF/cocoR/Parser.h>
102# pragma pop_macro("GUM_COCOR_PUBLIC")
103#endif // DOXYGEN_SHOULD_SKIP_THIS
104
105namespace gum {
149 template < GUM_Numeric GUM_SCALAR >
150 class BIFReader final: public BNReader< GUM_SCALAR > {
151 public:
152 BIFReader(BayesNet< GUM_SCALAR >* bn, std::string_view filename);
153
154 ~BIFReader() override;
155
158 BIF::Scanner& scanner();
159
161 const std::string& streamName() const;
162
164 bool trace() const;
165 void trace(bool b);
166
170 Size proceed() override;
171
174
176 Size errors() const;
178 Size warnings() const;
179
181 Idx errLine(Idx i) const;
183 Idx errCol(Idx i) const;
185 bool errIsError(Idx i) const;
187 std::string errMsg(Idx i) const;
188
190 void showElegantErrors(std::ostream& o = std::cerr) const;
191
193 void showElegantErrorsAndWarnings(std::ostream& o = std::cerr) const;
194
196 void showErrorCounts(std::ostream& o = std::cerr) const;
198
199 private:
200 BayesNet< GUM_SCALAR >* _bn_;
202 BIF::Scanner* _scanner_;
203 BIF::Parser* _parser_;
204
205 std::string _streamName_;
208
209 // a boolean to throw the ioerror not in the constructor but in the
210 // proceed()
212 };
213
214
215#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
216 extern template class GUM_PUBLIC_BN BIFReader< double >;
217#endif
218} // namespace gum
219
221
222#endif // GUM_BIF_READER_H
Definition of templatized reader of BIF files for Bayesian networks.
Definition of abstract classes for file input manipulation of Bayesian networks.
bool _traceScanning_
Definition BIFReader.h:206
BayesNet< GUM_SCALAR > * _bn_
Definition BIFReader.h:200
Idx errCol(Idx i) const
col of ith error or warning
Size warnings() const
BIF::Parser * _parser_
Definition BIFReader.h:203
Size errors() const
publishing Errors API
BIF::Scanner * _scanner_
Definition BIFReader.h:202
void showErrorCounts(std::ostream &o=std::cerr) const
send on std::cerr the number of errors and the number of warnings
BIF::Scanner & scanner()
Direct access to BIF scanner (mandatory for listener connection).
BIFReader(BayesNet< GUM_SCALAR > *bn, std::string_view filename)
BayesNetFactory< GUM_SCALAR > * _factory_
Definition BIFReader.h:201
Idx errLine(Idx i) const
line of ith error or warning
void showElegantErrors(std::ostream &o=std::cerr) const
send on std::cerr the list of errors
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
std::string _streamName_
Definition BIFReader.h:205
~BIFReader() override
const std::string & streamName() const
name of read file
Size proceed() override
parse.
bool errIsError(Idx i) const
type of ith error or warning
void trace(bool b)
bool trace() const
accessor to trace function (just write the number of parser line)
BNReader(BayesNet< GUM_SCALAR > *bn, std::string_view filename)
Constructor A reader is defined for reading a defined file.
A factory class to ease BayesNet construction.
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
template class GUM_PUBLIC_BN BIFReader< double >
Definition BIFReader.cpp:46