aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
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 68 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 136 of file O3prmReader_tpl.h.

136  :
137  _prm_(new PRM< GUM_SCALAR >()), _o3_prm_(std::unique_ptr< O3PRM >(new O3PRM())) {
138  GUM_CONSTRUCTOR(O3prmReader);
139  }
PRM< GUM_SCALAR > * _prm_
Definition: O3prmReader.h:143
std::unique_ptr< O3PRM > _o3_prm_
Definition: O3prmReader.h:144

◆ O3prmReader() [2/4]

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

Definition at line 142 of file O3prmReader_tpl.h.

142  :
143  _prm_(&prm), _o3_prm_(std::unique_ptr< O3PRM >(new O3PRM())) {
144  GUM_CONSTRUCTOR(O3prmReader);
145  }
gum::prm::PRM< GUM_SCALAR > * prm()
Definition: O3prmReader.h:107
PRM< GUM_SCALAR > * _prm_
Definition: O3prmReader.h:143
std::unique_ptr< O3PRM > _o3_prm_
Definition: O3prmReader.h:144

◆ O3prmReader() [3/4]

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

Definition at line 148 of file O3prmReader_tpl.h.

148  :
149  _prm_(src._prm_), _o3_prm_(std::unique_ptr< O3PRM >(new O3PRM(*(src._o3_prm_)))),
150  _class_path_(src._class_path_), _imported_(src._imported_), _errors_(src._errors_) {
151  GUM_CONS_CPY(O3prmReader);
152  }
std::vector< std::string > _class_path_
Definition: O3prmReader.h:145
PRM< GUM_SCALAR > * _prm_
Definition: O3prmReader.h:143
std::unique_ptr< O3PRM > _o3_prm_
Definition: O3prmReader.h:144
Set< std::string > _imported_
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 155 of file O3prmReader_tpl.h.

155  :
156  _prm_(std::move(src._prm_)), _o3_prm_(std::move(src._o3_prm_)),
157  _class_path_(std::move(src._class_path_)), _imported_(std::move(src._imported_)),
158  _errors_(std::move(src._errors_)) {
159  GUM_CONS_CPY(O3prmReader);
160  }
std::vector< std::string > _class_path_
Definition: O3prmReader.h:145
PRM< GUM_SCALAR > * _prm_
Definition: O3prmReader.h:143
std::unique_ptr< O3PRM > _o3_prm_
Definition: O3prmReader.h:144
Set< std::string > _imported_
Definition: O3prmReader.h:146

◆ ~O3prmReader()

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

Definition at line 163 of file O3prmReader_tpl.h.

163  {
164  GUM_DESTRUCTOR(O3prmReader);
165  }

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 36 of file O3prmReader_tpl.h.

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

393  {
394  auto copy = std::vector< const O3Import* >();
395  for (const auto& i: _o3_prm_->imports()) {
396  if (!_imported_.exists(i->import().label())) { copy.push_back(i.get()); }
397  }
398  return copy;
399  }
bool exists(const Key &k) const
Indicates whether a given elements belong to the set.
Definition: set_tpl.h:600
std::unique_ptr< O3PRM > _o3_prm_
Definition: O3prmReader.h:144
Set< std::string > _imported_
Definition: O3prmReader.h:146

◆ _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 351 of file O3prmReader_tpl.h.

352  {
353  if (!_imported_.exists(i.import().label())) {
354  _imported_.insert(i.import().label());
355 
356  auto module_path = module;
357  std::replace(module_path.begin(), module_path.end(), '.', '/');
358 
359  auto path = i.import().label();
360  std::replace(path.begin(), path.end(), '.', '/');
361 
362  auto imported = false;
363  for (const auto& cp: _class_path_) {
364  auto file_path = cp + path + ".o3prm";
365  std::ifstream file(file_path);
366 
367  if (file.is_open()) {
368  _parseStream_(file, file_path, i.import().label());
369  imported = true;
370  break;
371  }
372 
373  file_path = cp + module + path + ".o3prm";
374  std::ifstream file2(file_path);
375 
376  if (file2.is_open()) {
377  _parseStream_(file2, file_path, module + "." + i.import().label());
378  imported = true;
379  break;
380  }
381  }
382 
383  if (!imported) {
384  const auto& pos = i.import().position();
385  std::stringstream msg;
386  msg << "Import error: could not resolve import " << i.import().label();
387  _errors_.addError(msg.str(), pos.file(), pos.line(), pos.column());
388  }
389  }
390  }
std::vector< std::string > _class_path_
Definition: O3prmReader.h:145
void _parseStream_(std::istream &input, const std::string &filename, const std::string &module)
bool exists(const Key &k) const
Indicates whether a given elements belong to the set.
Definition: set_tpl.h:600
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 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:606
Set< std::string > _imported_
Definition: O3prmReader.h:146

◆ _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 336 of file O3prmReader_tpl.h.

338  {
339  auto sBuff = _readStream_(input);
340  auto buffer = std::unique_ptr< unsigned char[] >(new unsigned char[sBuff.length() + 1]);
341  strcpy((char*)buffer.get(), sBuff.c_str());
342  auto s = o3prm_scanner(buffer.get(), int(sBuff.length() + 1), filename);
343  auto p = o3prm_parser(&s);
344  p.set_prm(_o3_prm_.get());
345  p.set_prefix(module);
346  p.Parse();
347  _errors_ += p.errors();
348  }
gum::prm::o3prm::Parser o3prm_parser
std::vector< ParseError > errors
The list of gum::ParseError contained in this gum::ErrorsContainer.
void _readStream_(std::istream &input, const std::string &file, std::string module="")
gum::prm::o3prm::Scanner o3prm_scanner
std::unique_ptr< O3PRM > _o3_prm_
Definition: O3prmReader.h:144

◆ _print_()

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

Definition at line 108 of file O3prmReader_tpl.h.

108  {
109  std::stringstream s;
110  s << err.filename << "|" << err.line << " col " << err.column << "| " << _clean_(err.msg);
111  return s.str();
112  }
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 402 of file O3prmReader_tpl.h.

404  {
405  if (module.size() > 0 && module.back() != '.') { module.append("."); }
406 
407  _parseStream_(input, file, module);
408 
409  auto imports = _copyImports_();
410  do {
411  for (auto i: imports) {
412  _parseImport_(*i, module);
413  }
414  imports = _copyImports_();
415  } while (imports.size() > 0);
416 
417 
418  if (_errors_.error_count == 0) {
419  auto solver = O3NameSolver< GUM_SCALAR >(*_prm_, *_o3_prm_, _errors_);
420  auto type_factory = O3TypeFactory< GUM_SCALAR >(*_prm_, *_o3_prm_, solver, _errors_);
421 
422  auto interface_factory
423  = O3InterfaceFactory< GUM_SCALAR >(*_prm_, *_o3_prm_, solver, _errors_);
424  auto class_factory = O3ClassFactory< GUM_SCALAR >(*_prm_, *_o3_prm_, solver, _errors_);
425 
426  auto system_factory = O3SystemFactory< GUM_SCALAR >(*_prm_, *_o3_prm_, solver, _errors_);
427 
428  try {
429  type_factory.build();
430  interface_factory.buildInterfaces();
431  class_factory.buildClasses();
432  interface_factory.buildElements();
433  class_factory.buildImplementations();
434  class_factory.buildParameters();
435  class_factory.buildReferenceSlots();
436  class_factory.declareAttributes();
437  class_factory.declareAggregates();
438  class_factory.completeAggregates();
439  class_factory.completeAttributes();
440  system_factory.build();
441  } catch (Exception&) {
442  if (_errors_.count() == 0) { _errors_.addException("an unknown error occured", file); }
443  } catch (...) { _errors_.addException("an unknown exception occured", file); }
444  }
445  }
Size count() const
Returns the number of errors and warnings.
Size error_count
Number of errors detected.
PRM< GUM_SCALAR > * _prm_
Definition: O3prmReader.h:143
void _parseImport_(const O3Import &i, const std::string &module_path)
void _parseStream_(std::istream &input, const std::string &filename, const std::string &module)
std::unique_ptr< O3PRM > _o3_prm_
Definition: O3prmReader.h:144
std::vector< const O3Import *> _copyImports_()
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 115 of file O3prmReader_tpl.h.

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

◆ 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 211 of file O3prmReader_tpl.h.

211  {
212  auto path = class_path;
213  if (path[path.size() - 1] != '/') { path.append("/"); }
214  auto dir = Directory(path);
215 
216  if (!dir.isValid()) {
217  _errors_.addException("could not resolve class path", path);
218  } else {
219  _class_path_.push_back(std::move(path));
220  }
221  }
std::vector< std::string > _class_path_
Definition: O3prmReader.h:145
void addException(const std::string &msg, const std::string &filename)
Add an exception.

◆ 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 229 of file O3prmReader_tpl.h.

229  {
230  return _errors_.error(i).column;
231  }
ParseError error(Idx i) const
Returns the i-th error.
Idx column
The column of this gum::ParseError, default is 0.

◆ 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 234 of file O3prmReader_tpl.h.

234  {
235  return widen(_errors_.error(i).filename);
236  }
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.

◆ 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 239 of file O3prmReader_tpl.h.

239  {
240  return _errors_.error(i).is_error;
241  }
bool is_error
If false, this gum::ParseError is a warning.
ParseError error(Idx i) const
Returns the i-th error.

◆ 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 224 of file O3prmReader_tpl.h.

224  {
225  return _errors_.error(i).line;
226  }
Idx line
The line of this gum::ParseError.
ParseError error(Idx i) const
Returns the i-th error.

◆ 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 244 of file O3prmReader_tpl.h.

244  {
245  return _errors_.error(i).msg;
246  }
std::string msg
The gum::ParseError message.
ParseError error(Idx i) const
Returns the i-th error.

◆ errors()

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

publishing Errors API

of errors

Definition at line 270 of file O3prmReader_tpl.h.

270  {
271  return _errors_.error_count;
272  }
Size error_count
Number of errors detected.

◆ errorsContainer()

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

publishing Errors API

of errors

Definition at line 280 of file O3prmReader_tpl.h.

280  {
281  return _errors_;
282  }

◆ 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 169 of file O3prmReader_tpl.h.

169  {
170  if (this == &src) { return *this; }
171  _prm_ = src._prm_;
172  _o3_prm_ = std::unique_ptr< O3PRM >(new O3PRM(*(src._o3_prm_)));
173  _class_path_ = src._class_path_;
174  _imported_ = src._imported_;
175  _errors_ = src._errors_;
176  return *this;
177  }
std::vector< std::string > _class_path_
Definition: O3prmReader.h:145
PRM< GUM_SCALAR > * _prm_
Definition: O3prmReader.h:143
std::unique_ptr< O3PRM > _o3_prm_
Definition: O3prmReader.h:144
Set< std::string > _imported_
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 180 of file O3prmReader_tpl.h.

180  {
181  if (this == &src) { return *this; }
182  _prm_ = std::move(src._prm_);
183  _o3_prm_ = std::move(src._o3_prm_);
184  _class_path_ = std::move(src._class_path_);
185  _imported_ = std::move(src._imported_);
186  _errors_ = std::move(src._errors_);
187  return *this;
188  }
std::vector< std::string > _class_path_
Definition: O3prmReader.h:145
PRM< GUM_SCALAR > * _prm_
Definition: O3prmReader.h:143
std::unique_ptr< O3PRM > _o3_prm_
Definition: O3prmReader.h:144
Set< std::string > _imported_
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 327 of file O3prmReader_tpl.h.

329  {
330  _readStream_(input, "", module);
331 
333  }
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 107 of file O3prmReader.h.

107 { return _prm_; }
PRM< GUM_SCALAR > * _prm_
Definition: O3prmReader.h:143

◆ 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 108 of file O3prmReader.h.

108 { return _prm_; }
PRM< GUM_SCALAR > * _prm_
Definition: O3prmReader.h:143

◆ 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 292 of file O3prmReader_tpl.h.

293  {
294  try {
295  auto lastSlashIndex = file.find_last_of('/');
296 
297  auto dir = Directory(file.substr(0, lastSlashIndex + 1));
298 
299  if (!dir.isValid()) {
300  _errors_.addException("could not find file", file);
301  return _errors_.count();
302  }
303 
304  auto basename = file.substr(lastSlashIndex + 1);
305  auto absFilename = dir.absolutePath() + basename;
306 
307  std::ifstream input(absFilename);
308  if (input.is_open()) {
309  _readStream_(input, file, module);
310  } else {
311  _errors_.addException("could not open file", file);
312  }
313 
314  return _errors_.count();
315 
316  } catch (gum::Exception& e) {
317  GUM_SHOWERROR(e);
319  return _errors_.count();
320  } catch (...) {
321  _errors_.addException("unknown error", file);
322  return _errors_.count();
323  }
324  }
Size count() const
Returns the number of errors and warnings.
#define GUM_SHOWERROR(e)
Definition: exceptions.h:57
void _readStream_(std::istream &input, const std::string &file, std::string module="")
std::string errorContent() const
Returns the message content.
Definition: exceptions.h:130
Base class for all aGrUM&#39;s exceptions.
Definition: exceptions.h:102
void addException(const std::string &msg, const std::string &filename)
Add an exception.

◆ 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 285 of file O3prmReader_tpl.h.

285  {
286  std::stringstream sBuff(str);
287  _readStream_(sBuff, "");
288  return _errors_.count();
289  }
Size count() const
Returns the number of errors and warnings.
void _readStream_(std::istream &input, const std::string &file, std::string module="")

◆ 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 191 of file O3prmReader_tpl.h.

191  {
192  _class_path_ = std::vector< std::string >();
193  size_t i = 0;
194  size_t j = class_path.find(';');
195 
196  while (j != std::string::npos) {
197  addClassPath(class_path.substr(i, j - i));
198  i = j + 1;
199 
200  if (i < class_path.size()) {
201  j = class_path.find(';', i);
202  } else {
203  j = std::string::npos;
204  }
205  }
206 
207  if (i < class_path.size()) { addClassPath(class_path.substr(i, std::string::npos)); }
208  }
std::vector< std::string > _class_path_
Definition: O3prmReader.h:145
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 249 of file O3prmReader_tpl.h.

249  {
250  for (Idx i = 0; i < _errors_.count(); ++i) {
251  auto err = _errors_.error(i);
252  if (err.is_error) { o << _print_(err) << std::endl; }
253  }
254  }
std::string _print_(const ParseError &err) const
Size count() const
Returns the number of errors and warnings.
ParseError error(Idx i) const
Returns the i-th error.

◆ 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 257 of file O3prmReader_tpl.h.

257  {
258  for (Idx i = 0; i < _errors_.count(); ++i) {
259  auto err = _errors_.error(i);
260  o << _print_(err) << std::endl;
261  }
262  }
std::string _print_(const ParseError &err) const
Size count() const
Returns the number of errors and warnings.
ParseError error(Idx i) const
Returns the i-th error.

◆ 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 265 of file O3prmReader_tpl.h.

265  {
267  }
void syntheticResults(std::ostream &o) const
Print errors on output stream.

◆ warnings()

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

of errors

Definition at line 275 of file O3prmReader_tpl.h.

275  {
276  return _errors_.warning_count;
277  }

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 145 of file O3prmReader.h.

◆ _errors_

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

Definition at line 149 of file O3prmReader.h.

◆ _imported_

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

Definition at line 146 of file O3prmReader.h.

◆ _o3_prm_

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

Definition at line 144 of file O3prmReader.h.

◆ _prm_

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

Definition at line 143 of file O3prmReader.h.


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