aGrUM  0.14.2
O3prmrContext.h
Go to the documentation of this file.
1 
2 /***************************************************************************
3  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
4  * {prenom.nom}_at_lip6.fr *
5  * *
6  * This program is free software; you can redistribute it and/or modify *
7  * it under the terms of the GNU General Public License as published by *
8  * the Free Software Foundation; either version 2 of the License, or *
9  * (at your option) any later version. *
10  * *
11  * This program 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 General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU General Public License *
17  * along with this program; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
20  ***************************************************************************/
28 #ifndef SKOORSYNTAXTREE_H
29 #define SKOORSYNTAXTREE_H
30 
31 #include <map>
32 #include <string>
33 #include <vector>
34 
36 
38 
39 namespace gum {
40  namespace prm {
41  namespace o3prmr {
42 
48  class O3prmrCommand {
49  public:
50  int line;
51  enum class RequestType : char {
52  Observe,
53  Unobserve,
54  Query,
55  SetEngine,
57  };
58 
59  explicit O3prmrCommand(int line) : line(line) {}
60  O3prmrCommand(const O3prmrCommand& c) : line(c.line) {}
61  virtual ~O3prmrCommand() {}
62 
63  virtual RequestType type() const = 0;
64  virtual std::string toString() const = 0;
65  };
66 
68  class ImportCommand {
69  public:
71  const std::string& value,
72  const std::string& alias) :
73  line(line),
74  value(value), alias(alias) {}
76  line(c.line), value(c.value), alias(c.alias) {}
77 
78  int line;
79  std::string value;
80  std::string alias;
81 
82  std::string toString() const {
83  return "import " + value + (alias.empty() ? "" : "as " + alias) + ";";
84  }
85  };
86 
89  public:
90  SetEngineCommand(int line, const std::string& value) :
91  O3prmrCommand(line), value(value) {}
93  O3prmrCommand(c), value(c.value) {}
94 
95  std::string value;
96 
98  std::string toString() const { return "engine " + value + ";"; }
99  };
100 
103  public:
104  SetGndEngineCommand(int line, const std::string& value) :
105  O3prmrCommand(line), value(value) {}
107  O3prmrCommand(c), value(c.value) {}
108 
109  std::string value;
110 
112  std::string toString() const { return "grd_engine " + value + ";"; }
113  };
114 
116  template < typename GUM_SCALAR >
117  class ObserveCommand : public O3prmrCommand {
118  public:
120  const std::string& leftValue,
121  const std::string& rightValue) :
122  O3prmrCommand(line),
123  leftValue(leftValue), rightValue(rightValue), system(0) {}
125  O3prmrCommand(c), leftValue(c.leftValue), rightValue(c.rightValue),
126  system(c.system), chain(c.chain) {}
127 
128  std::string leftValue;
129  std::string rightValue;
133 
135  std::string toString() const {
136  return leftValue + " = " + rightValue + ";";
137  }
138  };
139 
141  template < typename GUM_SCALAR >
143  public:
144  std::string value;
147 
148  UnobserveCommand(int line, const std::string& value) :
149  O3prmrCommand(line), value(value), system(0) {}
151  O3prmrCommand(c), value(c.value), system(c.system), chain(c.chain) {}
152 
154  std::string toString() const { return "unobserve " + value + ";"; }
155  };
156 
158  template < typename GUM_SCALAR >
159  class QueryCommand : public O3prmrCommand {
160  public:
161  QueryCommand(int line, const std::string& val) :
162  O3prmrCommand(line), value(val), system(nullptr) {}
163 
164  std::string value;
167 
168  RequestType type() const { return RequestType::Query; }
169  std::string toString() const { return "? " + value + ";"; }
170  };
171 
176  template < typename GUM_SCALAR >
179  std::string m_name;
181  std::vector< O3prmrCommand* > m_commands;
182  std::map< const PRMSystem< GUM_SCALAR >*, PRMInference< GUM_SCALAR >* >
184 
185  public:
186  explicit O3prmrSession(const std::string& name = std::string());
187  O3prmrSession(const O3prmrSession& s);
188  virtual ~O3prmrSession();
189 
190  std::string name() const;
191 
192  std::vector< O3prmrCommand* > commands() const;
193  void addObserve(int line,
194  const std::string& leftValue,
195  const std::string& rightValue);
196  void addUnobserve(int line, const std::string& value);
197  void addQuery(int line, const std::string& value);
198  void addSetEngine(int line, const std::string& value);
199  void addSetGndEngine(int line, const std::string& value);
200  void addCommand(const O3prmrCommand* command);
201 
202  virtual std::string toString() const;
203  O3prmrSession& operator+=(const O3prmrSession& c);
204 
205  private:
206  void addCommand(O3prmrCommand* command);
207  };
208 
213  template < typename GUM_SCALAR >
215  std::string m_filename;
216  std::string m_package;
217  std::vector< O3prmrSession< GUM_SCALAR >* > m_sessions;
218  std::vector< ImportCommand* > m_imports;
220 
221  public:
222  explicit O3prmrContext(const std::string& filename = std::string());
223  O3prmrContext(const O3prmrContext& s);
224  virtual ~O3prmrContext();
225 
226  const ImportCommand* mainImport() const { return m_mainImport; }
227 
228  std::string filename() const;
229 
230  std::string package() const;
231  void setPackage(const std::string& package);
232 
233  std::string aliasToImport(const std::string& alias);
234  std::vector< ImportCommand* > imports() const;
235  void addImport(int line,
236  const std::string& import,
237  const std::string& alias);
238  void addImport(int line, const std::string& import, bool ismain);
239  void addImport(const ImportCommand& i) {
240  m_imports.push_back(new ImportCommand(i.line, i.value, i.alias));
241 
242  if (i.alias == "default") m_mainImport = m_imports.back();
243  }
244 
245  std::vector< O3prmrSession< GUM_SCALAR >* > sessions() const;
246  void addSession(const O3prmrSession< GUM_SCALAR >& session);
247 
248  virtual std::string toString() const;
249  O3prmrContext& operator+=(const O3prmrContext& c);
250  };
251 
252 
253 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
254 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
255 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
256 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
257 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
258  extern template class ObserveCommand< double >;
259 # endif
260 # endif
261 # endif
262 # endif
263 #endif
264 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
265 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
266 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
267 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
268 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
269  extern template class UnobserveCommand< double >;
270 # endif
271 # endif
272 # endif
273 # endif
274 #endif
275 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
276 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
277 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
278 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
279 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
280  extern template class QueryCommand< double >;
281 # endif
282 # endif
283 # endif
284 # endif
285 #endif
286 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
287 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
288 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
289 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
290 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
291  extern template class O3prmrSession< double >;
292 # endif
293 # endif
294 # endif
295 # endif
296 #endif
297 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
298 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
299 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
300 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
301 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
302  extern template class O3prmrContext< double >;
303 # endif
304 # endif
305 # endif
306 # endif
307 #endif
308 
309 
310  } // namespace o3prmr
311  } // namespace prm
312 } // namespace gum
313 
315 
316 #endif // SKOORSYNTAXTREE_H
aGrUM&#39;s Potential is a multi-dimensional array with tensor operators.
Definition: potential.h:57
const PRMSystem< GUM_SCALAR > * system
Potential< GUM_SCALAR > potentiel
SetEngineCommand(const SetEngineCommand &c)
Definition: O3prmrContext.h:92
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:60
Implementation of O3prmReader.
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)
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
ImportCommand(int line, const std::string &value, const std::string &alias)
Definition: O3prmrContext.h:70
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:90
Headers of PRMInference.
A PRMSystem is a container of PRMInstance and describe a relational skeleton.
Definition: PRMObject.h:226
PRMInference< GUM_SCALAR >::Chain chain
Headers of PRMSystem.
void addImport(const ImportCommand &i)
std::pair< const PRMInstance< GUM_SCALAR > *, const PRMAttribute< GUM_SCALAR > *> Chain
Code alias.
Definition: PRMInference.h:54
This is an abstract class.
Definition: O3prmrContext.h:48
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:49
ObserveCommand(const ObserveCommand &c)
This class contains a o3prmr session.
ImportCommand(const ImportCommand &c)
Definition: O3prmrContext.h:75
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:82
virtual RequestType type() const =0
std::string m_name
The session name;.