55#ifndef DOXYGEN_SHOULD_SKIP_THIS
59 template < GUM_Numeric GUM_SCALAR >
61 BNReader< GUM_SCALAR >(bn, filename) {
62 GUM_CONSTRUCTOR(BIFReader);
64 _streamName_ = filename;
67 _factory_ =
new BayesNetFactory< GUM_SCALAR >(_bn_);
72 _scanner_ =
new BIF::Scanner(_streamName_.c_str());
73 _parser_ =
new BIF::Parser(_scanner_);
74 _parser_->setFactory(
static_cast< IBayesNetFactory*
>(_factory_));
75 }
catch (
IOError const&) { _ioerror_ =
true; }
78 template < GUM_Numeric GUM_SCALAR >
79 BIFReader< GUM_SCALAR >::~BIFReader() {
80 GUM_DESTRUCTOR(BIFReader);
84 if (_parser_)
delete (_parser_);
86 if (_scanner_)
delete (_scanner_);
89 if (_factory_)
delete (_factory_);
92 template < GUM_Numeric GUM_SCALAR >
93 BIF::Scanner& BIFReader< GUM_SCALAR >::scanner() {
94 if (_ioerror_) {
GUM_ERROR(gum::IOError,
"No such file " + streamName()) }
99 template < GUM_Numeric GUM_SCALAR >
100 const std::string& BIFReader< GUM_SCALAR >::streamName()
const {
104 template < GUM_Numeric GUM_SCALAR >
105 bool BIFReader< GUM_SCALAR >::trace()
const {
106 return _traceScanning_;
109 template < GUM_Numeric GUM_SCALAR >
110 void BIFReader< GUM_SCALAR >::trace(
bool b) {
112 scanner().setTrace(b);
115 template < GUM_Numeric GUM_SCALAR >
116 Size BIFReader< GUM_SCALAR >::proceed() {
117 if (_ioerror_) {
GUM_ERROR(gum::IOError,
"No such file " + streamName()) }
125 return 1 + _parser_->errors().error_count;
129 return (_parser_->errors().error_count);
134 template < GUM_Numeric GUM_SCALAR >
135 Idx BIFReader< GUM_SCALAR >::errLine(Idx i)
const {
136 if (_parseDone_)
return _parser_->errors().error(i).line;
140 template < GUM_Numeric GUM_SCALAR >
141 Idx BIFReader< GUM_SCALAR >::errCol(Idx i)
const {
142 if (_parseDone_)
return _parser_->errors().error(i).column;
146 template < GUM_Numeric GUM_SCALAR >
147 bool BIFReader< GUM_SCALAR >::errIsError(Idx i)
const {
148 if (_parseDone_)
return _parser_->errors().error(i).is_error;
152 template < GUM_Numeric GUM_SCALAR >
153 std::string BIFReader< GUM_SCALAR >::errMsg(Idx i)
const {
154 if (_parseDone_)
return _parser_->errors().error(i).msg;
158 template < GUM_Numeric GUM_SCALAR >
159 void BIFReader< GUM_SCALAR >::showElegantErrors(std::ostream& o)
const {
160 if (_parseDone_) _parser_->errors().elegantErrors(o);
164 template < GUM_Numeric GUM_SCALAR >
165 void BIFReader< GUM_SCALAR >::showElegantErrorsAndWarnings(std::ostream& o)
const {
166 if (_parseDone_) _parser_->errors().elegantErrorsAndWarnings(o);
170 template < GUM_Numeric GUM_SCALAR >
171 void BIFReader< GUM_SCALAR >::showErrorCounts(std::ostream& o)
const {
172 if (_parseDone_) _parser_->errors().syntheticResults(o);
176 template < GUM_Numeric GUM_SCALAR >
177 Size BIFReader< GUM_SCALAR >::errors()
const {
178 return (!_parseDone_) ? (Size)0 : _parser_->errors().error_count;
181 template < GUM_Numeric GUM_SCALAR >
182 Size BIFReader< GUM_SCALAR >::warnings()
const {
183 return (!_parseDone_) ? (Size)0 : _parser_->errors().warning_count;
Definition of templatized reader of BIF files for Bayesian networks.
Definition of abstract classes for file input manipulation of Bayesian networks.
BIFReader(BayesNet< GUM_SCALAR > *bn, std::string_view filename)
Pure virtual class for reading a BN from a file.
Class representing a Bayesian network.
Base class for all aGrUM's exceptions.
Exception : input/output problem.
Exception : operation not allowed.
#define GUM_ERROR(type, msg)
gum is the global namespace for all aGrUM entities