aGrUM  0.16.0
gum::prm::o3prm::O3prmReader< GUM_SCALAR > Class Template Reference

This class read O3PRM files and creates the corresponding gum::prm::PRM. More...

#include <agrum/PRM/o3prm/O3prmReader.h>

+ Collaboration diagram for gum::prm::o3prm::O3prmReader< GUM_SCALAR >:

Public Member Functions

 O3prmReader ()
 
 O3prmReader (PRM< GUM_SCALAR > &prm)
 
 O3prmReader (const O3prmReader &src)
 
 O3prmReader (O3prmReader &&src)
 
 ~O3prmReader ()
 
O3prmReaderoperator= (const O3prmReader &src)
 
O3prmReaderoperator= (O3prmReader &&src)
 
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's content package. More...
 
Size readString (const std::string &string)
 With readString method, you must set the current path to search from import yourself, using addClassPath. More...
 
void parseStream (std::istream &input, std::ostream &output, std::string module="")
 
void setClassPath (const std::string &class_path)
 This methods defines the list of paths to look for o3prm files. More...
 
void addClassPath (const std::string &class_path)
 Add a list of paths to look for o3prm files. More...
 
gum::prm::PRM< GUM_SCALAR > * prm ()
 
const gum::prm::PRM< GUM_SCALAR > * prm () const
 
Size errors () const
 publishing Errors API More...
 
Size warnings () const
 

of errors

More...
 
const ErrorsContainererrorsContainer () const
 publishing Errors API More...
 
Idx errLine (Idx i) const
 line of ith error or warning More...
 
Idx errCol (Idx i) const
 col of ith error or warning More...
 
std::wstring errFilename (Idx i) const
 filename of ith error or warning More...
 
bool errIsError (Idx i) const
 type of ith error or warning More...
 
std::string errMsg (Idx i) const
 message of ith error or warning More...
 
void showElegantErrors (std::ostream &o=std::cerr) const
 send on std::cerr the list of errors More...
 
void showElegantErrorsAndWarnings (std::ostream &o=std::cerr) const
 send on std::cerr the list of errors or warnings More...
 
void showErrorCounts (std::ostream &o=std::cerr) const
 send on std::cerr the number of errors and the number of warnings More...
 

Detailed Description

template<typename GUM_SCALAR>
class gum::prm::o3prm::O3prmReader< GUM_SCALAR >

This class read O3PRM files and creates the corresponding gum::prm::PRM.

Template Parameters
GUM_SCALARThe scalar type to use with the gum::prm::PRM.

Definition at line 69 of file O3prmReader.h.

Constructor & Destructor Documentation

◆ O3prmReader() [1/4]

template<typename GUM_SCALAR >
INLINE gum::prm::o3prm::O3prmReader< GUM_SCALAR >::O3prmReader ( )

Definition at line 141 of file O3prmReader_tpl.h.

141  :
142  __prm(new PRM< GUM_SCALAR >()),
143  __o3_prm(std::unique_ptr< O3PRM >(new O3PRM())) {
144  GUM_CONSTRUCTOR(O3prmReader);
145  }
std::unique_ptr< O3PRM > __o3_prm
Definition: O3prmReader.h:147
PRM< GUM_SCALAR > * __prm
Definition: O3prmReader.h:146

◆ O3prmReader() [2/4]

template<typename GUM_SCALAR>
INLINE gum::prm::o3prm::O3prmReader< GUM_SCALAR >::O3prmReader ( PRM< GUM_SCALAR > &  prm)
explicit

Definition at line 148 of file O3prmReader_tpl.h.

148  :
149  __prm(&prm), __o3_prm(std::unique_ptr< O3PRM >(new O3PRM())) {
150  GUM_CONSTRUCTOR(O3prmReader);
151  }
gum::prm::PRM< GUM_SCALAR > * prm()
Definition: O3prmReader.h:110
std::unique_ptr< O3PRM > __o3_prm
Definition: O3prmReader.h:147
PRM< GUM_SCALAR > * __prm
Definition: O3prmReader.h:146

◆ O3prmReader() [3/4]

template<typename GUM_SCALAR>
INLINE gum::prm::o3prm::O3prmReader< GUM_SCALAR >::O3prmReader ( const O3prmReader< GUM_SCALAR > &  src)

Definition at line 154 of file O3prmReader_tpl.h.

154  :
155  __prm(src.__prm),
156  __o3_prm(std::unique_ptr< O3PRM >(new O3PRM(*(src.__o3_prm)))),
157  __class_path(src.__class_path), __imported(src.__imported),
158  __errors(src.__errors) {
159  GUM_CONS_CPY(O3prmReader);
160  }
std::vector< std::string > __class_path
Definition: O3prmReader.h:148
std::unique_ptr< O3PRM > __o3_prm
Definition: O3prmReader.h:147
Set< std::string > __imported
Definition: O3prmReader.h:149
PRM< GUM_SCALAR > * __prm
Definition: O3prmReader.h:146

◆ O3prmReader() [4/4]

template<typename GUM_SCALAR>
INLINE gum::prm::o3prm::O3prmReader< GUM_SCALAR >::O3prmReader ( O3prmReader< GUM_SCALAR > &&  src)

Definition at line 163 of file O3prmReader_tpl.h.

163  :
164  __prm(std::move(src.__prm)), __o3_prm(std::move(src.__o3_prm)),
165  __class_path(std::move(src.__class_path)),
166  __imported(std::move(src.__imported)),
167  __errors(std::move(src.__errors)) {
168  GUM_CONS_CPY(O3prmReader);
169  }
std::vector< std::string > __class_path
Definition: O3prmReader.h:148
std::unique_ptr< O3PRM > __o3_prm
Definition: O3prmReader.h:147
Set< std::string > __imported
Definition: O3prmReader.h:149
PRM< GUM_SCALAR > * __prm
Definition: O3prmReader.h:146

◆ ~O3prmReader()

template<typename GUM_SCALAR >
INLINE gum::prm::o3prm::O3prmReader< GUM_SCALAR >::~O3prmReader ( )

Definition at line 172 of file O3prmReader_tpl.h.

172  {
173  GUM_DESTRUCTOR(O3prmReader);
174  }

Member Function Documentation

◆ __clean()

template<typename GUM_SCALAR >
INLINE std::string gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__clean ( std::string  text) const
private

Definition at line 38 of file O3prmReader_tpl.h.

38  {
39  // This could be way more faster with regex but there are not implemented
40  // with gcc-4.8 !
41  text = replace(text, "Syntax error", "Error");
42 
43  text = replace(text, "LABEL_OR_STAR_LIST", "declaration");
44 
45  text = replace(text, "ARRAY_REFERENCE_SLOT", "declaration");
46  text = replace(text, "FLOAT_AS_LABEL", "declaration");
47  text = replace(text, "FLOAT_OR_INT", "declaration");
48  text = replace(text, "INTEGER_AS_FLOAT", "declaration");
49  text = replace(text, "INTEGER_AS_LABEL", "declaration");
50  text = replace(text, "INT_TYPE_DECLARATION", "declaration");
51  text = replace(text, "LABEL_OR_INT", "declaration");
52  text = replace(text, "LABEL_OR_STAR", "declaration");
53  text = replace(text, "NAMED_CLASS_ELEMENT", "declaration");
54  text = replace(text, "REAL_TYPE_DECLARATION", "declaration");
55 
56  text = replace(text, "AGGREGATE_PARENTS", "declaration");
57  text = replace(text, "CLASS_BODY", "declaration");
58  text = replace(text, "CLASS_DECLARATION", "declaration");
59  text = replace(text, "CLASS_ELEMENT", "declaration");
60  text = replace(text, "CLASS_PARAMETER", "declaration");
61  text = replace(text, "CLASS_UNIT", "declaration");
62  text = replace(text, "FLOAT_LIST", "declaration");
63  text = replace(text, "FORMULA_LIST", "declaration");
64  text = replace(text, "IDENTIFIER_LIST", "declaration");
65  text = replace(text, "IMPORT_BODY", "declaration");
66  text = replace(text, "IMPORT_DECLARATION", "declaration");
67  text = replace(text, "IMPORT_UNIT", "declaration");
68  text = replace(text, "INTERFACE_BODY", "declaration");
69  text = replace(text, "INTERFACE_DECLARATION", "declaration");
70  text = replace(text, "INTERFACE_UNIT", "declaration");
71  text = replace(text, "LABEL_LIST", "declaration");
72  text = replace(text, "PARAMETER_LIST", "declaration");
73  text = replace(text, "PREFIXED_LABEL", "declaration");
74  text = replace(text, "RAW_CPT", "declaration");
75  text = replace(text, "REFERENCE_SLOT", "declaration");
76  text = replace(text, "RULE_CPT", "declaration");
77  text = replace(text, "SYSTEM_BODY", "declaration");
78  text = replace(text, "SYSTEM_DECLARATION", "declaration");
79  text = replace(text, "SYSTEM_UNIT", "declaration");
80  text = replace(text, "TYPE_DECLARATION", "declaration");
81  text = replace(text, "TYPE_LABEL", "declaration");
82  text = replace(text, "TYPE_UNIT", "declaration");
83  text = replace(text, "TYPE_VALUE_LIST", "declaration");
84 
85  text = replace(text, "AGGREGATE", "declaration");
86  text = replace(text, "ARRAY", "declaration");
87  text = replace(text, "ATTRIBUTE", "declaration");
88  text = replace(text, "CAST", "declaration");
89  text = replace(text, "CHAIN", "declaration");
90  text = replace(text, "CLASS", "declaration");
91  text = replace(text, "FLOAT", "declaration");
92  text = replace(text, "FORMULA", "declaration");
93  text = replace(text, "IDENTIFIER", "declaration");
94  text = replace(text, "INT", "declaration");
95  text = replace(text, "INTEGER", "declaration");
96  text = replace(text, "INTERFACE", "declaration");
97  text = replace(text, "LABEL", "declaration");
98  text = replace(text, "LINK", "declaration");
99  text = replace(text, "MAP", "declaration");
100  text = replace(text, "PARAMETER", "declaration");
101  text = replace(text, "REAL", "declaration");
102  text = replace(text, "RULE", "declaration");
103  text = replace(text, "TYPE", "declaration");
104  text = replace(text, "UNIT", "declaration");
105 
106  return text;
107  }
std::string replace(const std::string &s, const std::string &val, const std::string &new_val)
not usable for gcc 4.8 std::vector<std::string> split( const std::string& orig, const std::string& de...

◆ __copyImports()

template<typename GUM_SCALAR >
INLINE std::vector< const O3Import *> gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__copyImports ( )
private

Definition at line 413 of file O3prmReader_tpl.h.

413  {
414  auto copy = std::vector< const O3Import* >();
415  for (const auto& i : __o3_prm->imports()) {
416  if (!__imported.exists(i->import().label())) { copy.push_back(i.get()); }
417  }
418  return copy;
419  }
std::unique_ptr< O3PRM > __o3_prm
Definition: O3prmReader.h:147
bool exists(const Key &k) const
Indicates whether a given elements belong to the set.
Definition: set_tpl.h:607
Set< std::string > __imported
Definition: O3prmReader.h:149

◆ __parseImport()

template<typename GUM_SCALAR >
INLINE void gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__parseImport ( const O3Import i,
const std::string &  module_path 
)
private

Definition at line 370 of file O3prmReader_tpl.h.

371  {
372  if (!__imported.exists(i.import().label())) {
373  __imported.insert(i.import().label());
374 
375  auto module_path = module;
376  std::replace(module_path.begin(), module_path.end(), '.', '/');
377 
378  auto path = i.import().label();
379  std::replace(path.begin(), path.end(), '.', '/');
380 
381  auto imported = false;
382  for (const auto& cp : __class_path) {
383  auto file_path = cp + path + ".o3prm";
384  std::ifstream file(file_path);
385 
386  if (file.is_open()) {
387  __parseStream(file, file_path, i.import().label());
388  imported = true;
389  break;
390  }
391 
392  file_path = cp + module + path + ".o3prm";
393  std::ifstream file2(file_path);
394 
395  if (file2.is_open()) {
396  __parseStream(file2, file_path, module + "." + i.import().label());
397  imported = true;
398  break;
399  }
400  }
401 
402  if (!imported) {
403  const auto& pos = i.import().position();
404  std::stringstream msg;
405  msg << "Import error: could not resolve import " << i.import().label();
406  __errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
407  }
408  }
409  }
std::vector< std::string > __class_path
Definition: O3prmReader.h:148
bool exists(const Key &k) const
Indicates whether a given elements belong to the set.
Definition: set_tpl.h:607
Set< std::string > __imported
Definition: O3prmReader.h:149
std::string replace(const std::string &s, const std::string &val, const std::string &new_val)
not usable for gcc 4.8 std::vector<std::string> split( const std::string& orig, const std::string& de...
void __parseStream(std::istream &input, const std::string &filename, const std::string &module)
void addError(const std::string &msg, const std::string &filename, Idx line, Idx col)
Adds an error.
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:613

◆ __parseStream()

template<typename GUM_SCALAR >
INLINE void gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__parseStream ( std::istream &  input,
const std::string &  filename,
const std::string &  module 
)
private

Definition at line 353 of file O3prmReader_tpl.h.

355  {
356  auto sBuff = __readStream(input);
357  auto buffer = std::unique_ptr< unsigned char[] >(
358  new unsigned char[sBuff.length() + 1]);
359  strcpy((char*)buffer.get(), sBuff.c_str());
360  auto s = o3prm_scanner(buffer.get(), int(sBuff.length() + 1), filename);
361  auto p = o3prm_parser(&s);
362  p.set_prm(__o3_prm.get());
363  p.set_prefix(module);
364  p.Parse();
365  __errors += p.errors();
366  }
void __readStream(std::istream &input, const std::string &file, std::string module="")
gum::prm::o3prm::Parser o3prm_parser
std::vector< ParseError > errors
The list of gum::ParseError contained in this gum::ErrorsContainer.
std::unique_ptr< O3PRM > __o3_prm
Definition: O3prmReader.h:147
gum::prm::o3prm::Scanner o3prm_scanner

◆ __print()

template<typename GUM_SCALAR >
INLINE std::string gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__print ( const ParseError err) const
private

Definition at line 111 of file O3prmReader_tpl.h.

111  {
112  std::stringstream s;
113  s << err.filename << "|" << err.line << " col " << err.column << "| "
114  << __clean(err.msg);
115  return s.str();
116  }
std::string __clean(std::string text) const

◆ __readStream() [1/2]

template<typename GUM_SCALAR >
INLINE void gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__readStream ( std::istream &  input,
const std::string &  file,
std::string  module = "" 
)
private

Definition at line 422 of file O3prmReader_tpl.h.

424  {
425  if (module.size() > 0 && module.back() != '.') { module.append("."); }
426 
427  __parseStream(input, file, module);
428 
429  auto imports = __copyImports();
430  do {
431  for (auto i : imports) {
432  __parseImport(*i, module);
433  }
434  imports = __copyImports();
435  } while (imports.size() > 0);
436 
437 
438  if (__errors.error_count == 0) {
439  auto solver = O3NameSolver< GUM_SCALAR >(*__prm, *__o3_prm, __errors);
440  auto type_factory =
441  O3TypeFactory< GUM_SCALAR >(*__prm, *__o3_prm, solver, __errors);
442 
443  auto interface_factory =
444  O3InterfaceFactory< GUM_SCALAR >(*__prm, *__o3_prm, solver, __errors);
445  auto class_factory =
446  O3ClassFactory< GUM_SCALAR >(*__prm, *__o3_prm, solver, __errors);
447 
448  auto system_factory =
449  O3SystemFactory< GUM_SCALAR >(*__prm, *__o3_prm, solver, __errors);
450 
451  try {
452  type_factory.build();
453  interface_factory.buildInterfaces();
454  class_factory.buildClasses();
455  interface_factory.buildElements();
456  class_factory.buildImplementations();
457  class_factory.buildParameters();
458  class_factory.buildReferenceSlots();
459  class_factory.declareAttributes();
460  class_factory.declareAggregates();
461  class_factory.completeAggregates();
462  class_factory.completeAttributes();
463  system_factory.build();
464  } catch (Exception&) {
465  if (__errors.count() == 0) {
466  __errors.addException("an unknown error occured", file);
467  }
468  // GUM_TRACE_NEWLINE;
469  // GUM_SHOWERROR( e );
470  } catch (...) {
471  __errors.addException("an unknown exception occured", file);
472  }
473  }
474  }
Size count() const
Returns the number of errors and warnings.
Size error_count
Number of errors detected.
std::unique_ptr< O3PRM > __o3_prm
Definition: O3prmReader.h:147
std::vector< const O3Import *> __copyImports()
void __parseImport(const O3Import &i, const std::string &module_path)
void __parseStream(std::istream &input, const std::string &filename, const std::string &module)
PRM< GUM_SCALAR > * __prm
Definition: O3prmReader.h:146
void addException(const std::string &msg, const std::string &filename)
Add an exception.

◆ __readStream() [2/2]

template<typename GUM_SCALAR >
INLINE std::string gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__readStream ( std::istream &  input)
private

Definition at line 120 of file O3prmReader_tpl.h.

120  {
121  if (inputstr) {
122  inputstr.seekg(0, inputstr.end);
123  int length = int(inputstr.tellg());
124  inputstr.seekg(0, inputstr.beg);
125 
126  auto str = std::string();
127  str.resize(length, ' ');
128  auto begin = &*str.begin();
129 
130  inputstr.read(begin, length);
131 
132  return str;
133  }
134  GUM_ERROR(OperationNotAllowed, "Could not open file");
135  }
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55

◆ addClassPath()

template<typename GUM_SCALAR >
void gum::prm::o3prm::O3prmReader< GUM_SCALAR >::addClassPath ( const std::string &  class_path)

Add a list of paths to look for o3prm files.

Use / for path separator ! Even on Windows !

Parameters
class_pathA semicolon separated list of paths.

Definition at line 223 of file O3prmReader_tpl.h.

Referenced by gum::prm::o3prmr::O3prmrInterpreter::interpretFile(), and gum::O3prmBNReader< GUM_SCALAR >::proceed().

223  {
224  auto path = class_path;
225  if (path[path.size() - 1] != '/') { path.append("/"); }
226  auto dir = Directory(path);
227 
228  if (!dir.isValid()) {
229  __errors.addException("could not resolve class path", path);
230  } else {
231  __class_path.push_back(std::move(path));
232  }
233  }
std::vector< std::string > __class_path
Definition: O3prmReader.h:148
void addException(const std::string &msg, const std::string &filename)
Add an exception.
+ Here is the caller graph for this function:

◆ errCol()

template<typename GUM_SCALAR >
INLINE Idx gum::prm::o3prm::O3prmReader< GUM_SCALAR >::errCol ( Idx  i) const

col of ith error or warning

Definition at line 241 of file O3prmReader_tpl.h.

Referenced by gum::prm::o3prm::O3prmReader< double >::prm().

241  {
242  return __errors.error(i).column;
243  }
ParseError error(Idx i) const
Returns the i-th error.
Idx column
The column of this gum::ParseError, default is 0.
+ Here is the caller graph for this function:

◆ errFilename()

template<typename GUM_SCALAR >
INLINE std::wstring gum::prm::o3prm::O3prmReader< GUM_SCALAR >::errFilename ( Idx  i) const

filename of ith error or warning

Definition at line 246 of file O3prmReader_tpl.h.

Referenced by gum::prm::o3prm::O3prmReader< double >::prm().

246  {
247  return widen(__errors.error(i).filename);
248  }
std::string filename
The file of this gum::ParseError, default is "".
std::wstring widen(const std::string &str)
Cast a std::string into a std::wstring.
ParseError error(Idx i) const
Returns the i-th error.
+ Here is the caller graph for this function:

◆ errIsError()

template<typename GUM_SCALAR >
INLINE bool gum::prm::o3prm::O3prmReader< GUM_SCALAR >::errIsError ( Idx  i) const

type of ith error or warning

Definition at line 251 of file O3prmReader_tpl.h.

Referenced by gum::prm::o3prm::O3prmReader< double >::prm().

251  {
252  return __errors.error(i).is_error;
253  }
bool is_error
If false, this gum::ParseError is a warning.
ParseError error(Idx i) const
Returns the i-th error.
+ Here is the caller graph for this function:

◆ errLine()

template<typename GUM_SCALAR >
INLINE Idx gum::prm::o3prm::O3prmReader< GUM_SCALAR >::errLine ( Idx  i) const

line of ith error or warning

Definition at line 236 of file O3prmReader_tpl.h.

Referenced by gum::prm::o3prm::O3prmReader< double >::prm().

236  {
237  return __errors.error(i).line;
238  }
Idx line
The line of this gum::ParseError.
ParseError error(Idx i) const
Returns the i-th error.
+ Here is the caller graph for this function:

◆ errMsg()

template<typename GUM_SCALAR >
INLINE std::string gum::prm::o3prm::O3prmReader< GUM_SCALAR >::errMsg ( Idx  i) const

message of ith error or warning

Definition at line 256 of file O3prmReader_tpl.h.

Referenced by gum::prm::o3prm::O3prmReader< double >::prm().

256  {
257  return __errors.error(i).msg;
258  }
std::string msg
The gum::ParseError message.
ParseError error(Idx i) const
Returns the i-th error.
+ Here is the caller graph for this function:

◆ errors()

template<typename GUM_SCALAR >
INLINE Size gum::prm::o3prm::O3prmReader< GUM_SCALAR >::errors ( ) const

publishing Errors API

of errors

Definition at line 285 of file O3prmReader_tpl.h.

Referenced by gum::prm::o3prmr::O3prmrInterpreter::import(), and gum::prm::o3prm::O3prmReader< double >::prm().

285  {
286  return __errors.error_count;
287  }
Size error_count
Number of errors detected.
+ Here is the caller graph for this function:

◆ errorsContainer()

template<typename GUM_SCALAR >
INLINE const ErrorsContainer & gum::prm::o3prm::O3prmReader< GUM_SCALAR >::errorsContainer ( ) const

publishing Errors API

of errors

Definition at line 296 of file O3prmReader_tpl.h.

Referenced by gum::prm::o3prmr::O3prmrInterpreter::import(), gum::prm::o3prm::O3prmReader< double >::prm(), and gum::O3prmBNReader< GUM_SCALAR >::proceed().

296  {
297  return __errors;
298  }
+ Here is the caller graph for this function:

◆ operator=() [1/2]

template<typename GUM_SCALAR >
INLINE O3prmReader< GUM_SCALAR > & gum::prm::o3prm::O3prmReader< GUM_SCALAR >::operator= ( const O3prmReader< GUM_SCALAR > &  src)

Definition at line 178 of file O3prmReader_tpl.h.

178  {
179  if (this == &src) { return *this; }
180  __prm = src.__prm;
181  __o3_prm = std::unique_ptr< O3PRM >(new O3PRM(*(src.__o3_prm)));
182  __class_path = src.__class_path;
183  __imported = src.__imported;
184  __errors = src.__errors;
185  return *this;
186  }
std::vector< std::string > __class_path
Definition: O3prmReader.h:148
std::unique_ptr< O3PRM > __o3_prm
Definition: O3prmReader.h:147
Set< std::string > __imported
Definition: O3prmReader.h:149
PRM< GUM_SCALAR > * __prm
Definition: O3prmReader.h:146

◆ operator=() [2/2]

template<typename GUM_SCALAR >
INLINE O3prmReader< GUM_SCALAR > & gum::prm::o3prm::O3prmReader< GUM_SCALAR >::operator= ( O3prmReader< GUM_SCALAR > &&  src)

Definition at line 190 of file O3prmReader_tpl.h.

190  {
191  if (this == &src) { return *this; }
192  __prm = std::move(src.__prm);
193  __o3_prm = std::move(src.__o3_prm);
194  __class_path = std::move(src.__class_path);
195  __imported = std::move(src.__imported);
196  __errors = std::move(src.__errors);
197  return *this;
198  }
std::vector< std::string > __class_path
Definition: O3prmReader.h:148
std::unique_ptr< O3PRM > __o3_prm
Definition: O3prmReader.h:147
Set< std::string > __imported
Definition: O3prmReader.h:149
PRM< GUM_SCALAR > * __prm
Definition: O3prmReader.h:146

◆ parseStream()

template<typename GUM_SCALAR >
INLINE void gum::prm::o3prm::O3prmReader< GUM_SCALAR >::parseStream ( std::istream &  input,
std::ostream &  output,
std::string  module = "" 
)

Definition at line 343 of file O3prmReader_tpl.h.

345  {
346  __readStream(input, "", module);
347 
349  }
void __readStream(std::istream &input, const std::string &file, std::string module="")
void showElegantErrorsAndWarnings(std::ostream &o=std::cerr) const
send on std::cerr the list of errors or warnings

◆ prm() [1/2]

template<typename GUM_SCALAR>
gum::prm::PRM< GUM_SCALAR >* gum::prm::o3prm::O3prmReader< GUM_SCALAR >::prm ( )
inline

Definition at line 110 of file O3prmReader.h.

Referenced by gum::prm::o3prmr::O3prmrInterpreter::interpretFile(), gum::prm::o3prmr::O3prmrInterpreter::prm(), gum::O3prmBNReader< GUM_SCALAR >::proceed(), and gum::prm::o3prmr::O3prmrInterpreter::~O3prmrInterpreter().

110 { return __prm; }
PRM< GUM_SCALAR > * __prm
Definition: O3prmReader.h:146
+ Here is the caller graph for this function:

◆ prm() [2/2]

template<typename GUM_SCALAR>
const gum::prm::PRM< GUM_SCALAR >* gum::prm::o3prm::O3prmReader< GUM_SCALAR >::prm ( ) const
inline

Definition at line 111 of file O3prmReader.h.

111 { return __prm; }
PRM< GUM_SCALAR > * __prm
Definition: O3prmReader.h:146

◆ readFile()

template<typename GUM_SCALAR >
INLINE Size gum::prm::o3prm::O3prmReader< GUM_SCALAR >::readFile ( const std::string &  file,
const std::string &  module = "" 
)

Read file and load its content using a PRMFactory. The package parameter set the file's content package.

Definition at line 308 of file O3prmReader_tpl.h.

Referenced by gum::prm::o3prmr::O3prmrInterpreter::import(), and gum::O3prmBNReader< GUM_SCALAR >::proceed().

309  {
310  try {
311  auto lastSlashIndex = file.find_last_of('/');
312 
313  auto dir = Directory(file.substr(0, lastSlashIndex + 1));
314 
315  if (!dir.isValid()) {
316  __errors.addException("could not find file", file);
317  return __errors.count();
318  }
319 
320  auto basename = file.substr(lastSlashIndex + 1);
321  auto absFilename = dir.absolutePath() + basename;
322 
323  std::ifstream input(absFilename);
324  if (input.is_open()) {
325  __readStream(input, file, module);
326  } else {
327  __errors.addException("could not open file", file);
328  }
329 
330  return __errors.count();
331 
332  } catch (gum::Exception& e) {
333  GUM_SHOWERROR(e);
335  return __errors.count();
336  } catch (...) {
337  __errors.addException("unknown error", file);
338  return __errors.count();
339  }
340  }
void __readStream(std::istream &input, const std::string &file, std::string module="")
Size count() const
Returns the number of errors and warnings.
#define GUM_SHOWERROR(e)
Definition: exceptions.h:61
Base class for all aGrUM&#39;s exceptions.
Definition: exceptions.h:106
const std::string errorContent() const
Returns the message content.
Definition: exceptions.h:135
void addException(const std::string &msg, const std::string &filename)
Add an exception.
+ Here is the caller graph for this function:

◆ readString()

template<typename GUM_SCALAR >
INLINE Size gum::prm::o3prm::O3prmReader< GUM_SCALAR >::readString ( const std::string &  string)

With readString method, you must set the current path to search from import yourself, using addClassPath.

Definition at line 301 of file O3prmReader_tpl.h.

301  {
302  std::stringstream sBuff(str);
303  __readStream(sBuff, "");
304  return __errors.count();
305  }
void __readStream(std::istream &input, const std::string &file, std::string module="")
Size count() const
Returns the number of errors and warnings.

◆ setClassPath()

template<typename GUM_SCALAR >
void gum::prm::o3prm::O3prmReader< GUM_SCALAR >::setClassPath ( const std::string &  class_path)

This methods defines the list of paths to look for o3prm files.

Use / for path separator ! Even on Windows !

Parameters
class_pathA semicolon separated list of paths.

Definition at line 201 of file O3prmReader_tpl.h.

201  {
202  __class_path = std::vector< std::string >();
203  size_t i = 0;
204  size_t j = class_path.find(';');
205 
206  while (j != std::string::npos) {
207  addClassPath(class_path.substr(i, j - i));
208  i = j + 1;
209 
210  if (i < class_path.size()) {
211  j = class_path.find(';', i);
212  } else {
213  j = std::string::npos;
214  }
215  }
216 
217  if (i < class_path.size()) {
218  addClassPath(class_path.substr(i, std::string::npos));
219  }
220  }
std::vector< std::string > __class_path
Definition: O3prmReader.h:148
void addClassPath(const std::string &class_path)
Add a list of paths to look for o3prm files.

◆ showElegantErrors()

template<typename GUM_SCALAR >
INLINE void gum::prm::o3prm::O3prmReader< GUM_SCALAR >::showElegantErrors ( std::ostream &  o = std::cerr) const

send on std::cerr the list of errors

Definition at line 262 of file O3prmReader_tpl.h.

Referenced by gum::prm::o3prm::O3prmReader< double >::prm().

262  {
263  for (Idx i = 0; i < __errors.count(); ++i) {
264  auto err = __errors.error(i);
265  if (err.is_error) { o << __print(err) << std::endl; }
266  }
267  }
Size count() const
Returns the number of errors and warnings.
std::string __print(const ParseError &err) const
ParseError error(Idx i) const
Returns the i-th error.
+ Here is the caller graph for this function:

◆ showElegantErrorsAndWarnings()

template<typename GUM_SCALAR >
INLINE void gum::prm::o3prm::O3prmReader< GUM_SCALAR >::showElegantErrorsAndWarnings ( std::ostream &  o = std::cerr) const

send on std::cerr the list of errors or warnings

Definition at line 270 of file O3prmReader_tpl.h.

Referenced by gum::prm::o3prm::O3prmReader< double >::prm().

271  {
272  for (Idx i = 0; i < __errors.count(); ++i) {
273  auto err = __errors.error(i);
274  o << __print(err) << std::endl;
275  }
276  }
Size count() const
Returns the number of errors and warnings.
std::string __print(const ParseError &err) const
ParseError error(Idx i) const
Returns the i-th error.
+ Here is the caller graph for this function:

◆ showErrorCounts()

template<typename GUM_SCALAR >
INLINE void gum::prm::o3prm::O3prmReader< GUM_SCALAR >::showErrorCounts ( std::ostream &  o = std::cerr) const

send on std::cerr the number of errors and the number of warnings

Definition at line 280 of file O3prmReader_tpl.h.

Referenced by gum::prm::o3prm::O3prmReader< double >::prm().

280  {
282  }
void syntheticResults(std::ostream &o) const
Print errors on output stream.
+ Here is the caller graph for this function:

◆ warnings()

template<typename GUM_SCALAR >
INLINE Size gum::prm::o3prm::O3prmReader< GUM_SCALAR >::warnings ( ) const

of errors

Definition at line 290 of file O3prmReader_tpl.h.

Referenced by gum::prm::o3prm::O3prmReader< double >::prm().

290  {
291  return __errors.warning_count;
292  }
+ Here is the caller graph for this function:

Member Data Documentation

◆ __class_path

template<typename GUM_SCALAR>
std::vector< std::string > gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__class_path
private

Definition at line 148 of file O3prmReader.h.

Referenced by gum::prm::o3prm::O3prmReader< double >::operator=().

◆ __errors

template<typename GUM_SCALAR>
ErrorsContainer gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__errors
private

Definition at line 152 of file O3prmReader.h.

Referenced by gum::prm::o3prm::O3prmReader< double >::operator=().

◆ __imported

template<typename GUM_SCALAR>
Set< std::string > gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__imported
private

Definition at line 149 of file O3prmReader.h.

Referenced by gum::prm::o3prm::O3prmReader< double >::operator=().

◆ __o3_prm

template<typename GUM_SCALAR>
std::unique_ptr< O3PRM > gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__o3_prm
private

Definition at line 147 of file O3prmReader.h.

Referenced by gum::prm::o3prm::O3prmReader< double >::operator=().

◆ __prm

template<typename GUM_SCALAR>
PRM< GUM_SCALAR >* gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__prm
private

The documentation for this class was generated from the following files: