aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
DSLReader_tpl.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright 2005-2020 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,
30  const std::string& filename) :
33  bn__ = bn;
35  parseDone__ = false;
36 
38 
39  ioerror__ = false;
40 
41  try {
43  parser__ = new DSL::Parser(scanner__);
45  } catch (IOError&) { ioerror__ = true; }
46  }
47 
48  template < typename GUM_SCALAR >
51 
52  if (!ioerror__) {
53  // this could lead to memory leak !!
54  if (parser__) delete (parser__);
55 
56  if (scanner__) delete (scanner__);
57  }
58 
59  if (factory__) delete (factory__);
60  }
61 
62  template < typename GUM_SCALAR >
64  if (ioerror__) { GUM_ERROR(gum::IOError, "No such file " + streamName()); }
65 
66  return *scanner__;
67  }
68 
69  template < typename GUM_SCALAR >
70  INLINE const std::string& DSLReader< GUM_SCALAR >::streamName() const {
71  return streamName__;
72  }
73 
74  template < typename GUM_SCALAR >
75  INLINE bool DSLReader< GUM_SCALAR >::trace() const {
76  return traceScanning__;
77  }
78 
79  template < typename GUM_SCALAR >
80  INLINE void DSLReader< GUM_SCALAR >::trace(bool b) {
82  scanner().setTrace(b);
83  }
84 
85  template < typename GUM_SCALAR >
87  if (ioerror__) { GUM_ERROR(gum::IOError, "No such file " + streamName()); }
88 
89  if (!parseDone__) {
90  try {
91  parser__->Parse();
92  parseDone__ = true;
93  } catch (gum::Exception& e) {
95  return 1 + parser__->errors().error_count;
96  }
97  }
98 
99  return (parser__->errors().error_count);
100  }
101 
102  /// @{
103  /// publishing Errors API
104  template < typename GUM_SCALAR >
106  if (parseDone__)
107  return parser__->errors().error(i).line;
108  else {
109  GUM_ERROR(OperationNotAllowed, "DSL file not parsed yet");
110  }
111  }
112 
113  template < typename GUM_SCALAR >
115  if (parseDone__)
116  return parser__->errors().error(i).column;
117  else {
118  GUM_ERROR(OperationNotAllowed, "DSL file not parsed yet");
119  }
120  }
121 
122  template < typename GUM_SCALAR >
124  if (parseDone__)
125  return parser__->errors().error(i).is_error;
126  else {
127  GUM_ERROR(OperationNotAllowed, "DSL file not parsed yet");
128  }
129  }
130 
131  template < typename GUM_SCALAR >
133  if (parseDone__)
134  return parser__->errors().error(i).msg;
135  else {
136  GUM_ERROR(OperationNotAllowed, "DSL file not parsed yet");
137  }
138  }
139 
140  template < typename GUM_SCALAR >
142  if (parseDone__)
144  else {
145  GUM_ERROR(OperationNotAllowed, "DSL file not parsed yet");
146  }
147  }
148 
149  template < typename GUM_SCALAR >
150  INLINE void
152  if (parseDone__)
154  else {
155  GUM_ERROR(OperationNotAllowed, "DSL file not parsed yet");
156  }
157  }
158 
159  template < typename GUM_SCALAR >
161  if (parseDone__)
163  else {
164  GUM_ERROR(OperationNotAllowed, "DSL file not parsed yet");
165  }
166  }
167 
168  template < typename GUM_SCALAR >
170  if (parseDone__)
172  else {
173  GUM_ERROR(OperationNotAllowed, "DSL file not parsed yet");
174  }
175  }
176 
177  template < typename GUM_SCALAR >
179  return (!parseDone__) ? (Size)0 : parser__->errors().error_count;
180  }
181 
182  template < typename GUM_SCALAR >
184  return (!parseDone__) ? (Size)0 : parser__->errors().warning_count;
185  }
186 
187  /// @}
188 } // namespace gum
189 
190 #endif // DOXYGEN_SHOULD_SKIP_THIS
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:669