aGrUM  0.13.2
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 67 of file O3prmReader.h.

Constructor & Destructor Documentation

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

Definition at line 139 of file O3prmReader_tpl.h.

139  :
140  __prm(new PRM< GUM_SCALAR >()),
141  __o3_prm(std::unique_ptr< O3PRM >(new O3PRM())) {
142  GUM_CONSTRUCTOR(O3prmReader);
143  }
std::unique_ptr< O3PRM > __o3_prm
Definition: O3prmReader.h:145
PRM< GUM_SCALAR > * __prm
Definition: O3prmReader.h:144
template<typename GUM_SCALAR>
INLINE gum::prm::o3prm::O3prmReader< GUM_SCALAR >::O3prmReader ( PRM< GUM_SCALAR > &  prm)
explicit

Definition at line 146 of file O3prmReader_tpl.h.

146  :
147  __prm(&prm), __o3_prm(std::unique_ptr< O3PRM >(new O3PRM())) {
148  GUM_CONSTRUCTOR(O3prmReader);
149  }
gum::prm::PRM< GUM_SCALAR > * prm()
Definition: O3prmReader.h:108
std::unique_ptr< O3PRM > __o3_prm
Definition: O3prmReader.h:145
PRM< GUM_SCALAR > * __prm
Definition: O3prmReader.h:144
template<typename GUM_SCALAR>
INLINE gum::prm::o3prm::O3prmReader< GUM_SCALAR >::O3prmReader ( const O3prmReader< GUM_SCALAR > &  src)

Definition at line 152 of file O3prmReader_tpl.h.

152  :
153  __prm(src.__prm),
154  __o3_prm(std::unique_ptr< O3PRM >(new O3PRM(*(src.__o3_prm)))),
155  __class_path(src.__class_path), __imported(src.__imported),
156  __errors(src.__errors) {
157  GUM_CONS_CPY(O3prmReader);
158  }
std::vector< std::string > __class_path
Definition: O3prmReader.h:146
std::unique_ptr< O3PRM > __o3_prm
Definition: O3prmReader.h:145
Set< std::string > __imported
Definition: O3prmReader.h:147
PRM< GUM_SCALAR > * __prm
Definition: O3prmReader.h:144
template<typename GUM_SCALAR>
INLINE gum::prm::o3prm::O3prmReader< GUM_SCALAR >::O3prmReader ( O3prmReader< GUM_SCALAR > &&  src)

Definition at line 161 of file O3prmReader_tpl.h.

161  :
162  __prm(std::move(src.__prm)), __o3_prm(std::move(src.__o3_prm)),
163  __class_path(std::move(src.__class_path)),
164  __imported(std::move(src.__imported)),
165  __errors(std::move(src.__errors)) {
166  GUM_CONS_CPY(O3prmReader);
167  }
std::vector< std::string > __class_path
Definition: O3prmReader.h:146
std::unique_ptr< O3PRM > __o3_prm
Definition: O3prmReader.h:145
Set< std::string > __imported
Definition: O3prmReader.h:147
PRM< GUM_SCALAR > * __prm
Definition: O3prmReader.h:144
template<typename GUM_SCALAR >
INLINE gum::prm::o3prm::O3prmReader< GUM_SCALAR >::~O3prmReader ( )

Definition at line 170 of file O3prmReader_tpl.h.

References gum::prm::o3prm::O3prmReader< GUM_SCALAR >::operator=().

170  {
171  GUM_DESTRUCTOR(O3prmReader);
172  }

+ Here is the call graph for this function:

Member Function Documentation

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.

References gum::replace().

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...

+ Here is the call graph for this function:

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

Definition at line 411 of file O3prmReader_tpl.h.

References gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__imported, gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__o3_prm, and gum::Set< Key, Alloc >::exists().

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

411  {
412  auto copy = std::vector< const O3Import* >();
413  for (const auto& i : __o3_prm->imports()) {
414  if (!__imported.exists(i->import().label())) { copy.push_back(i.get()); }
415  }
416  return copy;
417  }
std::unique_ptr< O3PRM > __o3_prm
Definition: O3prmReader.h:145
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:147

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

References gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__class_path, gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__errors, gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__imported, gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__parseStream(), gum::ErrorsContainer::addError(), gum::Set< Key, Alloc >::exists(), gum::prm::o3prm::O3Import::import(), gum::Set< Key, Alloc >::insert(), gum::prm::o3prm::O3Label::label(), gum::prm::o3prm::O3Label::position(), and gum::replace().

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

369  {
370  if (!__imported.exists(i.import().label())) {
371  __imported.insert(i.import().label());
372 
373  auto module_path = module;
374  std::replace(module_path.begin(), module_path.end(), '.', '/');
375 
376  auto path = i.import().label();
377  std::replace(path.begin(), path.end(), '.', '/');
378 
379  auto imported = false;
380  for (const auto& cp : __class_path) {
381  auto file_path = cp + path + ".o3prm";
382  std::ifstream file(file_path);
383 
384  if (file.is_open()) {
385  __parseStream(file, file_path, i.import().label());
386  imported = true;
387  break;
388  }
389 
390  file_path = cp + module + path + ".o3prm";
391  std::ifstream file2(file_path);
392 
393  if (file2.is_open()) {
394  __parseStream(file2, file_path, module + "." + i.import().label());
395  imported = true;
396  break;
397  }
398  }
399 
400  if (!imported) {
401  const auto& pos = i.import().position();
402  std::stringstream msg;
403  msg << "Import error: could not resolve import " << i.import().label();
404  __errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
405  }
406  }
407  }
std::vector< std::string > __class_path
Definition: O3prmReader.h:146
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:147
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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

References gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__errors, gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__o3_prm, gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__readStream(), and gum::ErrorsContainer::errors.

Referenced by gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__parseImport(), and gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__readStream().

353  {
354  auto sBuff = __readStream(input);
355  auto buffer = std::unique_ptr< unsigned char[] >(
356  new unsigned char[sBuff.length() + 1]);
357  strcpy((char*)buffer.get(), sBuff.c_str());
358  auto s = o3prm_scanner(buffer.get(), int(sBuff.length() + 1), filename);
359  auto p = o3prm_parser(&s);
360  p.set_prm(__o3_prm.get());
361  p.set_prefix(module);
362  p.Parse();
363  __errors += p.errors();
364  }
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:145
gum::prm::o3prm::Scanner o3prm_scanner

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 109 of file O3prmReader_tpl.h.

References gum::ParseError::column, gum::ParseError::filename, gum::ParseError::line, and gum::ParseError::msg.

Referenced by gum::prm::o3prm::O3prmReader< GUM_SCALAR >::showElegantErrors(), and gum::prm::o3prm::O3prmReader< GUM_SCALAR >::showElegantErrorsAndWarnings().

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

+ Here is the caller graph for this function:

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

References gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__copyImports(), gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__errors, gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__o3_prm, gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__parseImport(), gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__parseStream(), gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__prm, gum::ErrorsContainer::addException(), gum::ErrorsContainer::count(), and gum::ErrorsContainer::error_count.

Referenced by gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__parseStream(), gum::prm::o3prm::O3prmReader< GUM_SCALAR >::parseStream(), gum::prm::o3prm::O3prmReader< GUM_SCALAR >::readFile(), and gum::prm::o3prm::O3prmReader< GUM_SCALAR >::readString().

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 118 of file O3prmReader_tpl.h.

References GUM_ERROR.

118  {
119  if (inputstr) {
120  inputstr.seekg(0, inputstr.end);
121  int length = int(inputstr.tellg());
122  inputstr.seekg(0, inputstr.beg);
123 
124  auto str = std::string();
125  str.resize(length, ' ');
126  auto begin = &*str.begin();
127 
128  inputstr.read(begin, length);
129 
130  return str;
131  }
132  GUM_ERROR(OperationNotAllowed, "Could not open file");
133  }
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66
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 221 of file O3prmReader_tpl.h.

References gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__class_path, gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__errors, and gum::ErrorsContainer::addException().

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

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

References gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__errors, gum::ParseError::column, and gum::ErrorsContainer::error().

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

239  {
240  return __errors.error(i).column;
241  }
ParseError error(Idx i) const
Returns the i-th error.
Idx column
The column of this gum::ParseError, default is 0.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

References gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__errors, gum::ErrorsContainer::error(), gum::ParseError::filename, and widen().

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

244  {
245  return widen(__errors.error(i).filename);
246  }
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 call graph for this function:

+ Here is the caller graph for this function:

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

References gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__errors, gum::ErrorsContainer::error(), and gum::ParseError::is_error.

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

249  {
250  return __errors.error(i).is_error;
251  }
bool is_error
If false, this gum::ParseError is a warning.
ParseError error(Idx i) const
Returns the i-th error.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

References gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__errors, gum::ErrorsContainer::error(), and gum::ParseError::line.

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

234  {
235  return __errors.error(i).line;
236  }
Idx line
The line of this gum::ParseError.
ParseError error(Idx i) const
Returns the i-th error.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

References gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__errors, gum::ErrorsContainer::error(), and gum::ParseError::msg.

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

254  {
255  return __errors.error(i).msg;
256  }
std::string msg
The gum::ParseError message.
ParseError error(Idx i) const
Returns the i-th error.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

publishing Errors API

of errors

Definition at line 283 of file O3prmReader_tpl.h.

References gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__errors, and gum::ErrorsContainer::error_count.

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

283  {
284  return __errors.error_count;
285  }
Size error_count
Number of errors detected.

+ Here is the caller graph for this function:

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

publishing Errors API

of errors

Definition at line 294 of file O3prmReader_tpl.h.

References gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__errors.

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

294  {
295  return __errors;
296  }

+ Here is the caller graph for this function:

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

Definition at line 176 of file O3prmReader_tpl.h.

References gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__class_path, gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__errors, gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__imported, gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__o3_prm, and gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__prm.

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

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

+ Here is the caller graph for this function:

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

Definition at line 188 of file O3prmReader_tpl.h.

References gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__class_path, gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__errors, gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__imported, gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__o3_prm, and gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__prm.

188  {
189  if (this == &src) { return *this; }
190  __prm = std::move(src.__prm);
191  __o3_prm = std::move(src.__o3_prm);
192  __class_path = std::move(src.__class_path);
193  __imported = std::move(src.__imported);
194  __errors = std::move(src.__errors);
195  return *this;
196  }
std::vector< std::string > __class_path
Definition: O3prmReader.h:146
std::unique_ptr< O3PRM > __o3_prm
Definition: O3prmReader.h:145
Set< std::string > __imported
Definition: O3prmReader.h:147
PRM< GUM_SCALAR > * __prm
Definition: O3prmReader.h:144
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 341 of file O3prmReader_tpl.h.

References gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__readStream(), and gum::prm::o3prm::O3prmReader< GUM_SCALAR >::showElegantErrorsAndWarnings().

343  {
344  __readStream(input, "", module);
345 
347  }
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

+ Here is the call graph for this function:

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

Definition at line 108 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().

108 { return __prm; }
PRM< GUM_SCALAR > * __prm
Definition: O3prmReader.h:144

+ Here is the caller graph for this function:

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

Definition at line 109 of file O3prmReader.h.

109 { return __prm; }
PRM< GUM_SCALAR > * __prm
Definition: O3prmReader.h:144
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 306 of file O3prmReader_tpl.h.

References gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__errors, gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__readStream(), gum::ErrorsContainer::addException(), gum::ErrorsContainer::count(), gum::Exception::errorContent(), and GUM_SHOWERROR.

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

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

References gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__errors, gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__readStream(), and gum::ErrorsContainer::count().

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

+ Here is the call graph for this function:

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

References gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__class_path, and gum::prm::o3prm::O3prmReader< GUM_SCALAR >::addClassPath().

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

+ Here is the call graph for this function:

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

References gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__errors, gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__print(), gum::ErrorsContainer::count(), and gum::ErrorsContainer::error().

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

260  {
261  for (Idx i = 0; i < __errors.count(); ++i) {
262  auto err = __errors.error(i);
263  if (err.is_error) { o << __print(err) << std::endl; }
264  }
265  }
std::string __print(const ParseError &err) const
ParseError error(Idx i) const
Returns the i-th error.
Size count() const
Returns the number of errors and warnings.
unsigned long Idx
Type for indexes.
Definition: types.h:43

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

References gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__errors, gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__print(), gum::ErrorsContainer::count(), and gum::ErrorsContainer::error().

Referenced by gum::prm::o3prm::O3prmReader< GUM_SCALAR >::parseStream(), and gum::prm::o3prm::O3prmReader< double >::prm().

269  {
270  for (Idx i = 0; i < __errors.count(); ++i) {
271  auto err = __errors.error(i);
272  o << __print(err) << std::endl;
273  }
274  }
std::string __print(const ParseError &err) const
ParseError error(Idx i) const
Returns the i-th error.
Size count() const
Returns the number of errors and warnings.
unsigned long Idx
Type for indexes.
Definition: types.h:43

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

References gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__errors, and gum::ErrorsContainer::syntheticResults().

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

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

of errors

Definition at line 288 of file O3prmReader_tpl.h.

References gum::prm::o3prm::O3prmReader< GUM_SCALAR >::__errors, and gum::ErrorsContainer::warning_count.

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

288  {
289  return __errors.warning_count;
290  }

+ Here is the caller graph for this function:

Member Data Documentation


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