aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
DSLReader.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 DSLREADER_H
43#define DSLREADER_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
55# include <agrum/BN/io/DSL/cocoR/Parser.h>
56#endif // DOXYGEN_SHOULD_SKIP_THIS
57
58namespace gum {
59 /* =========================================================================*/
60 /* === READERS === */
61 /* =========================================================================*/
71 template < typename GUM_SCALAR >
72 class DSLReader: public BNReader< GUM_SCALAR > {
73 public:
83 DSLReader(BayesNet< GUM_SCALAR >* bn, const std::string& filename);
84
89
92 DSL::Scanner& scanner();
93
95 const std::string& streamName() const;
96
98 bool trace() const;
99 void trace(bool b);
100
104 Size proceed() final;
105
108
113
121 std::string errMsg(Idx i);
122
124 void showElegantErrors(std::ostream& o = std::cerr);
125
127 void showElegantErrorsAndWarnings(std::ostream& o = std::cerr);
128
130 void showErrorsAndWarnings(std::ostream& o = std::cerr);
131
133 void showErrorCounts(std::ostream& o = std::cerr);
135
136 protected:
137 BayesNet< GUM_SCALAR >* _bn_;
139 DSL::Scanner* _scanner_;
140 DSL::Parser* _parser_;
141
145
146 // a boolean to throw the ioerror not in the constructor but in the
147 // proceed()
149 };
150
151
152#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
153 extern template class DSLReader< double >;
154#endif
155
156} /* namespace gum */
157
158#include "DSLReader_tpl.h"
159
160#endif // DSLREADER_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
const std::string & streamName() const
name of readen file
DSL::Scanner & scanner()
Direct access to DSL scanner (mandatory for listener connection).
bool errIsError(Idx i)
type of ith error or warning
Idx errCol(Idx i)
col of ith error or warning
bool _traceScanning_
Definition DSLReader.h:143
void trace(bool b)
bool trace() const
accessor to trace function (just write the number of parser line)
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
void showErrorsAndWarnings(std::ostream &o=std::cerr)
send on std::cerr the list of errors or warnings
std::string _streamName_
Definition DSLReader.h:142
Size errors()
publishing Errors API
Size proceed() final
parse.
DSLReader(BayesNet< GUM_SCALAR > *bn, const std::string &filename)
Constructor A reader is defined for reading a defined file.
Idx errLine(Idx i)
line of ith error or warning
BayesNet< GUM_SCALAR > * _bn_
Definition DSLReader.h:137
BayesNetFactory< GUM_SCALAR > * _factory_
Definition DSLReader.h:138
DSL::Scanner * _scanner_
Definition DSLReader.h:139
DSL::Parser * _parser_
Definition DSLReader.h:140
std::string errMsg(Idx i)
message 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
~DSLReader()
Default destructor.
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.