aGrUM  0.13.2
netReader.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  ***************************************************************************/
20 #ifndef NETREADER_H
21 #define NETREADER_H
22 
23 #include <agrum/BN/BayesNet.h>
24 #include <agrum/BN/io/BNReader.h>
25 #include <agrum/agrum.h>
26 #include <iostream>
27 #include <string>
28 
29 #ifndef DOXYGEN_SHOULD_SKIP_THIS
30 // including coco-generated PARSER and SCANNER
31 # undef COCO_PARSER_H__
32 # undef COCO_SCANNER_H__
33 # include <agrum/BN/io/net/cocoR/Parser.h>
34 #endif // DOXYGEN_SHOULD_SKIP_THIS
35 
36 namespace gum {
37  /* =========================================================================*/
38  /* === READERS === */
39  /* =========================================================================*/
49  template < typename GUM_SCALAR >
50  class NetReader : public BNReader< GUM_SCALAR > {
51  public:
61  NetReader(BayesNet< GUM_SCALAR >* bn, const std::string& filename);
62 
66  ~NetReader() final;
67 
70  net::Scanner& scanner();
71 
73  const std::string& streamName() const;
74 
76  bool trace() const;
77  void trace(bool b);
78 
82  Size proceed() final;
83 
86 
88  Size errors();
90  Size warnings();
91 
93  Idx errLine(Idx i);
95  Idx errCol(Idx i);
97  bool errIsError(Idx i);
99  std::string errMsg(Idx i);
100 
102  void showElegantErrors(std::ostream& o = std::cerr);
103 
105  void showElegantErrorsAndWarnings(std::ostream& o = std::cerr);
106 
108  void showErrorsAndWarnings(std::ostream& o = std::cerr);
109 
111  void showErrorCounts(std::ostream& o = std::cerr);
113 
114  protected:
117  net::Scanner* __scanner;
118  net::Parser* __parser;
119 
120  std::string __streamName;
123 
124  // a boolean to throw the ioerror not in the constructor but in the
125  // proceed()
126  bool __ioerror;
127  };
128 
129 
130  extern template class NetReader< float >;
131  extern template class NetReader< double >;
132 
133 } /* namespace gum */
134 
135 #include "netReader_tpl.h"
136 
137 #endif // NETREADER_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
bool errIsError(Idx i)
type of ith error or warning
void showErrorsAndWarnings(std::ostream &o=std::cerr)
send on std::cerr the list of errors or warnings
BayesNet< GUM_SCALAR > * __bn
Definition: netReader.h:115
const std::string & streamName() const
name of readen file
net::Scanner * __scanner
Definition: netReader.h:117
Class representing Bayesian networks.
net::Parser * __parser
Definition: netReader.h:118
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
Pure virtual class for reading a BN from a file.
Definition: BNReader.h:52
Size warnings()
of errors
std::string errMsg(Idx i)
message of ith error or warning
BayesNetFactory< GUM_SCALAR > * __factory
Definition: netReader.h:116
Definition of abstract classes for file input manipulation of Bayesian Networks.
Size errors()
publishing Errors API
net::Scanner & scanner()
Direct access to DSL scanner (mandatory for listener connection)
std::string __streamName
Definition: netReader.h:120
void showErrorCounts(std::ostream &o=std::cerr)
send on std::cerr the number of errors and the number of warnings
~NetReader() final
Default destructor.
Size proceed() final
parse.
Pure virtual class for reading a BN from a file.
Definition: netReader.h:50
void showElegantErrorsAndWarnings(std::ostream &o=std::cerr)
send on std::cerr the list of errors or warnings with contents
bool __parseDone
Definition: netReader.h:122
bool __traceScanning
Definition: netReader.h:121
bool trace() const
accessor to trace function (just write the number of parser line)
void showElegantErrors(std::ostream &o=std::cerr)
send on std::cerr the list of errorswith contents
unsigned long Idx
Type for indexes.
Definition: types.h:43
NetReader(BayesNet< GUM_SCALAR > *bn, const std::string &filename)
Constructor A reader is defined for reading a defined file.
Idx errCol(Idx i)
col of ith error or warning
A factory class to ease BayesNet construction.
Definition: BayesNet.h:43
Idx errLine(Idx i)
line of ith error or warning