aGrUM
0.20.2
a C++ library for (probabilistic) graphical models
fmdpDatReader_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
/**
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
156
FMDPDatReader
<
GUM_SCALAR
>::
showElegantErrorsAndWarnings
(
std
::
ostream
&
o
) {
157
if
(
parseDone__
)
158
parser__
->
errors
().
elegantErrorsAndWarnings
(
o
);
159
else
160
GUM_ERROR
(
OperationNotAllowed
,
"FMDPDat file not parsed yet"
);
161
}
162
163
template
<
typename
GUM_SCALAR
>
164
INLINE
void
FMDPDatReader
<
GUM_SCALAR
>::
showErrorCounts
(
std
::
ostream
&
o
) {
165
if
(
parseDone__
)
166
parser__
->
errors
().
syntheticResults
(
o
);
167
else
168
GUM_ERROR
(
OperationNotAllowed
,
"FMDPDat file not parsed yet"
);
169
}
170
171
template
<
typename
GUM_SCALAR
>
172
INLINE
Size
FMDPDatReader
<
GUM_SCALAR
>::
errors
() {
173
return
(!
parseDone__
) ? (
Size
)0 :
parser__
->
errors
().
error_count
;
174
}
175
176
template
<
typename
GUM_SCALAR
>
177
INLINE
Size
FMDPDatReader
<
GUM_SCALAR
>::
warnings
() {
178
return
(!
parseDone__
) ? (
Size
)0 :
parser__
->
errors
().
warning_count
;
179
}
180
181
/// @}
182
}
// namespace gum
183
184
#
endif
// DOXYGEN_SHOULD_SKIP_THIS
gum::Set::emplace
INLINE void emplace(Args &&... args)
Definition:
set_tpl.h:669