aGrUM 3.2.0
a C++ library for (probabilistic) graphical models
netReader.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
42#ifndef GUM_NET_READER_H
43#define GUM_NET_READER_H
44
45#include <iostream>
46#include <string>
47
48#include <agrum/agrum.h>
49
51
52#ifndef DOXYGEN_SHOULD_SKIP_THIS
53// including coco-generated PARSER and SCANNER; GUM_COCOR_PUBLIC is locally
54// forced to this module's own export macro so the grammar is tagged
55// correctly even in a translation unit (e.g. gumTest) that does not define
56// AGRUM_BN_EXPORTING.
57# undef _COCO_PARSER_H_
58# undef _COCO_SCANNER_H_
59# pragma push_macro("GUM_COCOR_PUBLIC")
60# undef GUM_COCOR_PUBLIC
61# define GUM_COCOR_PUBLIC GUM_PUBLIC_BN
62# include <agrum/BN/io/net/cocoR/Parser.h>
63# pragma pop_macro("GUM_COCOR_PUBLIC")
64#endif // DOXYGEN_SHOULD_SKIP_THIS
65
66namespace gum {
67 /* =========================================================================*/
68 /* === READERS === */
69 /* =========================================================================*/
79 template < GUM_Numeric GUM_SCALAR >
80 class NetReader: public BNReader< GUM_SCALAR > {
81 public:
91 NetReader(BayesNet< GUM_SCALAR >* bn, std::string_view filename);
92
96 ~NetReader() override;
97
100 net::Scanner& scanner();
101
103 const std::string& streamName() const;
104
106 bool trace() const;
107 void trace(bool b);
108
112 Size proceed() final;
113
116
121
129 std::string errMsg(Idx i);
130
132 void showElegantErrors(std::ostream& o = std::cerr);
133
135 void showElegantErrorsAndWarnings(std::ostream& o = std::cerr);
136
138 void showErrorsAndWarnings(std::ostream& o = std::cerr);
139
141 void showErrorCounts(std::ostream& o = std::cerr);
143
144 protected:
145 BayesNet< GUM_SCALAR >* _bn_;
147 net::Scanner* _scanner_;
148 net::Parser* _parser_;
149
153
154 // a boolean to throw the ioerror not in the constructor but in the
155 // proceed()
157 };
158
159
160#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
161 extern template class GUM_PUBLIC_BN NetReader< double >;
162#endif
163
164} /* namespace gum */
165
166#include "netReader_tpl.h"
167
168#endif // GUM_NET_READER_H
Definition of abstract classes for file input manipulation of Bayesian networks.
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.
Class representing a Bayesian network.
Definition BayesNet.h:99
const std::string & streamName() const
name of readen file
net::Parser * _parser_
Definition netReader.h:148
bool trace() const
accessor to trace function (just write the number of parser line)
bool errIsError(Idx i)
type of ith error or warning
Size errors()
publishing Errors API
net::Scanner * _scanner_
Definition netReader.h:147
std::string _streamName_
Definition netReader.h:150
Size proceed() final
parse.
void trace(bool b)
Idx errLine(Idx i)
line of ith error or warning
void showErrorCounts(std::ostream &o=std::cerr)
send on std::cerr the number of errors and the number of warnings
std::string errMsg(Idx i)
message of ith error or warning
void showErrorsAndWarnings(std::ostream &o=std::cerr)
send on std::cerr the list of errors or warnings
Idx errCol(Idx i)
col of ith error or warning
~NetReader() override
Default destructor.
void showElegantErrorsAndWarnings(std::ostream &o=std::cerr)
send on std::cerr the list of errors or warnings with contents
void showElegantErrors(std::ostream &o=std::cerr)
send on std::cerr the list of errorswith contents
bool _traceScanning_
Definition netReader.h:151
BayesNetFactory< GUM_SCALAR > * _factory_
Definition netReader.h:146
net::Scanner & scanner()
Direct access to DSL scanner (mandatory for listener connection).
NetReader(BayesNet< GUM_SCALAR > *bn, std::string_view filename)
Constructor A reader is defined for reading a defined file.
BayesNet< GUM_SCALAR > * _bn_
Definition netReader.h:145
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 NetReader< double >
Definition netReader.cpp:46
STL namespace.