aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
DSLReader_tpl.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright (c) 2005-2021 by Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4  * info_at_agrum_dot_org
5  *
6  * This library is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 
22 #ifndef DOXYGEN_SHOULD_SKIP_THIS
23 
24 # include <agrum/BN/io/DSL/DSLReader.h>
25 
26 namespace gum {
27 
28  template < typename GUM_SCALAR >
29  DSLReader< GUM_SCALAR >::DSLReader(BayesNet< GUM_SCALAR >* bn, const std::string& filename) :
32  _bn_ = bn;
34  _parseDone_ = false;
35 
37 
38  _ioerror_ = false;
39 
40  try {
42  _parser_ = new DSL::Parser(_scanner_);
44  } catch (IOError&) { _ioerror_ = true; }
45  }
46 
47  template < typename GUM_SCALAR >
50 
51  if (!_ioerror_) {
52  // this could lead to memory leak !!
53  if (_parser_) delete (_parser_);
54 
55  if (_scanner_) delete (_scanner_);
56  }
57 
58  if (_factory_) delete (_factory_);
59  }
60 
61  template < typename GUM_SCALAR >
63  if (_ioerror_) { GUM_ERROR(gum::IOError, "No such file " + streamName()) }
64 
65  return *_scanner_;
66  }
67 
68  template < typename GUM_SCALAR >
69  INLINE const std::string& DSLReader< GUM_SCALAR >::streamName() const {
70  return _streamName_;
71  }
72 
73  template < typename GUM_SCALAR >
74  INLINE bool DSLReader< GUM_SCALAR >::trace() const {
75  return _traceScanning_;
76  }
77 
78  template < typename GUM_SCALAR >
79  INLINE void DSLReader< GUM_SCALAR >::trace(bool b) {
81  scanner().setTrace(b);
82  }
83 
84  template < typename GUM_SCALAR >
86  if (_ioerror_) { GUM_ERROR(gum::IOError, "No such file " + streamName()) }
87 
88  if (!_parseDone_) {
89  try {
90  _parser_->Parse();
91  _parseDone_ = true;
92  } catch (gum::Exception& e) {
94  return 1 + _parser_->errors().error_count;
95  }
96  }
97 
98  return (_parser_->errors().error_count);
99  }
100 
101  /// @{
102  /// publishing Errors API
103  template < typename GUM_SCALAR >
105  if (_parseDone_)
106  return _parser_->errors().error(i).line;
107  else {
108  GUM_ERROR(OperationNotAllowed, "DSL file not parsed yet")
109  }
110  }
111 
112  template < typename GUM_SCALAR >
114  if (_parseDone_)
115  return _parser_->errors().error(i).column;
116  else {
117  GUM_ERROR(OperationNotAllowed, "DSL file not parsed yet")
118  }
119  }
120 
121  template < typename GUM_SCALAR >
123  if (_parseDone_)
124  return _parser_->errors().error(i).is_error;
125  else {
126  GUM_ERROR(OperationNotAllowed, "DSL file not parsed yet")
127  }
128  }
129 
130  template < typename GUM_SCALAR >
132  if (_parseDone_)
133  return _parser_->errors().error(i).msg;
134  else {
135  GUM_ERROR(OperationNotAllowed, "DSL file not parsed yet")
136  }
137  }
138 
139  template < typename GUM_SCALAR >
141  if (_parseDone_)
143  else {
144  GUM_ERROR(OperationNotAllowed, "DSL file not parsed yet")
145  }
146  }
147 
148  template < typename GUM_SCALAR >
150  if (_parseDone_)
152  else {
153  GUM_ERROR(OperationNotAllowed, "DSL file not parsed yet")
154  }
155  }
156 
157  template < typename GUM_SCALAR >
159  if (_parseDone_)
161  else {
162  GUM_ERROR(OperationNotAllowed, "DSL file not parsed yet")
163  }
164  }
165 
166  template < typename GUM_SCALAR >
168  if (_parseDone_)
170  else {
171  GUM_ERROR(OperationNotAllowed, "DSL file not parsed yet")
172  }
173  }
174 
175  template < typename GUM_SCALAR >
177  return (!_parseDone_) ? (Size)0 : _parser_->errors().error_count;
178  }
179 
180  template < typename GUM_SCALAR >
182  return (!_parseDone_) ? (Size)0 : _parser_->errors().warning_count;
183  }
184 
185  /// @}
186 } // namespace gum
187 
188 #endif // DOXYGEN_SHOULD_SKIP_THIS
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643