aGrUM 3.2.0
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-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_DSL_READER_H
43#define GUM_DSL_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# pragma push_macro("GUM_COCOR_PUBLIC")
58# undef GUM_COCOR_PUBLIC
59# define GUM_COCOR_PUBLIC GUM_PUBLIC_BN
60# include <agrum/BN/io/DSL/cocoR/Parser.h>
61# pragma pop_macro("GUM_COCOR_PUBLIC")
62#endif // DOXYGEN_SHOULD_SKIP_THIS
63
64namespace gum {
65 /* =========================================================================*/
66 /* === READERS === */
67 /* =========================================================================*/
77 template < GUM_Numeric GUM_SCALAR >
78 class DSLReader: public BNReader< GUM_SCALAR > {
79 public:
89 DSLReader(BayesNet< GUM_SCALAR >* bn, std::string_view filename);
90
94 ~DSLReader() override;
95
98 DSL::Scanner& scanner();
99
101 const std::string& streamName() const;
102
104 bool trace() const;
105 void trace(bool b);
106
110 Size proceed() final;
111
114
119
127 std::string errMsg(Idx i);
128
130 void showElegantErrors(std::ostream& o = std::cerr);
131
133 void showElegantErrorsAndWarnings(std::ostream& o = std::cerr);
134
136 void showErrorsAndWarnings(std::ostream& o = std::cerr);
137
139 void showErrorCounts(std::ostream& o = std::cerr);
141
142 protected:
143 BayesNet< GUM_SCALAR >* _bn_;
145 DSL::Scanner* _scanner_;
146 DSL::Parser* _parser_;
147
151
152 // a boolean to throw the ioerror not in the constructor but in the
153 // proceed()
155 };
156
157
158#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
159 extern template class GUM_PUBLIC_BN DSLReader< double >;
160#endif
161
162} /* namespace gum */
163
164#include "DSLReader_tpl.h"
165
166#endif // GUM_DSL_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
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
DSLReader(BayesNet< GUM_SCALAR > *bn, std::string_view filename)
Constructor A reader is defined for reading a defined file.
bool _traceScanning_
Definition DSLReader.h:149
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:148
Size errors()
publishing Errors API
Size proceed() final
parse.
~DSLReader() override
Default destructor.
Idx errLine(Idx i)
line of ith error or warning
BayesNet< GUM_SCALAR > * _bn_
Definition DSLReader.h:143
BayesNetFactory< GUM_SCALAR > * _factory_
Definition DSLReader.h:144
DSL::Scanner * _scanner_
Definition DSLReader.h:145
DSL::Parser * _parser_
Definition DSLReader.h:146
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
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 DSLReader< double >
Definition DSLReader.cpp:46
STL namespace.