aGrUM  0.20.2
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 140 of file O3prmReader_tpl.h.

140  :
141  prm__(new PRM< GUM_SCALAR >()),
142  o3_prm__(std::unique_ptr< O3PRM >(new O3PRM())) {
143  GUM_CONSTRUCTOR(O3prmReader);
144  }
PRM< GUM_SCALAR > * prm__
Definition: O3prmReader.h:145
std::unique_ptr< O3PRM > o3_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 147 of file O3prmReader_tpl.h.

147  :
148  prm__(&prm), o3_prm__(std::unique_ptr< O3PRM >(new O3PRM())) {
149  GUM_CONSTRUCTOR(O3prmReader);
150  }
PRM< GUM_SCALAR > * prm__
Definition: O3prmReader.h:145
std::unique_ptr< O3PRM > o3_prm__
Definition: O3prmReader.h:146
gum::prm::PRM< GUM_SCALAR > * prm()
Definition: O3prmReader.h:109

◆ O3prmReader() [3/4]

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

Definition at line 153 of file O3prmReader_tpl.h.

153  :
154  prm__(src.prm__),
155  o3_prm__(std::unique_ptr< O3PRM >(new O3PRM(*(src.o3_prm__)))),
156  class_path__(src.class_path__), imported__(src.imported__),
157  errors__(src.errors__) {
158  GUM_CONS_CPY(O3prmReader);
159  }
PRM< GUM_SCALAR > * prm__
Definition: O3prmReader.h:145
std::unique_ptr< O3PRM > o3_prm__
Definition: O3prmReader.h:146
std::vector< std::string > class_path__
Definition: O3prmReader.h:147
Set< std::string > imported__
Definition: O3prmReader.h:148

◆ O3prmReader() [4/4]

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

Definition at line 162 of file O3prmReader_tpl.h.

162  :
163  prm__(std::move(src.prm__)), o3_prm__(std::move(src.o3_prm__)),
164  class_path__(std::move(src.class_path__)),
165  imported__(std::move(src.imported__)),
166  errors__(std::move(src.errors__)) {
167  GUM_CONS_CPY(O3prmReader);
168  }
PRM< GUM_SCALAR > * prm__
Definition: O3prmReader.h:145
std::unique_ptr< O3PRM > o3_prm__
Definition: O3prmReader.h:146
std::vector< std::string > class_path__
Definition: O3prmReader.h:147
Set< std::string > imported__
Definition: O3prmReader.h:148

◆ ~O3prmReader()

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

Definition at line 171 of file O3prmReader_tpl.h.

171  {
172  GUM_DESTRUCTOR(O3prmReader);
173  }

Member Function Documentation

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

222  {
223  auto path = class_path;
224  if (path[path.size() - 1] != '/') { path.append("/"); }
225  auto dir = Directory(path);
226 
227  if (!dir.isValid()) {
228  errors__.addException("could not resolve class path", path);
229  } else {
230  class_path__.push_back(std::move(path));
231  }
232  }
std::vector< std::string > class_path__
Definition: O3prmReader.h:147
void addException(const std::string &msg, const std::string &filename)
Add an exception.

◆ clean__()

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

Definition at line 37 of file O3prmReader_tpl.h.

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

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

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

240  {
241  return errors__.error(i).column;
242  }
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 245 of file O3prmReader_tpl.h.

245  {
246  return widen(errors__.error(i).filename);
247  }
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 250 of file O3prmReader_tpl.h.

250  {
251  return errors__.error(i).is_error;
252  }
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 235 of file O3prmReader_tpl.h.

235  {
236  return errors__.error(i).line;
237  }
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 255 of file O3prmReader_tpl.h.

255  {
256  return errors__.error(i).msg;
257  }
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 284 of file O3prmReader_tpl.h.

284  {
285  return errors__.error_count;
286  }
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 295 of file O3prmReader_tpl.h.

295  {
296  return errors__;
297  }

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

177  {
178  if (this == &src) { return *this; }
179  prm__ = src.prm__;
180  o3_prm__ = std::unique_ptr< O3PRM >(new O3PRM(*(src.o3_prm__)));
181  class_path__ = src.class_path__;
182  imported__ = src.imported__;
183  errors__ = src.errors__;
184  return *this;
185  }
PRM< GUM_SCALAR > * prm__
Definition: O3prmReader.h:145
std::unique_ptr< O3PRM > o3_prm__
Definition: O3prmReader.h:146
std::vector< std::string > class_path__
Definition: O3prmReader.h:147
Set< std::string > imported__
Definition: O3prmReader.h:148

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

189  {
190  if (this == &src) { return *this; }
191  prm__ = std::move(src.prm__);
192  o3_prm__ = std::move(src.o3_prm__);
193  class_path__ = std::move(src.class_path__);
194  imported__ = std::move(src.imported__);
195  errors__ = std::move(src.errors__);
196  return *this;
197  }
PRM< GUM_SCALAR > * prm__
Definition: O3prmReader.h:145
std::unique_ptr< O3PRM > o3_prm__
Definition: O3prmReader.h:146
std::vector< std::string > class_path__
Definition: O3prmReader.h:147
Set< std::string > imported__
Definition: O3prmReader.h:148

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

370  {
371  if (!imported__.exists(i.import().label())) {
372  imported__.insert(i.import().label());
373 
374  auto module_path = module;
375  std::replace(module_path.begin(), module_path.end(), '.', '/');
376 
377  auto path = i.import().label();
378  std::replace(path.begin(), path.end(), '.', '/');
379 
380  auto imported = false;
381  for (const auto& cp: class_path__) {
382  auto file_path = cp + path + ".o3prm";
383  std::ifstream file(file_path);
384 
385  if (file.is_open()) {
386  parseStream__(file, file_path, i.import().label());
387  imported = true;
388  break;
389  }
390 
391  file_path = cp + module + path + ".o3prm";
392  std::ifstream file2(file_path);
393 
394  if (file2.is_open()) {
395  parseStream__(file2, file_path, module + "." + i.import().label());
396  imported = true;
397  break;
398  }
399  }
400 
401  if (!imported) {
402  const auto& pos = i.import().position();
403  std::stringstream msg;
404  msg << "Import error: could not resolve import " << i.import().label();
405  errors__.addError(msg.str(), pos.file(), pos.line(), pos.column());
406  }
407  }
408  }
std::vector< std::string > class_path__
Definition: O3prmReader.h:147
Set< std::string > imported__
Definition: O3prmReader.h:148
bool exists(const Key &k) const
Indicates whether a given elements belong to the set.
Definition: set_tpl.h:626
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:632

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

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

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

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

◆ print__()

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

Definition at line 110 of file O3prmReader_tpl.h.

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

◆ prm() [1/2]

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

Definition at line 109 of file O3prmReader.h.

109 { return prm__; }
PRM< GUM_SCALAR > * prm__
Definition: O3prmReader.h:145

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

110 { return prm__; }
PRM< GUM_SCALAR > * prm__
Definition: O3prmReader.h:145

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

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

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

423  {
424  if (module.size() > 0 && module.back() != '.') { module.append("."); }
425 
426  parseStream__(input, file, module);
427 
428  auto imports = copyImports__();
429  do {
430  for (auto i: imports) {
431  parseImport__(*i, module);
432  }
433  imports = copyImports__();
434  } while (imports.size() > 0);
435 
436 
437  if (errors__.error_count == 0) {
438  auto solver = O3NameSolver< GUM_SCALAR >(*prm__, *o3_prm__, errors__);
439  auto type_factory
440  = O3TypeFactory< GUM_SCALAR >(*prm__, *o3_prm__, solver, errors__);
441 
442  auto interface_factory = O3InterfaceFactory< GUM_SCALAR >(*prm__,
443  *o3_prm__,
444  solver,
445  errors__);
446  auto class_factory
447  = O3ClassFactory< GUM_SCALAR >(*prm__, *o3_prm__, solver, errors__);
448 
449  auto system_factory
450  = O3SystemFactory< GUM_SCALAR >(*prm__, *o3_prm__, solver, errors__);
451 
452  try {
453  type_factory.build();
454  interface_factory.buildInterfaces();
455  class_factory.buildClasses();
456  interface_factory.buildElements();
457  class_factory.buildImplementations();
458  class_factory.buildParameters();
459  class_factory.buildReferenceSlots();
460  class_factory.declareAttributes();
461  class_factory.declareAggregates();
462  class_factory.completeAggregates();
463  class_factory.completeAttributes();
464  system_factory.build();
465  } catch (Exception&) {
466  if (errors__.count() == 0) {
467  errors__.addException("an unknown error occured", file);
468  }
469  // GUM_TRACE_NEWLINE;
470  // GUM_SHOWERROR( e );
471  } catch (...) {
472  errors__.addException("an unknown exception occured", file);
473  }
474  }
475  }
PRM< GUM_SCALAR > * prm__
Definition: O3prmReader.h:145
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:146
void parseImport__(const O3Import &i, const std::string &module_path)
void parseStream__(std::istream &input, const std::string &filename, const std::string &module)
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 119 of file O3prmReader_tpl.h.

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

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

300  {
301  std::stringstream sBuff(str);
302  readStream__(sBuff, "");
303  return errors__.count();
304  }
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 200 of file O3prmReader_tpl.h.

200  {
201  class_path__ = std::vector< std::string >();
202  size_t i = 0;
203  size_t j = class_path.find(';');
204 
205  while (j != std::string::npos) {
206  addClassPath(class_path.substr(i, j - i));
207  i = j + 1;
208 
209  if (i < class_path.size()) {
210  j = class_path.find(';', i);
211  } else {
212  j = std::string::npos;
213  }
214  }
215 
216  if (i < class_path.size()) {
217  addClassPath(class_path.substr(i, std::string::npos));
218  }
219  }
std::vector< std::string > class_path__
Definition: O3prmReader.h:147
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 261 of file O3prmReader_tpl.h.

261  {
262  for (Idx i = 0; i < errors__.count(); ++i) {
263  auto err = errors__.error(i);
264  if (err.is_error) { o << print__(err) << std::endl; }
265  }
266  }
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.

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

270  {
271  for (Idx i = 0; i < errors__.count(); ++i) {
272  auto err = errors__.error(i);
273  o << print__(err) << std::endl;
274  }
275  }
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.

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

279  {
281  }
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 289 of file O3prmReader_tpl.h.

289  {
290  return errors__.warning_count;
291  }

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

◆ errors__

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

Definition at line 151 of file O3prmReader.h.

◆ imported__

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

Definition at line 148 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 146 of file O3prmReader.h.

◆ prm__

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

Definition at line 145 of file O3prmReader.h.


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