aGrUM
3.2.0
a C++ library for (probabilistic) graphical models
Toggle main menu visibility
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
50
#include <
agrum/BN/io/BNReader.h
>
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
64
namespace
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
116
Size
errors
();
118
Size
warnings
();
119
121
Idx
errLine
(
Idx
i);
123
Idx
errCol
(
Idx
i);
125
bool
errIsError
(
Idx
i);
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_
;
144
BayesNetFactory
< GUM_SCALAR >*
_factory_
;
145
DSL::Scanner*
_scanner_
;
146
DSL::Parser*
_parser_
;
147
148
std
::
string
_streamName_
;
149
bool
_traceScanning_
;
150
bool
_parseDone_
;
151
152
// a boolean to throw the ioerror not in the constructor but in the
153
// proceed()
154
bool
_ioerror_
;
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
BNReader.h
Definition of abstract classes for file input manipulation of Bayesian networks.
DSLReader_tpl.h
agrum.h
gum::BNReader::BNReader
BNReader(BayesNet< GUM_SCALAR > *bn, std::string_view filename)
Constructor A reader is defined for reading a defined file.
gum::BayesNetFactory
A factory class to ease BayesNet construction.
Definition
BayesNetFactory.h:83
gum::BayesNet
Class representing a Bayesian network.
Definition
BayesNet.h:99
gum::DSLReader::streamName
const std::string & streamName() const
name of readen file
gum::DSLReader::scanner
DSL::Scanner & scanner()
Direct access to DSL scanner (mandatory for listener connection).
gum::DSLReader::errIsError
bool errIsError(Idx i)
type of ith error or warning
gum::DSLReader::warnings
Size warnings()
gum::DSLReader::errCol
Idx errCol(Idx i)
col of ith error or warning
gum::DSLReader::DSLReader
DSLReader(BayesNet< GUM_SCALAR > *bn, std::string_view filename)
Constructor A reader is defined for reading a defined file.
gum::DSLReader::_traceScanning_
bool _traceScanning_
Definition
DSLReader.h:149
gum::DSLReader::trace
void trace(bool b)
gum::DSLReader::trace
bool trace() const
accessor to trace function (just write the number of parser line)
gum::DSLReader::showElegantErrorsAndWarnings
void showElegantErrorsAndWarnings(std::ostream &o=std::cerr)
send on std::cerr the list of errors or warnings with contents
gum::DSLReader::showElegantErrors
void showElegantErrors(std::ostream &o=std::cerr)
send on std::cerr the list of errorswith contents
gum::DSLReader::showErrorsAndWarnings
void showErrorsAndWarnings(std::ostream &o=std::cerr)
send on std::cerr the list of errors or warnings
gum::DSLReader::_streamName_
std::string _streamName_
Definition
DSLReader.h:148
gum::DSLReader::errors
Size errors()
publishing Errors API
gum::DSLReader::proceed
Size proceed() final
parse.
gum::DSLReader::_parseDone_
bool _parseDone_
Definition
DSLReader.h:150
gum::DSLReader::~DSLReader
~DSLReader() override
Default destructor.
gum::DSLReader::_ioerror_
bool _ioerror_
Definition
DSLReader.h:154
gum::DSLReader::errLine
Idx errLine(Idx i)
line of ith error or warning
gum::DSLReader::_bn_
BayesNet< GUM_SCALAR > * _bn_
Definition
DSLReader.h:143
gum::DSLReader::_factory_
BayesNetFactory< GUM_SCALAR > * _factory_
Definition
DSLReader.h:144
gum::DSLReader::_scanner_
DSL::Scanner * _scanner_
Definition
DSLReader.h:145
gum::DSLReader::_parser_
DSL::Parser * _parser_
Definition
DSLReader.h:146
gum::DSLReader::errMsg
std::string errMsg(Idx i)
message of ith error or warning
gum::DSLReader::showErrorCounts
void showErrorCounts(std::ostream &o=std::cerr)
send on std::cerr the number of errors and the number of warnings
gum::Size
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition
types.h:74
gum::Idx
Size Idx
Type for indexes.
Definition
types.h:79
gum
gum is the global namespace for all aGrUM entities
Definition
agrum.h:46
gum::DSLReader< double >
template class GUM_PUBLIC_BN DSLReader< double >
Definition
DSLReader.cpp:46
std
STL namespace.
aGrUM
3.2.0
© PHW&CG&others - 2022
DoXyGeN 1.18.0