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