aGrUM 2.3.2
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-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
42#ifndef NETREADER_H
43#define NETREADER_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
54# undef _COCO_PARSER_H_
55# undef _COCO_SCANNER_H_
56# include <agrum/BN/io/net/cocoR/Parser.h>
57#endif // DOXYGEN_SHOULD_SKIP_THIS
58
59namespace gum {
60 /* =========================================================================*/
61 /* === READERS === */
62 /* =========================================================================*/
72 template < typename GUM_SCALAR >
73 class NetReader: public BNReader< GUM_SCALAR > {
74 public:
84 NetReader(BayesNet< GUM_SCALAR >* bn, const std::string& filename);
85
90
93 net::Scanner& scanner();
94
96 const std::string& streamName() const;
97
99 bool trace() const;
100 void trace(bool b);
101
105 Size proceed() final;
106
109
114
122 std::string errMsg(Idx i);
123
125 void showElegantErrors(std::ostream& o = std::cerr);
126
128 void showElegantErrorsAndWarnings(std::ostream& o = std::cerr);
129
131 void showErrorsAndWarnings(std::ostream& o = std::cerr);
132
134 void showErrorCounts(std::ostream& o = std::cerr);
136
137 protected:
138 BayesNet< GUM_SCALAR >* _bn_;
140 net::Scanner* _scanner_;
141 net::Parser* _parser_;
142
146
147 // a boolean to throw the ioerror not in the constructor but in the
148 // proceed()
150 };
151
152
153#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
154 extern template class NetReader< double >;
155#endif
156
157} /* namespace gum */
158
159#include "netReader_tpl.h"
160
161#endif // NETREADER_H
Definition of abstract classes for file input manipulation of Bayesian networks.
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.
Class representing a Bayesian network.
Definition BayesNet.h:93
NetReader(BayesNet< GUM_SCALAR > *bn, const std::string &filename)
Constructor A reader is defined for reading a defined file.
const std::string & streamName() const
name of readen file
net::Parser * _parser_
Definition netReader.h:141
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:140
std::string _streamName_
Definition netReader.h:143
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()
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:144
BayesNetFactory< GUM_SCALAR > * _factory_
Definition netReader.h:139
net::Scanner & scanner()
Direct access to DSL scanner (mandatory for listener connection).
BayesNet< GUM_SCALAR > * _bn_
Definition netReader.h:138
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
STL namespace.