45#ifndef DOXYGEN_SHOULD_SKIP_THIS
51 template < GUM_Numeric GUM_SCALAR >
53 BNReader< GUM_SCALAR >(bn, filename) {
54 GUM_CONSTRUCTOR(NetReader);
56 _streamName_ = filename;
59 _factory_ =
new BayesNetFactory< GUM_SCALAR >(_bn_);
64 _scanner_ =
new net::Scanner(_streamName_.c_str());
65 _parser_ =
new net::Parser(_scanner_);
66 _parser_->setFactory((IBayesNetFactory*)_factory_);
67 }
catch (
IOError const&) { _ioerror_ =
true; }
70 template < GUM_Numeric GUM_SCALAR >
71 NetReader< GUM_SCALAR >::~NetReader() {
72 GUM_DESTRUCTOR(NetReader);
76 if (_parser_)
delete (_parser_);
78 if (_scanner_)
delete (_scanner_);
81 if (_factory_)
delete (_factory_);
84 template < GUM_Numeric GUM_SCALAR >
85 net::Scanner& NetReader< GUM_SCALAR >::scanner() {
86 if (_ioerror_) {
GUM_ERROR(gum::IOError,
"No such file " + streamName()) }
91 template < GUM_Numeric GUM_SCALAR >
92 const std::string& NetReader< GUM_SCALAR >::streamName()
const {
96 template < GUM_Numeric GUM_SCALAR >
97 bool NetReader< GUM_SCALAR >::trace()
const {
98 return _traceScanning_;
101 template < GUM_Numeric GUM_SCALAR >
102 void NetReader< GUM_SCALAR >::trace(
bool b) {
104 scanner().setTrace(b);
107 template < GUM_Numeric GUM_SCALAR >
108 Size NetReader< GUM_SCALAR >::proceed() {
109 if (_ioerror_) {
GUM_ERROR(gum::IOError,
"No such file " + streamName()) }
116 return 1 + _parser_->errors().error_count;
122 return (_parser_->errors().error_count);
127 template < GUM_Numeric GUM_SCALAR >
128 Idx NetReader< GUM_SCALAR >::errLine(Idx i) {
129 if (_parseDone_)
return _parser_->errors().error(i).line;
133 template < GUM_Numeric GUM_SCALAR >
134 Idx NetReader< GUM_SCALAR >::errCol(Idx i) {
135 if (_parseDone_)
return _parser_->errors().error(i).column;
139 template < GUM_Numeric GUM_SCALAR >
140 bool NetReader< GUM_SCALAR >::errIsError(Idx i) {
141 if (_parseDone_)
return _parser_->errors().error(i).is_error;
145 template < GUM_Numeric GUM_SCALAR >
146 std::string NetReader< GUM_SCALAR >::errMsg(Idx i) {
147 if (_parseDone_)
return _parser_->errors().error(i).msg;
151 template < GUM_Numeric GUM_SCALAR >
152 void NetReader< GUM_SCALAR >::showElegantErrors(std::ostream& o) {
153 if (_parseDone_) _parser_->errors().elegantErrors(o);
157 template < GUM_Numeric GUM_SCALAR >
158 void NetReader< GUM_SCALAR >::showElegantErrorsAndWarnings(std::ostream& o) {
159 if (_parseDone_) _parser_->errors().elegantErrorsAndWarnings(o);
163 template < GUM_Numeric GUM_SCALAR >
164 void NetReader< GUM_SCALAR >::showErrorsAndWarnings(std::ostream& o) {
165 if (_parseDone_) _parser_->errors().simpleErrorsAndWarnings(o);
169 template < GUM_Numeric GUM_SCALAR >
170 void NetReader< GUM_SCALAR >::showErrorCounts(std::ostream& o) {
171 if (_parseDone_) _parser_->errors().syntheticResults(o);
175 template < GUM_Numeric GUM_SCALAR >
176 Size NetReader< GUM_SCALAR >::errors() {
177 return (!_parseDone_) ? (Size)0 : _parser_->errors().error_count;
180 template < GUM_Numeric GUM_SCALAR >
181 Size NetReader< GUM_SCALAR >::warnings() {
182 return (!_parseDone_) ? (Size)0 : _parser_->errors().warning_count;
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.
NetReader(BayesNet< GUM_SCALAR > *bn, std::string_view filename)
Constructor A reader is defined for reading a defined file.
Exception : operation not allowed.
#define GUM_ERROR(type, msg)
gum is the global namespace for all aGrUM entities