52#if __has_include("defs.h")
58#if (defined(_MSVC_LANG) && _MSVC_LANG < 201703L) \
59 || (!defined(_MSVC_LANG) && (__cplusplus < 201703L))
60#error "errorcode requires c++17"
88 ~erc () noexcept (false);
89 erc& operator= (const
erc& rhs);
90 erc& operator= (
erc&& rhs);
91 operator
int () const;
102 bool operator== (const
erc& other) const;
103 bool operator!= (const
erc& other) const;
114 void message (const std::
string& m);
122 mutable
int active : 1;
124 const errfac& facility_;
154 virtual std::string
message (
const erc& e)
const;
157 const std::string&
name ()
const;
165 virtual void raise (
const erc& e)
const;
166 virtual void log (
const erc& e)
const;
172 static errfac* default_facility;
175#if (defined(_MSVC_LANG) && _MSVC_LANG >= 202002L) \
176 || (!defined(_MSVC_LANG) && (__cplusplus >= 202002L))
178concept checkable = !std::is_convertible_v<T, int>;
196template <checkable T>
197class checked :
public erc
208 checked (
const T& obj_,
const erc& err)
214 checked (
const T& obj_,
int value = 0, erc::level pri_ = erc::level::error)
219 checked (T&& obj_, erc&& err)
220 : erc (std::move (err))
221 , obj (std::move (obj_))
224 checked (T&& obj_,
const erc& err)
226 , obj (std::move (obj_))
230 checked (
const checked<T>& other)
236 checked (checked<T>&& other)
241 ~checked () noexcept (false) = default;
244 checked<T>& operator= (const checked<T>& rhs)
248 erc::operator= (rhs);
255 checked<T>& operator= (checked<T>&& rhs)
259 *(erc*)
this = std::move (rhs);
260 obj = std::move (rhs.obj);
266 checked<T>& operator= (
const erc& rhs)
268 erc::operator= (rhs);
276 if (code () && priority ())
286 if (code () && priority ())
296 if (code () && priority ())
303 const T* operator->()
const
305 if (code () && priority ())
375 return std::string (
"error ") + std::to_string (e.value);
380 return *default_facility;
389 default_facility = facility ? facility : &
deffac;
402 if (e.priority_ >= log_level)
404 if (e.priority_ >= throw_level)
416 fprintf (stderr,
"%s - %s\n",
name ().c_str (), e.
message ().c_str ());
436 , facility_{errfac::Default ()}
442 , priority_{(unsigned short)l}
443 , facility_{errfac::Default ()}
450 , priority_{(unsigned short)l}
469 , priority_{other.priority_}
470 , active{other.active}
471 , facility_{other.facility_}
481 , priority_{other.priority_}
482 , active{other.active}
483 , facility_{other.facility_}
511 int rhs_active = rhs.active;
513 if (active && priority_)
514 facility_.raise (*
this);
516 priority_ = rhs.priority_;
517 const_cast<errfac&
> (facility_) = rhs.facility_;
535 bool rhs_active = rhs.active;
537 if (active && value && priority_)
538 facility_.raise (*
this);
540 priority_ = rhs.priority_;
541 const_cast<errfac&
>(facility_) = rhs.facility_;
574 const_cast<erc&
> (other).active =
false;
575 if ((!priority_ || !value) && (!other.priority_ || !other.value))
577 if (&facility_ == &other.facility_ && priority_ == other.priority_ && value == other.value)
600 if (value && active && priority_)
601 facility_.raise (*
this);
623 return msg.empty () ? facility_.message (*
this) : msg;
637inline erc::operator int ()
const
objects returned as a function result or thrown directly.
Definition errorcode.h:68
void reactivate() const
Similar to re-throwing an exception.
Definition errorcode.h:644
bool operator!=(const erc &other) const
Inequality comparison operator.
Definition errorcode.h:591
int code() const
Return numerical value.
Definition errorcode.h:610
std::string message() const
Get logging message.
Definition errorcode.h:621
bool operator==(const erc &other) const
Equality comparison operator.
Definition errorcode.h:571
level priority() const
Return priority value.
Definition errorcode.h:548
~erc() noexcept(false)
Destructor. Call raise() function to see if the error should get logged or thrown.
Definition errorcode.h:491
void deactivate() const
Marks error code as inactive.
Definition errorcode.h:654
static erc success
The SUCCESS indicator.
Definition errorcode.h:116
void raise() const
Definition errorcode.h:598
erc()
Default ctor for erc objects creates an inactive error.
Definition errorcode.h:432
bool is_active() const
Return activity flag.
Definition errorcode.h:553
const errfac & facility() const
Return reference to facility.
Definition errorcode.h:558
erc & operator=(const erc &rhs)
Principal assignment operator.
Definition errorcode.h:507
level
Error levels (borrowed from BSD Unix)
Definition errorcode.h:72
@ emerg
always logged, thrown
Definition errorcode.h:80
@ none
always not logged, not thrown
Definition errorcode.h:73
@ notice
default not logged, not thrown
Definition errorcode.h:75
@ info
default not logged, not thrown
Definition errorcode.h:74
@ error
default logged, thrown
Definition errorcode.h:77
@ alert
default logged, thrown
Definition errorcode.h:79
@ critical
default logged, thrown
Definition errorcode.h:78
@ warning
default logged, not thrown
Definition errorcode.h:76
An error facility routes a group of errors handled in a similar manner.
Definition errorcode.h:136
virtual void raise(const erc &e) const
Check if error must be logged or thrown.
Definition errorcode.h:400
const std::string & name() const
get name
Definition errorcode.h:367
erc::level log_priority() const
get log priority
Definition errorcode.h:362
virtual void log(const erc &e) const
Definition errorcode.h:414
erc::level throw_priority() const
get throw priority
Definition errorcode.h:352
void log_priority(erc::level pri)
set log priority
Definition errorcode.h:357
static void Default(errfac *f)
set default facility
Definition errorcode.h:387
errfac(const std::string &name="Error")
Set defaults for log and throw levels.
Definition errorcode.h:341
static errfac & Default()
get default facility
Definition errorcode.h:378
void throw_priority(erc::level pri)
set throw priority
Definition errorcode.h:347
virtual std::string message(const erc &e) const
return message to be logged
Definition errorcode.h:373
errfac deffac
The default facility.
Definition errorcode.h:322
timeval operator*(const timeval &op1, int op2)
Multiplication by an integer.
Definition tvops.h:178