aGrUM  0.14.2
O3prmReader.h
Go to the documentation of this file.
1 /**************************************************************************
2  * Copyright (C) 2005 by Pierre-Henri WUILLEMIN et Christophe GONZALES *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
20 
29 #ifndef GUM_PRM_O3PRM_O3PRM_FACTORY_H
30 #define GUM_PRM_O3PRM_O3PRM_FACTORY_H
31 
32 #include <cstdint>
33 #include <fstream>
34 #include <iostream>
35 #include <sstream>
36 #include <string>
37 #include <vector>
38 
39 #include <agrum/PRM/PRM.h>
45 #include <agrum/PRM/o3prm/O3prm.h>
46 #include <agrum/PRM/o3prm/cocoR/Parser.h>
47 #include <agrum/PRM/o3prm/cocoR/Scanner.h>
48 #include <agrum/agrum.h>
51 
52 namespace gum {
53  namespace prm {
54  namespace o3prm {
55 
66  template < typename GUM_SCALAR >
67  class O3prmReader {
68  public:
69  O3prmReader();
71  O3prmReader(const O3prmReader& src);
72  O3prmReader(O3prmReader&& src);
73  ~O3prmReader();
74  O3prmReader& operator=(const O3prmReader& src);
76 
79  Size readFile(const std::string& file, const std::string& module = "");
80 
83  Size readString(const std::string& string);
84 
85  void parseStream(std::istream& input,
86  std::ostream& output,
87  std::string module = "");
96  void setClassPath(const std::string& class_path);
97 
106  void addClassPath(const std::string& class_path);
107 
109  const gum::prm::PRM< GUM_SCALAR >* prm() const { return __prm; }
110 
113 
115  Size errors() const;
117  Size warnings() const;
118 
120  const ErrorsContainer& errorsContainer() const;
121 
123  Idx errLine(Idx i) const;
125  Idx errCol(Idx i) const;
127  std::wstring errFilename(Idx i) const;
129  bool errIsError(Idx i) const;
131  std::string errMsg(Idx i) const;
132 
134  void showElegantErrors(std::ostream& o = std::cerr) const;
135 
137  void showElegantErrorsAndWarnings(std::ostream& o = std::cerr) const;
138 
140  void showErrorCounts(std::ostream& o = std::cerr) const;
142 
143  private:
145  std::unique_ptr< O3PRM > __o3_prm;
146  std::vector< std::string > __class_path;
148 
149  // Needed when file can't be parse (can not open it for exemple)
151 
152  void __readStream(std::istream& input,
153  const std::string& file,
154  std::string module = "");
155 
156  void __parseImport(const O3Import& i, const std::string& module_path);
157 
158  void __parseStream(std::istream& input,
159  const std::string& filename,
160  const std::string& module);
161 
162  std::vector< const O3Import* > __copyImports();
163 
164  std::string __clean(std::string text) const;
165  std::string __print(const ParseError& err) const;
166  std::string __readStream(std::istream& input);
167  };
168 
169  } // namespace o3prm
170  } // namespace prm
171 } // namespace gum
172 
173 // always include the implementation of the templates
175 
176 
177 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
178 extern template class gum::prm::o3prm::O3prmReader< double >;
179 #endif
180 
181 
182 #endif // GUM_PRM_O3PRM_O3PRM_FACTORY_H
Headers for the O3TypeFactory class.
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...
Errors container (at least) for parser.
void parseStream(std::istream &input, std::ostream &output, std::string module="")
Headers for the O3SystemFactory class.
gum::prm::PRM< GUM_SCALAR > * prm()
Definition: O3prmReader.h:108
Headers for the O3ClassFactory class.
std::vector< std::string > __class_path
Definition: O3prmReader.h:146
This class is used to represent parsing errors for the different parser implemented in aGrUM...
std::unique_ptr< O3PRM > __o3_prm
Definition: O3prmReader.h:145
Headers of PRM.
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
Headers for the O3NameSolver class.
This class is used contain and manipulate gum::ParseError.
Idx errCol(Idx i) const
col of ith error or warning
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
The O3Import is part of the AST of the O3PRM language.
Definition: O3prm.h:866
O3prmReader & operator=(const O3prmReader &src)
This class read O3PRM files and creates the corresponding gum::prm::PRM.
Definition: O3prmReader.h:67
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:109
Headers for the O3InterfaceFactory class.
Idx errLine(Idx i) const
line of ith error or warning
void __parseImport(const O3Import &i, const std::string &module_path)
Headers for the AST of the O3PRM language.
void addClassPath(const std::string &class_path)
Add a list of paths to look for o3prm files.
Set< std::string > __imported
Definition: O3prmReader.h:147
This class represents a Probabilistic Relational PRMSystem<GUM_SCALAR>.
Definition: PRM.h:63
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:50
Utilities for manipulating strings.
Implementation for the O3prmReader class.
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:45
PRM< GUM_SCALAR > * __prm
Definition: O3prmReader.h:144