45#ifndef DOXYGEN_SHOULD_SKIP_THIS
51 template < GUM_Numeric GUM_SCALAR >
53 BNReader< GUM_SCALAR >(bn, filename) {
54 GUM_CONSTRUCTOR(DSLReader);
56 _streamName_ = filename;
59 _factory_ =
new BayesNetFactory< GUM_SCALAR >(_bn_);
64 _scanner_ =
new DSL::Scanner(_streamName_.c_str());
65 _parser_ =
new DSL::Parser(_scanner_);
66 _parser_->setFactory((IBayesNetFactory*)_factory_);
67 }
catch (
IOError const&) { _ioerror_ =
true; }
70 template < GUM_Numeric GUM_SCALAR >
71 DSLReader< GUM_SCALAR >::~DSLReader() {
72 GUM_DESTRUCTOR(DSLReader);
82 template < GUM_Numeric GUM_SCALAR >
83 DSL::Scanner& DSLReader< GUM_SCALAR >::scanner() {
84 if (_ioerror_) {
GUM_ERROR(gum::IOError,
"No such file " + streamName()) }
89 template < GUM_Numeric GUM_SCALAR >
90 const std::string& DSLReader< GUM_SCALAR >::streamName()
const {
94 template < GUM_Numeric GUM_SCALAR >
95 bool DSLReader< GUM_SCALAR >::trace()
const {
96 return _traceScanning_;
99 template < GUM_Numeric GUM_SCALAR >
100 void DSLReader< GUM_SCALAR >::trace(
bool b) {
102 scanner().setTrace(b);
105 template < GUM_Numeric GUM_SCALAR >
106 Size DSLReader< GUM_SCALAR >::proceed() {
107 if (_ioerror_) {
GUM_ERROR(gum::IOError,
"No such file " + streamName()) }
115 return 1 + _parser_->errors().error_count;
119 return (_parser_->errors().error_count);
124 template < GUM_Numeric GUM_SCALAR >
125 Idx DSLReader< GUM_SCALAR >::errLine(Idx i) {
126 if (_parseDone_)
return _parser_->errors().error(i).line;
130 template < GUM_Numeric GUM_SCALAR >
131 Idx DSLReader< GUM_SCALAR >::errCol(Idx i) {
132 if (_parseDone_)
return _parser_->errors().error(i).column;
136 template < GUM_Numeric GUM_SCALAR >
137 bool DSLReader< GUM_SCALAR >::errIsError(Idx i) {
138 if (_parseDone_)
return _parser_->errors().error(i).is_error;
142 template < GUM_Numeric GUM_SCALAR >
143 std::string DSLReader< GUM_SCALAR >::errMsg(Idx i) {
144 if (_parseDone_)
return _parser_->errors().error(i).msg;
148 template < GUM_Numeric GUM_SCALAR >
149 void DSLReader< GUM_SCALAR >::showElegantErrors(std::ostream& o) {
150 if (_parseDone_) _parser_->errors().elegantErrors(o);
154 template < GUM_Numeric GUM_SCALAR >
155 void DSLReader< GUM_SCALAR >::showElegantErrorsAndWarnings(std::ostream& o) {
156 if (_parseDone_) _parser_->errors().elegantErrorsAndWarnings(o);
160 template < GUM_Numeric GUM_SCALAR >
161 void DSLReader< GUM_SCALAR >::showErrorsAndWarnings(std::ostream& o) {
162 if (_parseDone_) _parser_->errors().simpleErrorsAndWarnings(o);
166 template < GUM_Numeric GUM_SCALAR >
167 void DSLReader< GUM_SCALAR >::showErrorCounts(std::ostream& o) {
168 if (_parseDone_) _parser_->errors().syntheticResults(o);
172 template < GUM_Numeric GUM_SCALAR >
173 Size DSLReader< GUM_SCALAR >::errors() {
174 return (!_parseDone_) ? (Size)0 : _parser_->errors().error_count;
177 template < GUM_Numeric GUM_SCALAR >
178 Size DSLReader< GUM_SCALAR >::warnings() {
179 return (!_parseDone_) ? (Size)0 : _parser_->errors().warning_count;
Pure virtual class for reading a BN from a file.
Class representing a Bayesian network.
DSLReader(BayesNet< GUM_SCALAR > *bn, std::string_view filename)
Constructor A reader is defined for reading a defined file.
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