aGrUM 2.3.2
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-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
84#ifndef BIF_READER_H
85#define 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
95# include <agrum/BN/io/BIF/cocoR/Parser.h>
96#endif // DOXYGEN_SHOULD_SKIP_THIS
97
98namespace gum {
142 template < typename GUM_SCALAR >
143 class BIFReader final: public BNReader< GUM_SCALAR > {
144 public:
145 BIFReader(BayesNet< GUM_SCALAR >* bn, const std::string& filename);
146
148
151 BIF::Scanner& scanner();
152
154 const std::string& streamName() const;
155
157 bool trace() const;
158 void trace(bool b);
159
164
167
172
180 std::string errMsg(Idx i);
181
183 void showElegantErrors(std::ostream& o = std::cerr);
184
186 void showElegantErrorsAndWarnings(std::ostream& o = std::cerr);
187
189 void showErrorCounts(std::ostream& o = std::cerr);
191
192 private:
193 BayesNet< GUM_SCALAR >* _bn_;
195 BIF::Scanner* _scanner_;
196 BIF::Parser* _parser_;
197
198 std::string _streamName_;
201
202 // a boolean to throw the ioerror not in the constructor but in the
203 // proceed()
205 };
206
207
208#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
209 extern template class BIFReader< double >;
210#endif
211
212} // namespace gum
213
215
216#endif // BIF_READER_H
Definition of templatized reader of BIF files for Bayesian networks.
Definition of abstract classes for file input manipulation of Bayesian networks.
Definition of templatized reader of BIF files for Bayesian networks.
Definition BIFReader.h:143
bool _traceScanning_
Definition BIFReader.h:199
BayesNet< GUM_SCALAR > * _bn_
Definition BIFReader.h:193
BIF::Parser * _parser_
Definition BIFReader.h:196
BIF::Scanner * _scanner_
Definition BIFReader.h:195
bool errIsError(Idx i)
type of ith error or warning
void showElegantErrorsAndWarnings(std::ostream &o=std::cerr)
send on std::cerr the list of errors or warnings
BIF::Scanner & scanner()
Direct access to BIF scanner (mandatory for listener connection).
BayesNetFactory< GUM_SCALAR > * _factory_
Definition BIFReader.h:194
Idx errLine(Idx i)
line of ith error or warning
std::string _streamName_
Definition BIFReader.h:198
std::string errMsg(Idx i)
message of ith error or warning
Size errors()
publishing Errors API
Size proceed()
parse.
Idx errCol(Idx i)
col of ith error or warning
const std::string & streamName() const
name of read file
void showErrorCounts(std::ostream &o=std::cerr)
send on std::cerr the number of errors and the number of warnings
void trace(bool b)
bool trace() const
accessor to trace function (just write the number of parser line)
void showElegantErrors(std::ostream &o=std::cerr)
send on std::cerr the list of errors
BIFReader(BayesNet< GUM_SCALAR > *bn, const std::string &filename)
BNReader(BayesNet< GUM_SCALAR > *bn, const std::string &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