aGrUM  0.13.2
BIFReader.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Pierre-Henri WUILLEMIN et Christophe GONZALES *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
62 #ifndef BIF_READER_H
63 #define BIF_READER_H
64 
65 #include <fstream>
66 #include <iostream>
67 #include <string>
68 
70 #include <agrum/BN/IBayesNet.h>
71 #include <agrum/BN/io/BNReader.h>
72 
73 #ifndef DOXYGEN_SHOULD_SKIP_THIS
74 // including coco-generated PARSER and SCANNER
75 # include <agrum/BN/io/BIF/cocoR/Parser.h>
76 #endif // DOXYGEN_SHOULD_SKIP_THIS
77 
78 namespace gum {
122  template < typename GUM_SCALAR >
123  class BIFReader : public BNReader< GUM_SCALAR > {
124  public:
125  BIFReader(BayesNet< GUM_SCALAR >* bn, const std::string& filename);
126 
127  ~BIFReader() final;
128 
131  BIF::Scanner& scanner();
132 
134  const std::string& streamName() const;
135 
137  bool trace() const;
138  void trace(bool b);
139 
143  Size proceed() final;
144 
147 
149  Size errors();
151  Size warnings();
152 
154  Idx errLine(Idx i);
156  Idx errCol(Idx i);
158  bool errIsError(Idx i);
160  std::string errMsg(Idx i);
161 
163  void showElegantErrors(std::ostream& o = std::cerr);
164 
166  void showElegantErrorsAndWarnings(std::ostream& o = std::cerr);
167 
169  void showErrorCounts(std::ostream& o = std::cerr);
171 
172  protected:
175  BIF::Scanner* __scanner;
176  BIF::Parser* __parser;
177 
178  std::string __streamName;
181 
182  // a boolean to throw the ioerror not in the constructor but in the
183  // proceed()
184  bool __ioerror;
185  };
186 
187 
188  extern template class BIFReader< float >;
189  extern template class BIFReader< double >;
190 
191 } // namespace gum
192 
194 
195 #endif // BIF_READER_H
Class representing a Bayesian Network.
Definition: BayesNet.h:76
unsigned long Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:50
BayesNet< GUM_SCALAR > * __bn
Definition: BIFReader.h:173
bool errIsError(Idx i)
type of ith error or warning
std::string errMsg(Idx i)
message of ith error or warning
BayesNetFactory< GUM_SCALAR > * __factory
Definition: BIFReader.h:174
void showErrorCounts(std::ostream &o=std::cerr)
send on std::cerr the number of errors and the number of warnings
BIF::Parser * __parser
Definition: BIFReader.h:176
Class representing Bayesian networks.
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
void showElegantErrors(std::ostream &o=std::cerr)
send on std::cerr the list of errors
Pure virtual class for reading a BN from a file.
Definition: BNReader.h:52
bool trace() const
accessor to trace function (just write the number of parser line)
Size proceed() final
parse.
const std::string & streamName() const
name of readen file
BIF::Scanner * __scanner
Definition: BIFReader.h:175
Definition of abstract classes for file input manipulation of Bayesian Networks.
~BIFReader() final
Headers of the BayesNetFactory class.
Idx errCol(Idx i)
col of ith error or warning
Definition of templatized reader of BIF files for Bayesian Networks.
bool __parseDone
Definition: BIFReader.h:180
std::string __streamName
Definition: BIFReader.h:178
Definition of templatized reader of BIF files for Bayesian Networks.
Definition: BIFReader.h:123
Size warnings()
of errors
Size errors()
publishing Errors API
BIF::Scanner & scanner()
Direct access to BIF scanner (mandatory for listener connection)
bool __traceScanning
Definition: BIFReader.h:179
unsigned long Idx
Type for indexes.
Definition: types.h:43
Idx errLine(Idx i)
line of ith error or warning
A factory class to ease BayesNet construction.
Definition: BayesNet.h:43
BIFReader(BayesNet< GUM_SCALAR > *bn, const std::string &filename)
void showElegantErrorsAndWarnings(std::ostream &o=std::cerr)
send on std::cerr the list of errors or warnings