26#ifndef error_error_hpp
27#define error_error_hpp
29#include <source_location>
148 static constexpr int level = 0;
161 static constexpr int level = 1;
174 static constexpr int level = 2;
194 static constexpr int level = 3;
197#ifndef MXLIB_DEFAULT_VERBOSITY
198 #define MXLIB_DEFAULT_VERBOSITY vv
202typedef MXLIB_DEFAULT_VERBOSITY
d;
231template <
class verboseT=verbose::d>
233 const std::string &expl,
235 const std::source_location &loc
236 = std::source_location::current() );
282template <
class verboseT=verbose::d>
284 const std::source_location &loc
285 = std::source_location::current() );
330template <
class verboseT=verbose::d>
332 const std::string &expl,
334 const std::source_location &loc
335 = std::source_location::current() )
342 if constexpr( verboseT::level > 0 )
344 std::cerr << mxlib_error_message<verboseT>( code, expl, loc ) <<
'\n';
368template <
class verboseT=verbose::d>
370 const std::source_location &loc
371 = std::source_location::current() )
378 if constexpr( verboseT::level > 0 )
380 std::cerr << mxlib_error_message<verboseT>( code, loc ) <<
'\n';
405#define mxlib_error_check( fxn ) \
407 mx::error_t __mxlib_error_check_errc = fxn; \
408 if( __mxlib_error_check_errc != mx::error_t::noerror ) \
410 return internal::mxlib_error_report<verboseT>( __mxlib_error_check_errc ); \
424#define mxlib_error_return( fxn ) \
426 mx::error_t __mxlib_error_return_errc = fxn; \
427 if( __mxlib_error_return_errc != mx::error_t::noerror ) \
429 return internal::mxlib_error_report<verboseT>( __mxlib_error_return_errc ); \
431 return mx::error_t::noerror; \
445template <
class verboseT = verbose::d>
447 const std::string &expl,
449 const std::source_location &loc
450 = std::source_location::current() );
493template <
class verboseT = verbose::vvv>
495 const std::source_location &loc
496 = std::source_location::current() );
539template <
class verboseT = verbose::vvv>
541 const std::string &expl,
543 const std::source_location &loc
544 = std::source_location::current() )
551 if constexpr( verboseT::level > 0 )
553 std::cerr << error_message<verboseT>( code, expl, loc ) <<
'\n';
575template <
class verboseT = verbose::vvv>
577 const std::source_location &loc
578 = std::source_location::current() )
585 if constexpr( verboseT::level > 0 )
587 std::cerr << error_message<verboseT>( code, loc ) <<
'\n';
613#define mx_error_check( fxn ) \
615 mx::error_t __mxlib_error_check_errc = fxn; \
616 if( __mxlib_error_check_errc != mx::error_t::noerror ) \
618 return error_report<verboseT>( __mxlib_error_check_errc ); \
632#define mx_error_check_code( errc ) \
633 if( errc != mx::error_t::noerror ) \
635 return error_report<verboseT>( errc ); \
652#define mx_error_check_rv( fxn, rv ) \
654 mx::error_t __mxlib_error_check_errc = fxn; \
655 if( __mxlib_error_check_errc != mx::error_t::noerror ) \
657 error_report<verboseT>( __mxlib_error_check_errc ); \
673#define mx_error_check_code_rv( errc, rv ) \
674 if( errc != mx::error_t::noerror ) \
676 error_report<verboseT>( errc ); \
692#define mx_error_return( fxn ) \
694 mx::error_t __mx_error_return_errc = fxn; \
695 if( __mx_error_return_errc != mx::error_t::noerror ) \
697 return error_report<verboseT>( __mx_error_return_errc ); \
699 return mx::error_t::noerror; \
712#define mx_error_return_code( errc ) \
713 if( errc != mx::error_t::noerror ) \
715 return error_report<verboseT>( errc ); \
717 return mx::error_t::noerror;
The mxlib error_t type and utilities.
error_t
The mxlib error codes.
@ noerror
No error has occurred.
bool operator!(const error_t &errc)
Check if an error_t code is an error.
std::string error_message< mx::verbose::vvv >(const error_t &code, const std::string &expl, const std::source_location &loc)
Specialization of error_message for verbose::vvv.
bool operator==(const error_t &errc, bool tf)
Check if an error_t code is an error.
std::string error_message< mx::verbose::v >(const error_t &code, const std::string &expl, const std::source_location &loc)
Specialization of error_message for verbose::v.
std::string error_message< mx::verbose::o >(const error_t &code, const std::string &expl, const std::source_location &loc)
Specialization of error_message for verbose::o.
error_t error_report(const error_t &code, const std::string &expl, const std::source_location &loc=std::source_location::current())
Print a report to stderr given an mxlib error_t code and explanation and return the code.
error_t error_report< mx::verbose::o >(const error_t &code, const std::string &expl, const std::source_location &loc)
Specialization of error_report for verbose::o.
std::string error_message(const error_t &code, const std::string &expl, const std::source_location &loc=std::source_location::current())
Format a report given an mxlib error_t code and explanation.
bool isError(const error_t &errc)
Check if an error_t code is an error.
bool operator!=(const error_t &errc, bool tf)
Check if an error_t code is not an error.
std::string error_message< mx::verbose::vv >(const error_t &code, const std::string &expl, const std::source_location &loc)
Specialization of error_message for verbose::vv.
error_t mxlib_error_report(const error_t &code, const std::string &expl, const std::source_location &loc=std::source_location::current())
Print a report to stderr given an mxlib error_t code and explanation and return the code.
error_t mxlib_error_report< mx::verbose::o >(const error_t &code, const std::string &expl, const std::source_location &loc)
Specialization of mxlib_error_report for verbose::o.
std::string mxlib_error_message< mx::verbose::vv >(const error_t &code, const std::string &expl, const std::source_location &loc)
Specialization of mxlib_error_message for verbose::vv.
std::string mxlib_error_message< mx::verbose::v >(const error_t &code, const std::string &expl, const std::source_location &loc)
Specialization of mxlib_error_message for verbose::v.
std::string mxlib_error_message< mx::verbose::o >(const error_t &code, const std::string &expl, const std::source_location &loc)
Specialization of mxlib_error_message for verbose::o.
std::string mxlib_error_message< mx::verbose::vvv >(const error_t &code, const std::string &expl, const std::source_location &loc)
Specialization of mxlib_error_message for verbose::vvv.
std::string mxlib_error_message(const error_t &code, const std::string &expl, const std::source_location &loc=std::source_location::current())
Format a report given an mxlib error_t code and explanation.
MXLIB_DEFAULT_VERBOSITY d
The default verbosity.
Verbosity level 0, no reports are generated or printed to stderr.
Verbosity level 1. Minimal reports with no source location information.
Verbosity level 2. Additional information is provided, including source file and line.
Verbosity level 3. A full report is provided.