aGrUM  0.16.0
O3prmrContext.h
Go to the documentation of this file.
1 
30 #ifndef SKOORSYNTAXTREE_H
31 #define SKOORSYNTAXTREE_H
32 
33 #include <map>
34 #include <string>
35 #include <vector>
36 
38 
40 
41 namespace gum {
42  namespace prm {
43  namespace o3prmr {
44 
50  class O3prmrCommand {
51  public:
52  int line;
53  enum class RequestType : char {
54  Observe,
55  Unobserve,
56  Query,
57  SetEngine,
59  };
60 
61  explicit O3prmrCommand(int line) : line(line) {}
62  O3prmrCommand(const O3prmrCommand& c) : line(c.line) {}
63  virtual ~O3prmrCommand() {}
64 
65  virtual RequestType type() const = 0;
66  virtual std::string toString() const = 0;
67  };
68 
70  class ImportCommand {
71  public:
73  const std::string& value,
74  const std::string& alias) :
75  line(line),
76  value(value), alias(alias) {}
78  line(c.line), value(c.value), alias(c.alias) {}
79 
80  int line;
81  std::string value;
82  std::string alias;
83 
84  std::string toString() const {
85  return "import " + value + (alias.empty() ? "" : "as " + alias) + ";";
86  }
87  };
88 
91  public:
92  SetEngineCommand(int line, const std::string& value) :
93  O3prmrCommand(line), value(value) {}
95  O3prmrCommand(c), value(c.value) {}
96 
97  std::string value;
98 
100  std::string toString() const { return "engine " + value + ";"; }
101  };
102 
105  public:
106  SetGndEngineCommand(int line, const std::string& value) :
107  O3prmrCommand(line), value(value) {}
109  O3prmrCommand(c), value(c.value) {}
110 
111  std::string value;
112 
114  std::string toString() const { return "grd_engine " + value + ";"; }
115  };
116 
118  template < typename GUM_SCALAR >
119  class ObserveCommand : public O3prmrCommand {
120  public:
122  const std::string& leftValue,
123  const std::string& rightValue) :
124  O3prmrCommand(line),
125  leftValue(leftValue), rightValue(rightValue), system(0) {}
127  O3prmrCommand(c), leftValue(c.leftValue), rightValue(c.rightValue),
128  system(c.system), chain(c.chain) {}
129 
130  std::string leftValue;
131  std::string rightValue;
135 
137  std::string toString() const {
138  return leftValue + " = " + rightValue + ";";
139  }
140  };
141 
143  template < typename GUM_SCALAR >
145  public:
146  std::string value;
149 
150  UnobserveCommand(int line, const std::string& value) :
151  O3prmrCommand(line), value(value), system(0) {}
153  O3prmrCommand(c), value(c.value), system(c.system), chain(c.chain) {}
154 
156  std::string toString() const { return "unobserve " + value + ";"; }
157  };
158 
160  template < typename GUM_SCALAR >
161  class QueryCommand : public O3prmrCommand {
162  public:
163  QueryCommand(int line, const std::string& val) :
164  O3prmrCommand(line), value(val), system(nullptr) {}
165 
166  std::string value;
169 
170  RequestType type() const { return RequestType::Query; }
171  std::string toString() const { return "? " + value + ";"; }
172  };
173 
178  template < typename GUM_SCALAR >
181  std::string m_name;
183  std::vector< O3prmrCommand* > m_commands;
184  std::map< const PRMSystem< GUM_SCALAR >*, PRMInference< GUM_SCALAR >* >
186 
187  public:
188  explicit O3prmrSession(const std::string& name = std::string());
189  O3prmrSession(const O3prmrSession& s);
190  virtual ~O3prmrSession();
191 
192  std::string name() const;
193 
194  std::vector< O3prmrCommand* > commands() const;
195  void addObserve(int line,
196  const std::string& leftValue,
197  const std::string& rightValue);
198  void addUnobserve(int line, const std::string& value);
199  void addQuery(int line, const std::string& value);
200  void addSetEngine(int line, const std::string& value);
201  void addSetGndEngine(int line, const std::string& value);
202  void addCommand(const O3prmrCommand* command);
203 
204  virtual std::string toString() const;
205  O3prmrSession& operator+=(const O3prmrSession& c);
206 
207  private:
208  void addCommand(O3prmrCommand* command);
209  };
210 
215  template < typename GUM_SCALAR >
217  std::string m_filename;
218  std::string m_package;
219  std::vector< O3prmrSession< GUM_SCALAR >* > m_sessions;
220  std::vector< ImportCommand* > m_imports;
222 
223  public:
224  explicit O3prmrContext(const std::string& filename = std::string());
225  O3prmrContext(const O3prmrContext& s);
226  virtual ~O3prmrContext();
227 
228  const ImportCommand* mainImport() const { return m_mainImport; }
229 
230  std::string filename() const;
231 
232  std::string package() const;
233  void setPackage(const std::string& package);
234 
235  std::string aliasToImport(const std::string& alias);
236  std::vector< ImportCommand* > imports() const;
237  void addImport(int line,
238  const std::string& import,
239  const std::string& alias);
240  void addImport(int line, const std::string& import, bool ismain);
241  void addImport(const ImportCommand& i) {
242  m_imports.push_back(new ImportCommand(i.line, i.value, i.alias));
243 
244  if (i.alias == "default") m_mainImport = m_imports.back();
245  }
246 
247  std::vector< O3prmrSession< GUM_SCALAR >* > sessions() const;
248  void addSession(const O3prmrSession< GUM_SCALAR >& session);
249 
250  virtual std::string toString() const;
251  O3prmrContext& operator+=(const O3prmrContext& c);
252  };
253 
254 
255 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
256 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
257 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
258 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
259 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
260  extern template class ObserveCommand< double >;
261 # endif
262 # endif
263 # endif
264 # endif
265 #endif
266 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
267 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
268 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
269 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
270 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
271  extern template class UnobserveCommand< double >;
272 # endif
273 # endif
274 # endif
275 # endif
276 #endif
277 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
278 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
279 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
280 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
281 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
282  extern template class QueryCommand< double >;
283 # endif
284 # endif
285 # endif
286 # endif
287 #endif
288 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
289 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
290 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
291 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
292 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
293  extern template class O3prmrSession< double >;
294 # endif
295 # endif
296 # endif
297 # endif
298 #endif
299 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
300 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
301 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
302 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
303 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
304  extern template class O3prmrContext< double >;
305 # endif
306 # endif
307 # endif
308 # endif
309 #endif
310 
311 
312  } // namespace o3prmr
313  } // namespace prm
314 } // namespace gum
315 
317 
318 #endif // SKOORSYNTAXTREE_H
aGrUM&#39;s Potential is a multi-dimensional array with tensor operators.
Definition: potential.h:60
const PRMSystem< GUM_SCALAR > * system
Potential< GUM_SCALAR > potentiel
SetEngineCommand(const SetEngineCommand &c)
Definition: O3prmrContext.h:94
std::map< const PRMSystem< GUM_SCALAR > *, PRMInference< GUM_SCALAR > *> m_infEngineMap
const ImportCommand * mainImport() const
QueryCommand(int line, const std::string &val)
O3prmrCommand(const O3prmrCommand &c)
Definition: O3prmrContext.h:62
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
const PRMSystem< GUM_SCALAR > * system
PRMInference< GUM_SCALAR >::Chain chain
ObserveCommand(int line, const std::string &leftValue, const std::string &rightValue)
UnobserveCommand(const UnobserveCommand &c)
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
ImportCommand(int line, const std::string &value, const std::string &alias)
Definition: O3prmrContext.h:72
std::vector< O3prmrSession< GUM_SCALAR > *> m_sessions
SetGndEngineCommand(int line, const std::string &value)
const PRMSystem< GUM_SCALAR > * system
std::vector< ImportCommand *> m_imports
UnobserveCommand(int line, const std::string &value)
std::string toString() const
SetEngineCommand(int line, const std::string &value)
Definition: O3prmrContext.h:92
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
A PRMSystem is a container of PRMInstance and describe a relational skeleton.
Definition: PRMObject.h:229
PRMInference< GUM_SCALAR >::Chain chain
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
void addImport(const ImportCommand &i)
std::pair< const PRMInstance< GUM_SCALAR > *, const PRMAttribute< GUM_SCALAR > *> Chain
Code alias.
Definition: PRMInference.h:57
This is an abstract class.
Definition: O3prmrContext.h:50
Represent a o3prmr context, with an import, and some sequencials commands.
This abstract class is used as base class for all inference class on PRM<GUM_SCALAR>.
Definition: PRMInference.h:52
ObserveCommand(const ObserveCommand &c)
This class contains a o3prmr session.
ImportCommand(const ImportCommand &c)
Definition: O3prmrContext.h:77
SetGndEngineCommand(const SetGndEngineCommand &c)
virtual std::string toString() const =0
std::vector< O3prmrCommand *> m_commands
A sequence of commands.
PRMInference< GUM_SCALAR >::Chain chain
std::string toString() const
Definition: O3prmrContext.h:84
virtual RequestType type() const =0
std::string m_name
The session name;.