aGrUM 3.0.0
a C++ library for (probabilistic) graphical models
gum::GumBNReader< GUM_SCALAR > Class Template Reference

#include <GumBNReader.h>

Inheritance diagram for gum::GumBNReader< GUM_SCALAR >:
Collaboration diagram for gum::GumBNReader< GUM_SCALAR >:

Public Member Functions

 GumBNReader (BayesNet< GUM_SCALAR > *bn, std::string_view filename, bool binary=false)
 Constructor A reader is defined for reading a defined file.
 GumBNReader (BayesNet< GUM_SCALAR > *bn)
 Constructor for string-based parsing only (no file). Use exclusively with proceedFromString(); calling proceed() will fail.
 ~GumBNReader () override
 Default destructor.
Size proceed () final
 Parse the file given at construction.
Size proceedFromString (std::string_view content)
 Parse a jgum JSON string directly (no file I/O).
void showElegantErrorsAndWarnings (std::ostream &stream=std::cerr) const
void showErrorCounts (std::ostream &stream=std::cerr) const
Accessors / Modifiers
void add (ParseError error)
 Add an error object to the container.
ParseError error (Idx i) const
 Returns the i-th error.
ParseError last () const
 Returns the last added error.
void addError (std::string_view msg, std::string_view filename, Idx line, Idx col)
 Adds an error.
void addWarning (std::string_view msg, std::string_view filename, Idx line, Idx col)
 Adds a warning.
void addException (std::string_view msg, std::string_view filename)
 Add an exception.
Size count () const
 Returns the number of errors and warnings.
void syntheticResults (std::ostream &o) const
 Print errors on output stream.
void simpleErrors (std::ostream &o) const
 Print errors on output stream.
void simpleErrorsAndWarnings (std::ostream &o) const
 Print errors on output stream.
void elegantErrors (std::ostream &o) const
 Print errors on output stream.
void elegantErrorsAndWarnings (std::ostream &o) const
 Print errors on output stream.
Coco/R helpers
void Error (const std::wstring &filename, Idx line, Idx col, const wchar_t *msg)
 For adding errors.
void Warning (const std::wstring &filename, Idx line, Idx col, const wchar_t *msg)
 For adding warnings.
void Exception (const std::wstring &filename, const wchar_t *msg)
 For adding exceptions.
Class operators
ErrorsContainer operator+ (const ErrorsContainer &cont) const
 Return the sum of two gum::ErrorsContainer.
ErrorsContainer operator+= (const ErrorsContainer &cont)
 Add the content of a gum::ErrorsContainer to this gum::ErrorsContainer.

Public Attributes

Size error_count
 Number of errors detected.
Size warning_count

Private Member Functions

template<typename JsonType>
Size _proceedFromJson_ (const JsonType &content)

Private Attributes

BayesNet< GUM_SCALAR > * _bn_
std::string _streamName_
bool _parseDone_
bool _binary_
 If true, the input is in binary format, otherwise in text format.
std::vector< ParseErrorerrors
 The list of gum::ParseError contained in this gum::ErrorsContainer.

Detailed Description

template<GUM_Numeric GUM_SCALAR>
class gum::GumBNReader< GUM_SCALAR >

Definition at line 57 of file GumBNReader.h.

Constructor & Destructor Documentation

◆ GumBNReader() [1/2]

template<GUM_Numeric GUM_SCALAR>
gum::GumBNReader< GUM_SCALAR >::GumBNReader ( BayesNet< GUM_SCALAR > * bn,
std::string_view filename,
bool binary = false )

Constructor A reader is defined for reading a defined file.

Hence the 2 args of the constructor. Note that the BN has to be built outside the reader. There is no delegation to create/destroy the BN from inside the reader.

Parameters
bnThe BayesNet to fill with the read data.
filenameThe name of the file to read.
binaryIf true, the input is in binary format, otherwise in text format

◆ GumBNReader() [2/2]

template<GUM_Numeric GUM_SCALAR>
gum::GumBNReader< GUM_SCALAR >::GumBNReader ( BayesNet< GUM_SCALAR > * bn)
explicit

Constructor for string-based parsing only (no file). Use exclusively with proceedFromString(); calling proceed() will fail.

◆ ~GumBNReader()

template<GUM_Numeric GUM_SCALAR>
gum::GumBNReader< GUM_SCALAR >::~GumBNReader ( )
override

Default destructor.

Member Function Documentation

◆ _proceedFromJson_()

template<GUM_Numeric GUM_SCALAR>
template<typename JsonType>
Size gum::GumBNReader< GUM_SCALAR >::_proceedFromJson_ ( const JsonType & content)
private

References _proceedFromJson_().

Referenced by _proceedFromJson_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ add()

INLINE void gum::ErrorsContainer::add ( ParseError error)
inherited

Add an error object to the container.

Parameters
errorThe gum::ParseError to add.

Definition at line 74 of file errorsContainer_inl.h.

74 {
75 errors.push_back(error);
76
77 if (error.is_error) error_count++;
78 else warning_count++;
79 }
ParseError error(Idx i) const
Returns the i-th error.
Size error_count
Number of errors detected.
std::vector< ParseError > errors
The list of gum::ParseError contained in this gum::ErrorsContainer.

References error(), error_count, errors, and warning_count.

Referenced by addError(), addException(), addWarning(), Error(), Exception(), and Warning().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addError()

INLINE void gum::ErrorsContainer::addError ( std::string_view msg,
std::string_view filename,
Idx line,
Idx col )
inherited

Adds an error.

Parameters
msgThe error's message.
filenameThe error's file.
lineThe error's line.
colThe error's column.

Definition at line 82 of file errorsContainer_inl.h.

85 {
86 add(ParseError(true, std::string(msg), std::string(filename), line, col));
87 }
void add(ParseError error)
Add an error object to the container.

References add().

Here is the call graph for this function:

◆ addException()

INLINE void gum::ErrorsContainer::addException ( std::string_view msg,
std::string_view filename )
inherited

Add an exception.

Parameters
msgThe exception's message.
filenameThe exception's file.

Definition at line 98 of file errorsContainer_inl.h.

98 {
99 add(ParseError(true, std::string(msg), std::string(filename), 0, 0));
100 }

References add().

Here is the call graph for this function:

◆ addWarning()

INLINE void gum::ErrorsContainer::addWarning ( std::string_view msg,
std::string_view filename,
Idx line,
Idx col )
inherited

Adds a warning.

Parameters
msgThe warning's message.
filenameThe warning's file.
lineThe warning's line.
colThe warning's column.

Definition at line 90 of file errorsContainer_inl.h.

93 {
94 add(ParseError(false, std::string(msg), std::string(filename), line, col));
95 }

References add().

Here is the call graph for this function:

◆ count()

INLINE Size gum::ErrorsContainer::count ( ) const
inherited

Returns the number of errors and warnings.

Returns
Returns the number of errors and warnings.

Definition at line 103 of file errorsContainer_inl.h.

103{ return error_count + warning_count; }

References error_count, and warning_count.

◆ elegantErrors()

void gum::ErrorsContainer::elegantErrors ( std::ostream & o) const
inherited

Print errors on output stream.

Parameters
oThe output strem to send results.

◆ elegantErrorsAndWarnings()

void gum::ErrorsContainer::elegantErrorsAndWarnings ( std::ostream & o) const
inherited

Print errors on output stream.

Parameters
oThe output strem to send results.

◆ Error()

INLINE void gum::ErrorsContainer::Error ( const std::wstring & filename,
Idx line,
Idx col,
const wchar_t * msg )
inherited

For adding errors.

Parameters
filenameThe error's file.
lineThe error's line.
colThe error's column.
msgThe error's message.

Definition at line 56 of file errorsContainer_inl.h.

56 {
57 add(ParseError(true, narrow(std::wstring(msg)), narrow(filename), line, col));
58 }
std::string narrow(const std::wstring &str)
Cast a std::wstring into a std::string.

References add(), and narrow().

Here is the call graph for this function:

◆ error()

ParseError gum::ErrorsContainer::error ( Idx i) const
inherited

Returns the i-th error.

Parameters
iThe error to return.
Returns
Returns the i-th error.
Exceptions
OutOfBoundsRaised if there is less than i errors.

Referenced by ErrorsContainer(), and add().

Here is the caller graph for this function:

◆ Exception()

INLINE void gum::ErrorsContainer::Exception ( const std::wstring & filename,
const wchar_t * msg )
inherited

For adding exceptions.

Parameters
filenameThe exception's file.
msgThe exception's message.

Definition at line 69 of file errorsContainer_inl.h.

69 {
70 add(ParseError(true, "Exception : " + narrow(std::wstring(msg)), narrow(filename), 0, 0));
71 }

References add(), and narrow().

Here is the call graph for this function:

◆ last()

ParseError gum::ErrorsContainer::last ( ) const
inherited

Returns the last added error.

Returns
Returns the last added error.
Exceptions
OutOfBoundsRaised if is no error to return.

◆ operator+()

ErrorsContainer gum::ErrorsContainer::operator+ ( const ErrorsContainer & cont) const
inherited

Return the sum of two gum::ErrorsContainer.

Parameters
contThe gum::ErrorsContainer to add.
Returns
Return the sum of two gum::ErrorsContainer.

References ErrorsContainer().

Here is the call graph for this function:

◆ operator+=()

ErrorsContainer gum::ErrorsContainer::operator+= ( const ErrorsContainer & cont)
inherited

Add the content of a gum::ErrorsContainer to this gum::ErrorsContainer.

Parameters
contThe gum::ErrorsContainer to add to this.
Returns
Returns this gum::ErrorsContainer.

References ErrorsContainer().

Here is the call graph for this function:

◆ proceed()

template<GUM_Numeric GUM_SCALAR>
Size gum::GumBNReader< GUM_SCALAR >::proceed ( )
final

Parse the file given at construction.

Returns
the number of detected errors

◆ proceedFromString()

template<GUM_Numeric GUM_SCALAR>
Size gum::GumBNReader< GUM_SCALAR >::proceedFromString ( std::string_view content)

Parse a jgum JSON string directly (no file I/O).

Returns
the number of detected errors

References proceedFromString().

Referenced by proceedFromString().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ showElegantErrorsAndWarnings()

template<GUM_Numeric GUM_SCALAR>
void gum::GumBNReader< GUM_SCALAR >::showElegantErrorsAndWarnings ( std::ostream & stream = std::cerr) const

References showElegantErrorsAndWarnings().

Referenced by showElegantErrorsAndWarnings().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ showErrorCounts()

template<GUM_Numeric GUM_SCALAR>
void gum::GumBNReader< GUM_SCALAR >::showErrorCounts ( std::ostream & stream = std::cerr) const

References showErrorCounts().

Referenced by showErrorCounts().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ simpleErrors()

void gum::ErrorsContainer::simpleErrors ( std::ostream & o) const
inherited

Print errors on output stream.

Parameters
oThe output strem to send results.

◆ simpleErrorsAndWarnings()

void gum::ErrorsContainer::simpleErrorsAndWarnings ( std::ostream & o) const
inherited

Print errors on output stream.

Parameters
oThe output strem to send results.

◆ syntheticResults()

INLINE void gum::ErrorsContainer::syntheticResults ( std::ostream & o) const
inherited

Print errors on output stream.

Parameters
oThe output strem to send results.

Definition at line 106 of file errorsContainer_inl.h.

106 {
107 o << "Errors : " << error_count << std::endl;
108 o << "Warnings : " << warning_count << std::endl;
109 }

References error_count, and warning_count.

◆ Warning()

INLINE void gum::ErrorsContainer::Warning ( const std::wstring & filename,
Idx line,
Idx col,
const wchar_t * msg )
inherited

For adding warnings.

Parameters
filenameThe warning's file.
lineThe warning's line.
colThe warning's column.
msgThe warning's message.

Definition at line 61 of file errorsContainer_inl.h.

64 {
65 add(ParseError(false, narrow(std::wstring(msg)), narrow(filename), line, col));
66 }

References add(), and narrow().

Here is the call graph for this function:

Member Data Documentation

◆ _binary_

template<GUM_Numeric GUM_SCALAR>
bool gum::GumBNReader< GUM_SCALAR >::_binary_
private

If true, the input is in binary format, otherwise in text format.

Definition at line 102 of file GumBNReader.h.

◆ _bn_

template<GUM_Numeric GUM_SCALAR>
BayesNet< GUM_SCALAR >* gum::GumBNReader< GUM_SCALAR >::_bn_
private

Definition at line 99 of file GumBNReader.h.

◆ _parseDone_

template<GUM_Numeric GUM_SCALAR>
bool gum::GumBNReader< GUM_SCALAR >::_parseDone_
private

Definition at line 101 of file GumBNReader.h.

◆ _streamName_

template<GUM_Numeric GUM_SCALAR>
std::string gum::GumBNReader< GUM_SCALAR >::_streamName_
private

Definition at line 100 of file GumBNReader.h.

◆ error_count

Size gum::ErrorsContainer::error_count
inherited

Number of errors detected.

Definition at line 186 of file errorsContainer.h.

Referenced by add(), count(), and syntheticResults().

◆ errors

std::vector< ParseError > gum::ErrorsContainer::errors
mutableprivateinherited

The list of gum::ParseError contained in this gum::ErrorsContainer.

Definition at line 182 of file errorsContainer.h.

Referenced by add().

◆ warning_count

Size gum::ErrorsContainer::warning_count
inherited

Definition at line 189 of file errorsContainer.h.

Referenced by add(), count(), and syntheticResults().


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