aGrUM  0.16.0
fmdpDatReader_tpl.h
Go to the documentation of this file.
1 
31 #ifndef DOXYGEN_SHOULD_SKIP_THIS
32 
34 
35 namespace gum {
36 
37  template < typename GUM_SCALAR >
38  FMDPDatReader< GUM_SCALAR >::FMDPDatReader(FMDP< GUM_SCALAR >* fmdp,
39  const std::string& filename) :
40  FMDPReader< GUM_SCALAR >(fmdp, filename) {
41  GUM_CONSTRUCTOR(FMDPDatReader);
42 
43  __fmdp = fmdp;
44  __streamName = filename;
45  __parseDone = false;
46  // ddf->putOnNoVariableCheckMode();
47  __factory = new FMDPFactory< GUM_SCALAR >(__fmdp);
48  //~ __factory->setVerbose();
49  __ioerror = false;
50 
51  try {
52  __scanner = new MDPDAT::Scanner(__streamName.c_str());
53  __parser = new MDPDAT::Parser(__scanner);
54  __parser->setFactory((AbstractFMDPFactory*)__factory);
55  } catch (IOError e) { __ioerror = true; }
56  }
57 
58  template < typename GUM_SCALAR >
60  GUM_DESTRUCTOR(FMDPDatReader);
61 
62  if (!__ioerror) {
63  // this could lead to memory leak !!
64  if (__parser) delete (__parser);
65 
66  if (__scanner) delete (__scanner);
67  }
68 
69  if (__factory) delete (__factory);
70  }
71 
72  template < typename GUM_SCALAR >
73  INLINE MDPDAT::Scanner& FMDPDatReader< GUM_SCALAR >::scanner() {
74  if (__ioerror) { GUM_ERROR(gum::IOError, "No such file " + streamName()); }
75 
76  return *__scanner;
77  }
78 
79  template < typename GUM_SCALAR >
80  INLINE const std::string& FMDPDatReader< GUM_SCALAR >::streamName() const {
81  return __streamName;
82  }
83 
84  template < typename GUM_SCALAR >
85  INLINE bool FMDPDatReader< GUM_SCALAR >::trace() const {
86  return __traceScanning;
87  }
88 
89  template < typename GUM_SCALAR >
90  INLINE void FMDPDatReader< GUM_SCALAR >::trace(bool b) {
91  __traceScanning = b;
92  scanner().setTrace(b);
93  }
94 
95  template < typename GUM_SCALAR >
97  if (__ioerror) { GUM_ERROR(gum::IOError, "No such file " + streamName()); }
98 
99  if (!__parseDone) {
100  try {
101  __parser->Parse();
102  __parseDone = true;
103  } catch (gum::Exception& e) {
104  GUM_SHOWERROR(e);
105  return 1 + __parser->errors().error_count;
106  }
107  }
108 
109  return (__parser->errors().error_count);
110  }
111 
114  template < typename GUM_SCALAR >
116  if (__parseDone)
117  return __parser->errors().error(i).line;
118  else
119  GUM_ERROR(OperationNotAllowed, "FMDPDat file not parsed yet");
120  }
121 
122  template < typename GUM_SCALAR >
124  if (__parseDone)
125  return __parser->errors().error(i).column;
126  else
127  GUM_ERROR(OperationNotAllowed, "FMDPDat file not parsed yet");
128  }
129 
130  template < typename GUM_SCALAR >
132  if (__parseDone)
133  return __parser->errors().error(i).is_error;
134  else
135  GUM_ERROR(OperationNotAllowed, "FMDPDat file not parsed yet");
136  }
137 
138  template < typename GUM_SCALAR >
139  INLINE std::string FMDPDatReader< GUM_SCALAR >::errMsg(Idx i) {
140  if (__parseDone)
141  return __parser->errors().error(i).msg;
142  else
143  GUM_ERROR(OperationNotAllowed, "FMDPDat file not parsed yet");
144  }
145 
146  template < typename GUM_SCALAR >
147  INLINE void FMDPDatReader< GUM_SCALAR >::showElegantErrors(std::ostream& o) {
148  if (__parseDone)
149  __parser->errors().elegantErrors(o);
150  else
151  GUM_ERROR(OperationNotAllowed, "FMDPDat file not parsed yet");
152  }
153 
154  template < typename GUM_SCALAR >
155  INLINE void
157  if (__parseDone)
158  __parser->errors().elegantErrorsAndWarnings(o);
159  else
160  GUM_ERROR(OperationNotAllowed, "FMDPDat file not parsed yet");
161  }
162 
163  template < typename GUM_SCALAR >
164  INLINE void FMDPDatReader< GUM_SCALAR >::showErrorCounts(std::ostream& o) {
165  if (__parseDone)
166  __parser->errors().syntheticResults(o);
167  else
168  GUM_ERROR(OperationNotAllowed, "FMDPDat file not parsed yet");
169  }
170 
171  template < typename GUM_SCALAR >
173  return (!__parseDone) ? (Size)0 : __parser->errors().error_count;
174  }
175 
176  template < typename GUM_SCALAR >
178  return (!__parseDone) ? (Size)0 : __parser->errors().warning_count;
179  }
180 
182 } // namespace gum
183 
184 #endif // DOXYGEN_SHOULD_SKIP_THIS
bool errIsError(Idx i)
type of ith error or warning
FMDPDatReader(FMDP< GUM_SCALAR > *fmdp, const std::string &filename)
const std::string & streamName() const
name of readen file
Size errors()
publishing Errors API
#define GUM_SHOWERROR(e)
Definition: exceptions.h:61
FMDPFactory< GUM_SCALAR > * __factory
FMDP< GUM_SCALAR > * __fmdp
MDPDAT::Parser * __parser
Idx errCol(Idx i)
col of ith error or warning
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
void showElegantErrorsAndWarnings(std::ostream &o=std::cerr)
send on std::cerr the list of errors or warnings
MDPDAT::Scanner & scanner()
Direct access to FMDPDat scanner (mandatory for listener connection)
Size warnings()
of errors
Base class for all aGrUM&#39;s exceptions.
Definition: exceptions.h:106
void showElegantErrors(std::ostream &o=std::cerr)
send on std::cerr the list of errors
MDPDAT::Scanner * __scanner
void showErrorCounts(std::ostream &o=std::cerr)
send on std::cerr the number of errors and the number of warnings
std::string errMsg(Idx i)
message of ith error or warning
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
bool trace() const
accessor to trace function (just write the number of parser line)
Size proceed()
parse.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
std::string __streamName
Idx errLine(Idx i)
line of ith error or warning
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55