aGrUM  0.16.0
O3prmReader.h
Go to the documentation of this file.
1 
31 #ifndef GUM_PRM_O3PRM_O3PRM_FACTORY_H
32 #define GUM_PRM_O3PRM_O3PRM_FACTORY_H
33 
34 #include <cstdint>
35 #include <fstream>
36 #include <iostream>
37 #include <sstream>
38 #include <string>
39 #include <vector>
40 
41 #include <agrum/PRM/PRM.h>
47 #include <agrum/PRM/o3prm/O3prm.h>
48 #include <agrum/PRM/o3prm/cocoR/Parser.h>
49 #include <agrum/PRM/o3prm/cocoR/Scanner.h>
50 #include <agrum/agrum.h>
53 
54 namespace gum {
55  namespace prm {
56  namespace o3prm {
57 
68  template < typename GUM_SCALAR >
69  class O3prmReader {
70  public:
71  O3prmReader();
73  O3prmReader(const O3prmReader& src);
74  O3prmReader(O3prmReader&& src);
75  ~O3prmReader();
76  O3prmReader& operator=(const O3prmReader& src);
78 
81  Size readFile(const std::string& file, const std::string& module = "");
82 
85  Size readString(const std::string& string);
86 
87  void parseStream(std::istream& input,
88  std::ostream& output,
89  std::string module = "");
98  void setClassPath(const std::string& class_path);
99 
108  void addClassPath(const std::string& class_path);
109 
111  const gum::prm::PRM< GUM_SCALAR >* prm() const { return __prm; }
112 
115 
117  Size errors() const;
119  Size warnings() const;
120 
122  const ErrorsContainer& errorsContainer() const;
123 
125  Idx errLine(Idx i) const;
127  Idx errCol(Idx i) const;
129  std::wstring errFilename(Idx i) const;
131  bool errIsError(Idx i) const;
133  std::string errMsg(Idx i) const;
134 
136  void showElegantErrors(std::ostream& o = std::cerr) const;
137 
139  void showElegantErrorsAndWarnings(std::ostream& o = std::cerr) const;
140 
142  void showErrorCounts(std::ostream& o = std::cerr) const;
144 
145  private:
147  std::unique_ptr< O3PRM > __o3_prm;
148  std::vector< std::string > __class_path;
150 
151  // Needed when file can't be parse (can not open it for exemple)
153 
154  void __readStream(std::istream& input,
155  const std::string& file,
156  std::string module = "");
157 
158  void __parseImport(const O3Import& i, const std::string& module_path);
159 
160  void __parseStream(std::istream& input,
161  const std::string& filename,
162  const std::string& module);
163 
164  std::vector< const O3Import* > __copyImports();
165 
166  std::string __clean(std::string text) const;
167  std::string __print(const ParseError& err) const;
168  std::string __readStream(std::istream& input);
169  };
170 
171  } // namespace o3prm
172  } // namespace prm
173 } // namespace gum
174 
175 // always include the implementation of the templates
177 
178 
179 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
180 extern template class gum::prm::o3prm::O3prmReader< double >;
181 #endif
182 
183 
184 #endif // GUM_PRM_O3PRM_O3PRM_FACTORY_H
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
std::string __clean(std::string text) const
Size warnings() const
of errors
std::string errMsg(Idx i) const
message of ith error or warning
std::wstring errFilename(Idx i) const
filename of ith error or warning
void setClassPath(const std::string &class_path)
This methods defines the list of paths to look for o3prm files.
void __readStream(std::istream &input, const std::string &file, std::string module="")
Size readFile(const std::string &file, const std::string &module="")
Read file and load its content using a PRMFactory. The package parameter set the file&#39;s content packa...
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
void parseStream(std::istream &input, std::ostream &output, std::string module="")
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
gum::prm::PRM< GUM_SCALAR > * prm()
Definition: O3prmReader.h:110
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
std::vector< std::string > __class_path
Definition: O3prmReader.h:148
This class is used to represent parsing errors for the different parser implemented in aGrUM...
std::unique_ptr< O3PRM > __o3_prm
Definition: O3prmReader.h:147
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
void showErrorCounts(std::ostream &o=std::cerr) const
send on std::cerr the number of errors and the number of warnings
const ErrorsContainer & errorsContainer() const
publishing Errors API
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
This class is used contain and manipulate gum::ParseError.
Idx errCol(Idx i) const
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
The O3Import is part of the AST of the O3PRM language.
Definition: O3prm.h:868
O3prmReader & operator=(const O3prmReader &src)
This class read O3PRM files and creates the corresponding gum::prm::PRM.
Definition: O3prmReader.h:69
void showElegantErrorsAndWarnings(std::ostream &o=std::cerr) const
send on std::cerr the list of errors or warnings
std::vector< const O3Import *> __copyImports()
Size errors() const
publishing Errors API
void showElegantErrors(std::ostream &o=std::cerr) const
send on std::cerr the list of errors
const gum::prm::PRM< GUM_SCALAR > * prm() const
Definition: O3prmReader.h:111
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Idx errLine(Idx i) const
line of ith error or warning
void __parseImport(const O3Import &i, const std::string &module_path)
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
void addClassPath(const std::string &class_path)
Add a list of paths to look for o3prm files.
Set< std::string > __imported
Definition: O3prmReader.h:149
This class represents a Probabilistic Relational PRMSystem<GUM_SCALAR>.
Definition: PRM.h:66
std::string __print(const ParseError &err) const
bool errIsError(Idx i) const
type of ith error or warning
Size readString(const std::string &string)
With readString method, you must set the current path to search from import yourself, using addClassPath.
Size Idx
Type for indexes.
Definition: types.h:53
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
void __parseStream(std::istream &input, const std::string &filename, const std::string &module)
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
PRM< GUM_SCALAR > * __prm
Definition: O3prmReader.h:146