aGrUM
0.20.2
a C++ library for (probabilistic) graphical models
DSLReader_tpl.h
Go to the documentation of this file.
1
/**
2
*
3
* Copyright 2005-2020 Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4
* info_at_agrum_dot_org
5
*
6
* This library is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU Lesser General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
10
*
11
* This library is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU Lesser General Public License for more details.
15
*
16
* You should have received a copy of the GNU Lesser General Public License
17
* along with this library. If not, see <http://www.gnu.org/licenses/>.
18
*
19
*/
20
21
22
#
ifndef
DOXYGEN_SHOULD_SKIP_THIS
23
24
#
include
<
agrum
/
BN
/
io
/
DSL
/
DSLReader
.
h
>
25
26
namespace
gum
{
27
28
template
<
typename
GUM_SCALAR >
29
DSLReader< GUM_SCALAR >::DSLReader(
BayesNet
<
GUM_SCALAR
>*
bn
,
30
const
std
::
string
&
filename
) :
31
BNReader
<
GUM_SCALAR
>(
bn
,
filename
) {
32
GUM_CONSTRUCTOR
(
DSLReader
);
33
bn__
=
bn
;
34
streamName__
=
filename
;
35
parseDone__
=
false
;
36
37
factory__
=
new
BayesNetFactory
<
GUM_SCALAR
>(
bn__
);
38
39
ioerror__
=
false
;
40
41
try
{
42
scanner__
=
new
DSL
::
Scanner
(
streamName__
.
c_str
());
43
parser__
=
new
DSL
::
Parser
(
scanner__
);
44
parser__
->
setFactory
((
IBayesNetFactory
*)
factory__
);
45
}
catch
(
IOError
&) {
ioerror__
=
true
; }
46
}
47
48
template
<
typename
GUM_SCALAR
>
49
DSLReader
<
GUM_SCALAR
>::~
DSLReader
() {
50
GUM_DESTRUCTOR
(
DSLReader
);
51
52
if
(!
ioerror__
) {
53
// this could lead to memory leak !!
54
if
(
parser__
)
delete
(
parser__
);
55
56
if
(
scanner__
)
delete
(
scanner__
);
57
}
58
59
if
(
factory__
)
delete
(
factory__
);
60
}
61
62
template
<
typename
GUM_SCALAR
>
63
INLINE
DSL
::
Scanner
&
DSLReader
<
GUM_SCALAR
>::
scanner
() {
64
if
(
ioerror__
) {
GUM_ERROR
(
gum
::
IOError
,
"No such file "
+
streamName
()); }
65
66
return
*
scanner__
;
67
}
68
69
template
<
typename
GUM_SCALAR
>
70
INLINE
const
std
::
string
&
DSLReader
<
GUM_SCALAR
>::
streamName
()
const
{
71
return
streamName__
;
72
}
73
74
template
<
typename
GUM_SCALAR
>
75
INLINE
bool
DSLReader
<
GUM_SCALAR
>::
trace
()
const
{
76
return
traceScanning__
;
77
}
78
79
template
<
typename
GUM_SCALAR
>
80
INLINE
void
DSLReader
<
GUM_SCALAR
>::
trace
(
bool
b
) {
81
traceScanning__
=
b
;
82
scanner
().
setTrace
(
b
);
83
}
84
85
template
<
typename
GUM_SCALAR
>
86
Size
DSLReader
<
GUM_SCALAR
>::
proceed
() {
87
if
(
ioerror__
) {
GUM_ERROR
(
gum
::
IOError
,
"No such file "
+
streamName
()); }
88
89
if
(!
parseDone__
) {
90
try
{
91
parser__
->
Parse
();
92
parseDone__
=
true
;
93
}
catch
(
gum
::
Exception
&
e
) {
94
GUM_SHOWERROR
(
e
);
95
return
1 +
parser__
->
errors
().
error_count
;
96
}
97
}
98
99
return
(
parser__
->
errors
().
error_count
);
100
}
101
102
/// @{
103
/// publishing Errors API
104
template
<
typename
GUM_SCALAR
>
105
INLINE
Idx
DSLReader
<
GUM_SCALAR
>::
errLine
(
Idx
i
) {
106
if
(
parseDone__
)
107
return
parser__
->
errors
().
error
(
i
).
line
;
108
else
{
109
GUM_ERROR
(
OperationNotAllowed
,
"DSL file not parsed yet"
);
110
}
111
}
112
113
template
<
typename
GUM_SCALAR
>
114
INLINE
Idx
DSLReader
<
GUM_SCALAR
>::
errCol
(
Idx
i
) {
115
if
(
parseDone__
)
116
return
parser__
->
errors
().
error
(
i
).
column
;
117
else
{
118
GUM_ERROR
(
OperationNotAllowed
,
"DSL file not parsed yet"
);
119
}
120
}
121
122
template
<
typename
GUM_SCALAR
>
123
INLINE
bool
DSLReader
<
GUM_SCALAR
>::
errIsError
(
Idx
i
) {
124
if
(
parseDone__
)
125
return
parser__
->
errors
().
error
(
i
).
is_error
;
126
else
{
127
GUM_ERROR
(
OperationNotAllowed
,
"DSL file not parsed yet"
);
128
}
129
}
130
131
template
<
typename
GUM_SCALAR
>
132
INLINE
std
::
string
DSLReader
<
GUM_SCALAR
>::
errMsg
(
Idx
i
) {
133
if
(
parseDone__
)
134
return
parser__
->
errors
().
error
(
i
).
msg
;
135
else
{
136
GUM_ERROR
(
OperationNotAllowed
,
"DSL file not parsed yet"
);
137
}
138
}
139
140
template
<
typename
GUM_SCALAR
>
141
INLINE
void
DSLReader
<
GUM_SCALAR
>::
showElegantErrors
(
std
::
ostream
&
o
) {
142
if
(
parseDone__
)
143
parser__
->
errors
().
elegantErrors
(
o
);
144
else
{
145
GUM_ERROR
(
OperationNotAllowed
,
"DSL file not parsed yet"
);
146
}
147
}
148
149
template
<
typename
GUM_SCALAR
>
150
INLINE
void
151
DSLReader
<
GUM_SCALAR
>::
showElegantErrorsAndWarnings
(
std
::
ostream
&
o
) {
152
if
(
parseDone__
)
153
parser__
->
errors
().
elegantErrorsAndWarnings
(
o
);
154
else
{
155
GUM_ERROR
(
OperationNotAllowed
,
"DSL file not parsed yet"
);
156
}
157
}
158
159
template
<
typename
GUM_SCALAR
>
160
INLINE
void
DSLReader
<
GUM_SCALAR
>::
showErrorsAndWarnings
(
std
::
ostream
&
o
) {
161
if
(
parseDone__
)
162
parser__
->
errors
().
simpleErrorsAndWarnings
(
o
);
163
else
{
164
GUM_ERROR
(
OperationNotAllowed
,
"DSL file not parsed yet"
);
165
}
166
}
167
168
template
<
typename
GUM_SCALAR
>
169
INLINE
void
DSLReader
<
GUM_SCALAR
>::
showErrorCounts
(
std
::
ostream
&
o
) {
170
if
(
parseDone__
)
171
parser__
->
errors
().
syntheticResults
(
o
);
172
else
{
173
GUM_ERROR
(
OperationNotAllowed
,
"DSL file not parsed yet"
);
174
}
175
}
176
177
template
<
typename
GUM_SCALAR
>
178
INLINE
Size
DSLReader
<
GUM_SCALAR
>::
errors
() {
179
return
(!
parseDone__
) ? (
Size
)0 :
parser__
->
errors
().
error_count
;
180
}
181
182
template
<
typename
GUM_SCALAR
>
183
INLINE
Size
DSLReader
<
GUM_SCALAR
>::
warnings
() {
184
return
(!
parseDone__
) ? (
Size
)0 :
parser__
->
errors
().
warning_count
;
185
}
186
187
/// @}
188
}
// namespace gum
189
190
#
endif
// DOXYGEN_SHOULD_SKIP_THIS
gum::Set::emplace
INLINE void emplace(Args &&... args)
Definition:
set_tpl.h:669