MGIS
Loading...
Searching...
No Matches
mgis::Context Struct Referencefinal

a class used to pass an execution context to most methods of MGIS and gather information (error, logs, profiling). More...

#include </home/runner/work/MFrontGenericInterfaceSupport/MFrontGenericInterfaceSupport/include/MGIS/Context.hxx>

Inheritance diagram for mgis::Context:
mgis::ErrorBacktrace mgis::AbstractErrorHandler

Classes

struct  FailureHandler
 

Public Types

enum  FailureHandlerPolicy { ABORT , RAISE }
 
- Public Types inherited from mgis::ErrorBacktrace
using ErrorReportFunction = std::string(*)(const int)
 brief a simple alias
 
using ErrorReport = std::variant< const char *, std::pair< int, ErrorReportFunction >, std::string >
 a simple alias listing the main way to report an error.
 

Public Member Functions

 Context () noexcept
 default constructor
 
 Context (const ContextInitializer &) noexcept
 constructor for an initializer
 
 Context (Context &&)=delete
 
 Context (const Context &)=delete
 
Contextoperator= (Context &&)=delete
 
Contextoperator= (const Context &)=delete
 
const VerbosityLevelgetVerbosityLevel () const noexcept
 
void setVerbosityLevel (const VerbosityLevel) noexcept
 change the level of verbosity
 
void enableProfiling (const bool) noexcept
 enable or disable profiling
 
bool isProfilingEnabled () const noexcept
 
ProfilingSection startNewProfiling (std::string, bool) noexcept
 start a new profiling section
 
void pushProfilingNode (std::string) noexcept
 push a new profiling node into the current execution stack
 
void popProfilingNode (double) noexcept
 pop the current profiling node from the execution stack and accumulate time
 
const ProfilingDatagetProfilingResultTree () const noexcept
 
template<FailureHandlerPolicy policy = FailureHandlerPolicy::RAISE>
FailureHandler< policy > getFailureHandler ()
 
FailureHandler< FailureHandlerPolicy::RAISE > getThrowingFailureHandler () noexcept
 
FailureHandler< FailureHandlerPolicy::ABORT > getFatalFailureHandler () noexcept
 
void setLogStream (std::ostream &) noexcept
 set the current log stream.
 
void setLogStream (std::shared_ptr< std::ostream >) noexcept
 set the current log stream.
 
std::shared_ptr< std::ostream > getLogStreamPointer () const noexcept
 
void resetLogStream () noexcept
 reset the default log stream
 
void disableLogStream () noexcept
 disable the default log stream
 
std::ostream & log () noexcept
 
template<typename... Args>
std::ostream & log (const VerbosityLevel, Args &&...) noexcept
 display the given arguments in the log stream if the current verbosity level (as returned by the getVerbosityLevel method) is greater than a minimal one.
 
template<typename... Args>
void warning (Args &&...) noexcept
 a simple wrapper around the log method to print a warning
 
template<typename... Args>
void debug (Args &&...) noexcept
 a simple wrapper around the log method which sets the minimun verbosity level to verboseDebug
 
 ~Context () noexcept override
 destructor
 
template<typename... Args>
std::ostream & log (const VerbosityLevel l, Args &&...args) noexcept
 
template<typename... Args>
void warning (Args &&...args) noexcept
 
template<typename... Args>
void debug (Args &&...args) noexcept
 
- Public Member Functions inherited from mgis::ErrorBacktrace
InvalidResult registerErrorMessage (const char *const) final
 register a new error message
 
InvalidResult registerErrorMessage (const ErrorReport) noexcept
 register a new error message
 
InvalidResult registerErrorMessageWithoutSourceLocation (const ErrorReport) noexcept
 register a new error message
 
void clearErrorMessages () noexcept
 remove the error messages
 
std::string getErrorMessage (const bool=true) noexcept
 
std::string getRawErrorMessage (const bool=true) noexcept
 
bool empty () const noexcept
 
 ~ErrorBacktrace () noexcept override
 destructor
 
- Public Member Functions inherited from mgis::AbstractErrorHandler
virtual constexpr ~AbstractErrorHandler ()=default
 destructor
 

Additional Inherited Members

- Static Public Member Functions inherited from mgis::ErrorBacktrace
static void setErrorReportingAsFatal () noexcept
 specify if error reporting shall be fatal
 
static void unsetErrorReportingAsFatal () noexcept
 specify if error reporting shall be fatal
 

Detailed Description

a class used to pass an execution context to most methods of MGIS and gather information (error, logs, profiling).

The default logging stream is the one returned by the mgis::getDefaultLogStream free function.

Constructor & Destructor Documentation

◆ Context() [1/2]

mgis::Context::Context ( )
noexcept

default constructor

The verbositiy level is initialized by calling the getDefaultVerbosityLevel function.

◆ Context() [2/2]

mgis::Context::Context ( const ContextInitializer )
noexcept

constructor for an initializer

Parameters
[in]iinitializer

Member Function Documentation

◆ debug()

template<typename... Args>
void mgis::Context::debug ( Args &&  ...)
noexcept

a simple wrapper around the log method which sets the minimun verbosity level to verboseDebug

Template Parameters
Argstypes of the arguments
Parameters
[in]argsstreamed object
Note
note nothing is displayed if the current verbositiy level is below verboseDebug

◆ disableLogStream()

void mgis::Context::disableLogStream ( )
noexcept

disable the default log stream

Note
logging is disable by creating a no-op output stream

◆ enableProfiling()

void mgis::Context::enableProfiling ( const bool  )
noexcept

enable or disable profiling

Parameters
[in]ba boolean value stating whether profiling shall be enabled
Note
when profiling is disabled, profiling sections introduce almost no overhead.

◆ getFailureHandler()

template<FailureHandlerPolicy policy = FailureHandlerPolicy::RAISE>
FailureHandler< policy > mgis::Context::getFailureHandler ( )
inline
Returns
a failure handler
Template Parameters
policypolicy used to treat a failure
Note
the context must outlive the failure hander

◆ getFatalFailureHandler()

Context::FailureHandler< Context::FailureHandlerPolicy::ABORT > mgis::Context::getFatalFailureHandler ( )
inlinenoexcept
Returns
a failure handler aborting the execution in case of failure

◆ getLogStreamPointer()

std::shared_ptr< std::ostream > mgis::Context::getLogStreamPointer ( ) const
noexcept
Returns
a pointer to a log stream. This pointer may be null.

◆ getProfilingResultTree()

const ProfilingData & mgis::Context::getProfilingResultTree ( ) const
noexcept
Returns
the root node of the profiling results tree gathered during execution

◆ getThrowingFailureHandler()

Context::FailureHandler< Context::FailureHandlerPolicy::RAISE > mgis::Context::getThrowingFailureHandler ( )
inlinenoexcept
Returns
a failure handler throwing exception in case of failure

◆ getVerbosityLevel()

const VerbosityLevel & mgis::Context::getVerbosityLevel ( ) const
noexcept
Returns
the verbosity level

◆ isProfilingEnabled()

bool mgis::Context::isProfilingEnabled ( ) const
noexcept
Returns
true if profiling is enabled, false otherwise

◆ log() [1/2]

std::ostream & mgis::Context::log ( )
noexcept
Returns
the current log stream
Note
if no log stream is set, the default one is returned. See getDefaultLogStream for details.

◆ log() [2/2]

template<typename... Args>
std::ostream & mgis::Context::log ( const VerbosityLevel  ,
Args &&  ... 
)
noexcept

display the given arguments in the log stream if the current verbosity level (as returned by the getVerbosityLevel method) is greater than a minimal one.

Template Parameters
Argstypes of the arguments
Returns
the current log stream
Parameters
[in]lminimal verbosity level
[in]argsstreamed object
Note
note nothing is displayed if the current verbositiy level is below the first argument

◆ popProfilingNode()

void mgis::Context::popProfilingNode ( double  )
noexcept

pop the current profiling node from the execution stack and accumulate time

Parameters
[in]dtexecution time of the section in seconds
Note
this method is meant to be called internally by the Profiling class during its destruction.

◆ pushProfilingNode()

void mgis::Context::pushProfilingNode ( std::string  )
noexcept

push a new profiling node into the current execution stack

Parameters
[in]namename of the profiling section
Note
this method is meant to be called internally by the Profiling class during its construction.

◆ setLogStream() [1/2]

void mgis::Context::setLogStream ( std::ostream &  )
noexcept

set the current log stream.

Parameters
[in]slog stream
Note
the user is responsible for ensuring that the given object is alive

◆ setLogStream() [2/2]

void mgis::Context::setLogStream ( std::shared_ptr< std::ostream >  )
noexcept

set the current log stream.

Parameters
[in]slog stream
Note
if an empty shared pointer is given, the log stream is reset to the default one, i.e. the one returned by the mgis::getDefaultLogStream free function.

◆ setVerbosityLevel()

void mgis::Context::setVerbosityLevel ( const VerbosityLevel  )
noexcept

change the level of verbosity

Parameters
[in]lthe new verbose level

◆ startNewProfiling()

ProfilingSection mgis::Context::startNewProfiling ( std::string  ,
bool   
)
noexcept

start a new profiling section

Parameters
[in]namename of the profiling section
[in]enabledboolean stating whether this profiling section shall effectively collect timing information
Returns
a profiling section object
Note
the returned object relies on RAII semantics: timing starts during construction and stops during destruction.

◆ warning()

template<typename... Args>
void mgis::Context::warning ( Args &&  ...)
noexcept

a simple wrapper around the log method to print a warning

Template Parameters
Argstypes of the arguments
Parameters
[in]argsstreamed object

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