43#ifndef DOXYGEN_SHOULD_SKIP_THIS
49 template <
typename GUM_SCALAR >
51 BNReader< GUM_SCALAR >(bn, filename) {
52 GUM_CONSTRUCTOR(DSLReader);
54 _streamName_ = filename;
57 _factory_ =
new BayesNetFactory< GUM_SCALAR >(_bn_);
62 _scanner_ =
new DSL::Scanner(_streamName_.c_str());
63 _parser_ =
new DSL::Parser(_scanner_);
64 _parser_->setFactory((IBayesNetFactory*)_factory_);
65 }
catch (
IOError const&) { _ioerror_ =
true; }
68 template <
typename GUM_SCALAR >
69 DSLReader< GUM_SCALAR >::~DSLReader() {
70 GUM_DESTRUCTOR(DSLReader);
74 if (_parser_)
delete (_parser_);
76 if (_scanner_)
delete (_scanner_);
79 if (_factory_)
delete (_factory_);
82 template <
typename GUM_SCALAR >
83 INLINE DSL::Scanner& DSLReader< GUM_SCALAR >::scanner() {
84 if (_ioerror_) {
GUM_ERROR(gum::IOError,
"No such file " + streamName()) }
89 template <
typename GUM_SCALAR >
90 INLINE
const std::string& DSLReader< GUM_SCALAR >::streamName()
const {
94 template <
typename GUM_SCALAR >
95 INLINE
bool DSLReader< GUM_SCALAR >::trace()
const {
96 return _traceScanning_;
99 template <
typename GUM_SCALAR >
100 INLINE
void DSLReader< GUM_SCALAR >::trace(
bool b) {
102 scanner().setTrace(b);
105 template <
typename 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 <
typename GUM_SCALAR >
125 INLINE Idx DSLReader< GUM_SCALAR >::errLine(Idx i) {
126 if (_parseDone_)
return _parser_->errors().error(i).line;
130 template <
typename GUM_SCALAR >
131 INLINE Idx DSLReader< GUM_SCALAR >::errCol(Idx i) {
132 if (_parseDone_)
return _parser_->errors().error(i).column;
136 template <
typename GUM_SCALAR >
137 INLINE
bool DSLReader< GUM_SCALAR >::errIsError(Idx i) {
138 if (_parseDone_)
return _parser_->errors().error(i).is_error;
142 template <
typename GUM_SCALAR >
143 INLINE std::string DSLReader< GUM_SCALAR >::errMsg(Idx i) {
144 if (_parseDone_)
return _parser_->errors().error(i).msg;
148 template <
typename GUM_SCALAR >
149 INLINE
void DSLReader< GUM_SCALAR >::showElegantErrors(std::ostream& o) {
150 if (_parseDone_) _parser_->errors().elegantErrors(o);
154 template <
typename GUM_SCALAR >
155 INLINE
void DSLReader< GUM_SCALAR >::showElegantErrorsAndWarnings(std::ostream& o) {
156 if (_parseDone_) _parser_->errors().elegantErrorsAndWarnings(o);
160 template <
typename GUM_SCALAR >
161 INLINE
void DSLReader< GUM_SCALAR >::showErrorsAndWarnings(std::ostream& o) {
162 if (_parseDone_) _parser_->errors().simpleErrorsAndWarnings(o);
166 template <
typename GUM_SCALAR >
167 INLINE
void DSLReader< GUM_SCALAR >::showErrorCounts(std::ostream& o) {
168 if (_parseDone_) _parser_->errors().syntheticResults(o);
172 template <
typename GUM_SCALAR >
173 INLINE Size DSLReader< GUM_SCALAR >::errors() {
174 return (!_parseDone_) ? (Size)0 : _parser_->errors().error_count;
177 template <
typename GUM_SCALAR >
178 INLINE 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, const std::string &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