aGrUM
0.20.3
a C++ library for (probabilistic) graphical models
fmdpDatReader_tpl.h
Go to the documentation of this file.
1
/**
2
*
3
* Copyright (c) 2005-2021 by 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
/**
23
* @file
24
* @brief Definition of templatized reader of dat files for Factored Markov
25
* Decision Process.
26
*
27
* @author Pierre-Henri WUILLEMIN(@LIP6) and Jean-Christophe MAGNAN and Christophe
28
* GONZALES(@AMU)
29
*/
30
31
#
ifndef
DOXYGEN_SHOULD_SKIP_THIS
32
33
#
include
<
agrum
/
FMDP
/
io
/
dat
/
fmdpDatReader
.
h
>
34
35
namespace
gum
{
36
37
template
<
typename
GUM_SCALAR >
38
FMDPDatReader< GUM_SCALAR >::FMDPDatReader(
FMDP
<
GUM_SCALAR
>*
fmdp
,
39
const
std
::
string
&
filename
) :
40
FMDPReader
<
GUM_SCALAR
>(
fmdp
,
filename
) {
41
GUM_CONSTRUCTOR
(
FMDPDatReader
);
42
43
_fmdp_
=
fmdp
;
44
_streamName_
=
filename
;
45
_parseDone_
=
false
;
46
// ddf->putOnNoVariableCheckMode();
47
_factory_
=
new
FMDPFactory
<
GUM_SCALAR
>(
_fmdp_
);
48
//~ _factory_->setVerbose();
49
_ioerror_
=
false
;
50
51
try
{
52
_scanner_
=
new
MDPDAT
::
Scanner
(
_streamName_
.
c_str
());
53
_parser_
=
new
MDPDAT
::
Parser
(
_scanner_
);
54
_parser_
->
setFactory
((
AbstractFMDPFactory
*)
_factory_
);
55
}
catch
(
IOError
e
) {
_ioerror_
=
true
; }
56
}
57
58
template
<
typename
GUM_SCALAR
>
59
FMDPDatReader
<
GUM_SCALAR
>::~
FMDPDatReader
() {
60
GUM_DESTRUCTOR
(
FMDPDatReader
);
61
62
if
(!
_ioerror_
) {
63
// this could lead to memory leak !!
64
if
(
_parser_
)
delete
(
_parser_
);
65
66
if
(
_scanner_
)
delete
(
_scanner_
);
67
}
68
69
if
(
_factory_
)
delete
(
_factory_
);
70
}
71
72
template
<
typename
GUM_SCALAR
>
73
INLINE
MDPDAT
::
Scanner
&
FMDPDatReader
<
GUM_SCALAR
>::
scanner
() {
74
if
(
_ioerror_
) {
GUM_ERROR
(
gum
::
IOError
,
"No such file "
+
streamName
()) }
75
76
return
*
_scanner_
;
77
}
78
79
template
<
typename
GUM_SCALAR
>
80
INLINE
const
std
::
string
&
FMDPDatReader
<
GUM_SCALAR
>::
streamName
()
const
{
81
return
_streamName_
;
82
}
83
84
template
<
typename
GUM_SCALAR
>
85
INLINE
bool
FMDPDatReader
<
GUM_SCALAR
>::
trace
()
const
{
86
return
_traceScanning_
;
87
}
88
89
template
<
typename
GUM_SCALAR
>
90
INLINE
void
FMDPDatReader
<
GUM_SCALAR
>::
trace
(
bool
b
) {
91
_traceScanning_
=
b
;
92
scanner
().
setTrace
(
b
);
93
}
94
95
template
<
typename
GUM_SCALAR
>
96
Size
FMDPDatReader
<
GUM_SCALAR
>::
proceed
() {
97
if
(
_ioerror_
) {
GUM_ERROR
(
gum
::
IOError
,
"No such file "
+
streamName
()) }
98
99
if
(!
_parseDone_
) {
100
try
{
101
_parser_
->
Parse
();
102
_parseDone_
=
true
;
103
}
catch
(
gum
::
Exception
&
e
) {
104
GUM_SHOWERROR
(
e
);
105
return
1 +
_parser_
->
errors
().
error_count
;
106
}
107
}
108
109
return
(
_parser_
->
errors
().
error_count
);
110
}
111
112
/// @{
113
/// publishing Errors API
114
template
<
typename
GUM_SCALAR
>
115
INLINE
Idx
FMDPDatReader
<
GUM_SCALAR
>::
errLine
(
Idx
i
) {
116
if
(
_parseDone_
)
117
return
_parser_
->
errors
().
error
(
i
).
line
;
118
else
119
GUM_ERROR
(
OperationNotAllowed
,
"FMDPDat file not parsed yet"
)
120
}
121
122
template
<
typename
GUM_SCALAR
>
123
INLINE
Idx
FMDPDatReader
<
GUM_SCALAR
>::
errCol
(
Idx
i
) {
124
if
(
_parseDone_
)
125
return
_parser_
->
errors
().
error
(
i
).
column
;
126
else
127
GUM_ERROR
(
OperationNotAllowed
,
"FMDPDat file not parsed yet"
)
128
}
129
130
template
<
typename
GUM_SCALAR
>
131
INLINE
bool
FMDPDatReader
<
GUM_SCALAR
>::
errIsError
(
Idx
i
) {
132
if
(
_parseDone_
)
133
return
_parser_
->
errors
().
error
(
i
).
is_error
;
134
else
135
GUM_ERROR
(
OperationNotAllowed
,
"FMDPDat file not parsed yet"
)
136
}
137
138
template
<
typename
GUM_SCALAR
>
139
INLINE
std
::
string
FMDPDatReader
<
GUM_SCALAR
>::
errMsg
(
Idx
i
) {
140
if
(
_parseDone_
)
141
return
_parser_
->
errors
().
error
(
i
).
msg
;
142
else
143
GUM_ERROR
(
OperationNotAllowed
,
"FMDPDat file not parsed yet"
)
144
}
145
146
template
<
typename
GUM_SCALAR
>
147
INLINE
void
FMDPDatReader
<
GUM_SCALAR
>::
showElegantErrors
(
std
::
ostream
&
o
) {
148
if
(
_parseDone_
)
149
_parser_
->
errors
().
elegantErrors
(
o
);
150
else
151
GUM_ERROR
(
OperationNotAllowed
,
"FMDPDat file not parsed yet"
)
152
}
153
154
template
<
typename
GUM_SCALAR
>
155
INLINE
void
FMDPDatReader
<
GUM_SCALAR
>::
showElegantErrorsAndWarnings
(
std
::
ostream
&
o
) {
156
if
(
_parseDone_
)
157
_parser_
->
errors
().
elegantErrorsAndWarnings
(
o
);
158
else
159
GUM_ERROR
(
OperationNotAllowed
,
"FMDPDat file not parsed yet"
)
160
}
161
162
template
<
typename
GUM_SCALAR
>
163
INLINE
void
FMDPDatReader
<
GUM_SCALAR
>::
showErrorCounts
(
std
::
ostream
&
o
) {
164
if
(
_parseDone_
)
165
_parser_
->
errors
().
syntheticResults
(
o
);
166
else
167
GUM_ERROR
(
OperationNotAllowed
,
"FMDPDat file not parsed yet"
)
168
}
169
170
template
<
typename
GUM_SCALAR
>
171
INLINE
Size
FMDPDatReader
<
GUM_SCALAR
>::
errors
() {
172
return
(!
_parseDone_
) ? (
Size
)0 :
_parser_
->
errors
().
error_count
;
173
}
174
175
template
<
typename
GUM_SCALAR
>
176
INLINE
Size
FMDPDatReader
<
GUM_SCALAR
>::
warnings
() {
177
return
(!
_parseDone_
) ? (
Size
)0 :
_parser_
->
errors
().
warning_count
;
178
}
179
180
/// @}
181
}
// namespace gum
182
183
#
endif
// DOXYGEN_SHOULD_SKIP_THIS
gum::Set::emplace
INLINE void emplace(Args &&... args)
Definition:
set_tpl.h:643