aGrUM  0.14.1
DSLReader.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 DSLREADER_H
21 #define DSLREADER_H
22 
23 #include <agrum/BN/IBayesNet.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 
32 # include <agrum/BN/io/DSL/cocoR/Parser.h>
33 #endif // DOXYGEN_SHOULD_SKIP_THIS
34 
35 namespace gum {
36  /* =========================================================================*/
37  /* === READERS === */
38  /* =========================================================================*/
48  template < typename GUM_SCALAR >
49  class DSLReader : public BNReader< GUM_SCALAR > {
50  public:
60  DSLReader(BayesNet< GUM_SCALAR >* bn, const std::string& filename);
61 
65  ~DSLReader() final;
66 
69  DSL::Scanner& scanner();
70 
72  const std::string& streamName() const;
73 
75  bool trace() const;
76  void trace(bool b);
77 
81  Size proceed() final;
82 
85 
87  Size errors();
89  Size warnings();
90 
92  Idx errLine(Idx i);
94  Idx errCol(Idx i);
96  bool errIsError(Idx i);
98  std::string errMsg(Idx i);
99 
101  void showElegantErrors(std::ostream& o = std::cerr);
102 
104  void showElegantErrorsAndWarnings(std::ostream& o = std::cerr);
105 
107  void showErrorsAndWarnings(std::ostream& o = std::cerr);
108 
110  void showErrorCounts(std::ostream& o = std::cerr);
112 
113  protected:
116  DSL::Scanner* __scanner;
117  DSL::Parser* __parser;
118 
119  std::string __streamName;
122 
123  // a boolean to throw the ioerror not in the constructor but in the
124  // proceed()
125  bool __ioerror;
126  };
127 
128 
129 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
130  extern template class DSLReader< double >;
131 #endif
132 
133 } /* namespace gum */
134 
135 #include "DSLReader_tpl.h"
136 
137 #endif // DSLREADER_H
Class representing a Bayesian Network.
Definition: BayesNet.h:76
Size errors()
publishing Errors API
DSL::Parser * __parser
Definition: DSLReader.h:117
void showErrorCounts(std::ostream &o=std::cerr)
send on std::cerr the number of errors and the number of warnings
bool errIsError(Idx i)
type of ith error or warning
Class representing Bayesian networks.
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
Idx errLine(Idx i)
line of ith error or warning
Pure virtual class for reading a BN from a file.
Definition: BNReader.h:52
Pure virtual class for reading a BN from a file.
Definition: DSLReader.h:49
bool __traceScanning
Definition: DSLReader.h:120
Definition of abstract classes for file input manipulation of Bayesian Networks.
const std::string & streamName() const
name of readen file
std::string errMsg(Idx i)
message of ith error or warning
DSL::Scanner * __scanner
Definition: DSLReader.h:116
bool trace() const
accessor to trace function (just write the number of parser line)
~DSLReader() final
Default destructor.
std::string __streamName
Definition: DSLReader.h:119
void showErrorsAndWarnings(std::ostream &o=std::cerr)
send on std::cerr the list of errors or warnings
DSL::Scanner & scanner()
Direct access to DSL scanner (mandatory for listener connection)
bool __parseDone
Definition: DSLReader.h:121
Idx errCol(Idx i)
col of ith error or warning
Size proceed() final
parse.
void showElegantErrorsAndWarnings(std::ostream &o=std::cerr)
send on std::cerr the list of errors or warnings with contents
Size Idx
Type for indexes.
Definition: types.h:50
BayesNet< GUM_SCALAR > * __bn
Definition: DSLReader.h:114
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45
Size warnings()
of errors
DSLReader(BayesNet< GUM_SCALAR > *bn, const std::string &filename)
Constructor A reader is defined for reading a defined file.
void showElegantErrors(std::ostream &o=std::cerr)
send on std::cerr the list of errorswith contents
A factory class to ease BayesNet construction.
Definition: BayesNet.h:43
BayesNetFactory< GUM_SCALAR > * __factory
Definition: DSLReader.h:115