aGrUM  0.18.1
a C++ library for (probabilistic) graphical models
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
PRM< GUM_SCALAR > * prm__
Definition: O3prmReader.h:146
Copyright 2005-2020 Pierre-Henri WUILLEMIN() & Christophe GONZALES() info_at_agrum_dot_org.
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.
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-2020 Pierre-Henri WUILLEMIN() & Christophe GONZALES() info_at_agrum_dot_org.
void parseStream(std::istream &input, std::ostream &output, std::string module="")
std::unique_ptr< O3PRM > o3_prm__
Definition: O3prmReader.h:147
std::string clean__(std::string text) const
std::vector< std::string > class_path__
Definition: O3prmReader.h:148
Copyright 2005-2020 Pierre-Henri WUILLEMIN() & Christophe GONZALES() info_at_agrum_dot_org.
gum::prm::PRM< GUM_SCALAR > * prm()
Definition: O3prmReader.h:110
Copyright 2005-2020 Pierre-Henri WUILLEMIN() & Christophe GONZALES() info_at_agrum_dot_org.
This class is used to represent parsing errors for the different parser implemented in aGrUM...
Copyright 2005-2020 Pierre-Henri WUILLEMIN() & Christophe GONZALES() info_at_agrum_dot_org.
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-2020 Pierre-Henri WUILLEMIN() & Christophe GONZALES() info_at_agrum_dot_org.
This class is used contain and manipulate gum::ParseError.
Idx errCol(Idx i) const
col of ith error or warning
Copyright 2005-2020 Pierre-Henri WUILLEMIN() & Christophe GONZALES() info_at_agrum_dot_org.
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
Set< std::string > imported__
Definition: O3prmReader.h:149
void showElegantErrorsAndWarnings(std::ostream &o=std::cerr) const
send on std::cerr the list of errors or warnings
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-2020 Pierre-Henri WUILLEMIN() & Christophe GONZALES() info_at_agrum_dot_org.
Idx errLine(Idx i) const
line of ith error or warning
Copyright 2005-2020 Pierre-Henri WUILLEMIN() & Christophe GONZALES() info_at_agrum_dot_org.
void addClassPath(const std::string &class_path)
Add a list of paths to look for o3prm files.
std::string print__(const ParseError &err) const
void parseImport__(const O3Import &i, const std::string &module_path)
This class represents a Probabilistic Relational PRMSystem<GUM_SCALAR>.
Definition: PRM.h:66
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
void readStream__(std::istream &input, const std::string &file, std::string module="")
Copyright 2005-2020 Pierre-Henri WUILLEMIN() & Christophe GONZALES() info_at_agrum_dot_org.
Copyright 2005-2020 Pierre-Henri WUILLEMIN() & Christophe GONZALES() info_at_agrum_dot_org.
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
std::vector< const O3Import *> copyImports__()