aGrUM
0.20.2
a C++ library for (probabilistic) graphical models
Main Page
Related Pages
Modules
+
Namespaces
Namespace List
+
Namespace Members
+
All
_
a
b
c
d
e
f
g
h
i
j
l
m
n
o
p
r
s
t
v
w
+
Functions
_
a
b
c
d
e
f
g
h
i
l
m
n
o
p
r
s
t
v
Variables
Typedefs
Enumerations
+
Enumerator
a
c
e
f
g
h
i
l
p
s
t
w
+
Classes
Class List
Class Index
Class Hierarchy
+
Class Members
+
All
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
+
Functions
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
~
+
Variables
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
+
Typedefs
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
v
+
Enumerations
a
b
c
e
f
i
k
l
n
p
r
s
t
+
Enumerator
a
b
c
d
e
f
i
l
m
n
o
p
r
s
t
u
v
+
Related Functions
b
c
d
f
g
h
l
m
n
o
p
r
s
t
+
Files
File List
+
File Members
+
All
a
b
d
e
f
g
i
l
m
n
o
r
s
t
u
v
w
Functions
Variables
Enumerations
Enumerator
+
Macros
a
b
d
e
f
g
i
l
m
r
s
t
u
v
netReader_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
/
net
/
netReader
.
h
>
25
26
namespace
gum
{
27
28
template
<
typename
GUM_SCALAR >
29
NetReader< GUM_SCALAR >::NetReader(
BayesNet
<
GUM_SCALAR
>*
bn
,
30
const
std
::
string
&
filename
) :
31
BNReader
<
GUM_SCALAR
>(
bn
,
filename
) {
32
GUM_CONSTRUCTOR
(
NetReader
);
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
net
::
Scanner
(
streamName__
.
c_str
());
43
parser__
=
new
net
::
Parser
(
scanner__
);
44
parser__
->
setFactory
((
IBayesNetFactory
*)
factory__
);
45
}
catch
(
IOError
&) {
ioerror__
=
true
; }
46
}
47
48
template
<
typename
GUM_SCALAR
>
49
NetReader
<
GUM_SCALAR
>::~
NetReader
() {
50
GUM_DESTRUCTOR
(
NetReader
);
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
net
::
Scanner
&
NetReader
<
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
&
NetReader
<
GUM_SCALAR
>::
streamName
()
const
{
71
return
streamName__
;
72
}
73
74
template
<
typename
GUM_SCALAR
>
75
INLINE
bool
NetReader
<
GUM_SCALAR
>::
trace
()
const
{
76
return
traceScanning__
;
77
}
78
79
template
<
typename
GUM_SCALAR
>
80
INLINE
void
NetReader
<
GUM_SCALAR
>::
trace
(
bool
b
) {
81
traceScanning__
=
b
;
82
scanner
().
setTrace
(
b
);
83
}
84
85
template
<
typename
GUM_SCALAR
>
86
Size
NetReader
<
GUM_SCALAR
>::
proceed
() {
87
if
(
ioerror__
) {
GUM_ERROR
(
gum
::
IOError
,
"No such file "
+
streamName
()); }
88
89
if
(!
parseDone__
) {
90
try
{
91
parser__
->
Parse
();
92
}
catch
(
gum
::
Exception
&
e
) {
93
GUM_SHOWERROR
(
e
);
94
return
1 +
parser__
->
errors
().
error_count
;
95
}
96
97
parseDone__
=
true
;
98
}
99
100
return
(
parser__
->
errors
().
error_count
);
101
}
102
103
// @{
104
// publishing Errors API
105
template
<
typename
GUM_SCALAR
>
106
INLINE
Idx
NetReader
<
GUM_SCALAR
>::
errLine
(
Idx
i
) {
107
if
(
parseDone__
)
108
return
parser__
->
errors
().
error
(
i
).
line
;
109
else
{
110
GUM_ERROR
(
OperationNotAllowed
,
"Net file not parsed yet"
);
111
}
112
}
113
114
template
<
typename
GUM_SCALAR
>
115
INLINE
Idx
NetReader
<
GUM_SCALAR
>::
errCol
(
Idx
i
) {
116
if
(
parseDone__
)
117
return
parser__
->
errors
().
error
(
i
).
column
;
118
else
{
119
GUM_ERROR
(
OperationNotAllowed
,
"Net file not parsed yet"
);
120
}
121
}
122
123
template
<
typename
GUM_SCALAR
>
124
INLINE
bool
NetReader
<
GUM_SCALAR
>::
errIsError
(
Idx
i
) {
125
if
(
parseDone__
)
126
return
parser__
->
errors
().
error
(
i
).
is_error
;
127
else
{
128
GUM_ERROR
(
OperationNotAllowed
,
"Net file not parsed yet"
);
129
}
130
}
131
132
template
<
typename
GUM_SCALAR
>
133
INLINE
std
::
string
NetReader
<
GUM_SCALAR
>::
errMsg
(
Idx
i
) {
134
if
(
parseDone__
)
135
return
parser__
->
errors
().
error
(
i
).
msg
;
136
else
{
137
GUM_ERROR
(
OperationNotAllowed
,
"Net file not parsed yet"
);
138
}
139
}
140
141
template
<
typename
GUM_SCALAR
>
142
INLINE
void
NetReader
<
GUM_SCALAR
>::
showElegantErrors
(
std
::
ostream
&
o
) {
143
if
(
parseDone__
)
144
parser__
->
errors
().
elegantErrors
(
o
);
145
else
{
146
GUM_ERROR
(
OperationNotAllowed
,
"Net file not parsed yet"
);
147
}
148
}
149
150
template
<
typename
GUM_SCALAR
>
151
INLINE
void
152
NetReader
<
GUM_SCALAR
>::
showElegantErrorsAndWarnings
(
std
::
ostream
&
o
) {
153
if
(
parseDone__
)
154
parser__
->
errors
().
elegantErrorsAndWarnings
(
o
);
155
else
{
156
GUM_ERROR
(
OperationNotAllowed
,
"Net file not parsed yet"
);
157
}
158
}
159
160
template
<
typename
GUM_SCALAR
>
161
INLINE
void
NetReader
<
GUM_SCALAR
>::
showErrorsAndWarnings
(
std
::
ostream
&
o
) {
162
if
(
parseDone__
)
163
parser__
->
errors
().
simpleErrorsAndWarnings
(
o
);
164
else
{
165
GUM_ERROR
(
OperationNotAllowed
,
"Net file not parsed yet"
);
166
}
167
}
168
169
template
<
typename
GUM_SCALAR
>
170
INLINE
void
NetReader
<
GUM_SCALAR
>::
showErrorCounts
(
std
::
ostream
&
o
) {
171
if
(
parseDone__
)
172
parser__
->
errors
().
syntheticResults
(
o
);
173
else
{
174
GUM_ERROR
(
OperationNotAllowed
,
"Net file not parsed yet"
);
175
}
176
}
177
178
template
<
typename
GUM_SCALAR
>
179
INLINE
Size
NetReader
<
GUM_SCALAR
>::
errors
() {
180
return
(!
parseDone__
) ? (
Size
)0 :
parser__
->
errors
().
error_count
;
181
}
182
183
template
<
typename
GUM_SCALAR
>
184
INLINE
Size
NetReader
<
GUM_SCALAR
>::
warnings
() {
185
return
(!
parseDone__
) ? (
Size
)0 :
parser__
->
errors
().
warning_count
;
186
}
187
188
// @}
189
}
// namespace gum
190
191
#
endif
// DOXYGEN_SHOULD_SKIP_THIS
gum::Set::emplace
INLINE void emplace(Args &&... args)
Definition:
set_tpl.h:669