HelenOS sources
This source file includes following definitions.
- default_error_condition
- equivalent
- equivalent
- name
- message
- name
- message
- generic_category
- system_category
- assign
- clear
- value
- default_error_condition
- message
- make_error_code
- assign
- clear
- value
- message
- make_error_condition
#include <cstring>
#include <functional>
#include <string>
#include <system_error>
namespace std
{
error_category::~error_category()
{ }
error_condition error_category::default_error_condition(int code) const noexcept
{
return error_condition{code, *this};
}
bool error_category::equivalent(int code, const error_condition& cond) const noexcept
{
return default_error_condition(code) == cond;
}
bool error_category::equivalent(const error_code& ec, int cond) const noexcept
{
return *this == ec.category() && ec.value() == cond;
}
bool error_category::operator==(const error_category& rhs) const noexcept
{
return this == &rhs;
}
bool error_category::operator!=(const error_category& rhs) const noexcept
{
return !(*this == rhs);
}
bool error_category::operator<(const error_category& rhs) const noexcept
{
return less<const error_category*>{}(this, &rhs);
}
namespace aux
{
class generic_category_t: public error_category
{
public:
generic_category_t()
: error_category{}
{ }
~generic_category_t() = default;
const char* name() const noexcept override
{
return "generic";
}
string message(int ev) const override
{
return "ev: " + std::to_string(ev);
}
};
class system_category_t: public error_category
{
public:
system_category_t()
: error_category{}
{ }
~system_category_t() = default;
const char* name() const noexcept override
{
return "system";
}
string message(int ev) const override
{
return "ev: " + std::to_string(ev);
}
};
}
const error_category& generic_category() noexcept
{
static aux::generic_category_t instance{};
return instance;
}
const error_category& system_category() noexcept
{
static aux::system_category_t instance{};
return instance;
}
error_code::error_code() noexcept
: val_{}, cat_{&system_category()}
{ }
error_code::error_code(int val, const error_category& cat) noexcept
: val_{val}, cat_{&cat}
{ }
void error_code::assign(int val, const error_category& cat) noexcept
{
val_ = val;
cat_ = &cat;
}
void error_code::clear() noexcept
{
val_ = 0;
cat_ = &system_category();
}
int error_code::value() const noexcept
{
return val_;
}
const error_category& error_code::category() const noexcept
{
return *cat_;
}
error_condition error_code::default_error_condition() const noexcept
{
return cat_->default_error_condition(val_);
}
string error_code::message() const
{
return cat_->message(val_);
}
error_code make_error_code(errc e) noexcept
{
return error_code{static_cast<int>(e), generic_category()};
}
bool operator<(const error_code& lhs, const error_code& rhs) noexcept
{
return lhs.category() < rhs.category() ||
(lhs.category() == rhs.category() && lhs.value() < rhs.value());
}
error_condition::error_condition() noexcept
: val_{}, cat_{&generic_category()}
{ }
error_condition::error_condition(int val, const error_category& cat) noexcept
: val_{val}, cat_{&cat}
{ }
void error_condition::assign(int val, const error_category& cat) noexcept
{
val_ = val;
cat_ = &cat;
}
void error_condition::clear() noexcept
{
val_ = 0;
cat_ = &generic_category();
}
int error_condition::value() const noexcept
{
return val_;
}
const error_category& error_condition::category() const noexcept
{
return *cat_;
}
string error_condition::message() const
{
return cat_->message(val_);
}
error_condition make_error_condition(errc e) noexcept
{
return error_condition{static_cast<int>(e), generic_category()};
}
bool operator<(const error_condition& lhs, const error_condition& rhs) noexcept
{
return lhs.category() < rhs.category() ||
(lhs.category() == rhs.category() && lhs.value() < rhs.value());
}
bool operator==(const error_code& lhs, const error_code& rhs) noexcept
{
return lhs.category() == rhs.category() && lhs.value() == rhs.value();
}
bool operator==(const error_code& lhs, const error_condition& rhs) noexcept
{
return lhs.category().equivalent(lhs.value(), rhs)
|| rhs.category().equivalent(lhs, rhs.value());
}
bool operator==(const error_condition& lhs, const error_code& rhs) noexcept
{
return rhs.category().equivalent(rhs.value(), lhs)
|| lhs.category().equivalent(rhs, lhs.value());
}
bool operator==(const error_condition& lhs, const error_condition& rhs) noexcept
{
return lhs.category() == rhs.category() && lhs.value() == rhs.value();
}
bool operator!=(const error_code& lhs, const error_code& rhs) noexcept
{
return !(lhs == rhs);
}
bool operator!=(const error_code& lhs, const error_condition& rhs) noexcept
{
return !(lhs == rhs);
}
bool operator!=(const error_condition& lhs, const error_code& rhs) noexcept
{
return !(lhs == rhs);
}
bool operator!=(const error_condition& lhs, const error_condition& rhs) noexcept
{
return !(lhs == rhs);
}
system_error::system_error(error_code ec, const string& what_arg)
: runtime_error{what_arg.c_str()}, code_{ec}
{ }
system_error::system_error(error_code ec, const char* what_arg)
: runtime_error{what_arg}, code_{ec}
{ }
system_error::system_error(error_code ec)
: runtime_error{"system_error"}, code_{ec}
{ }
system_error::system_error(int code, const error_category& cat,
const string& what_arg)
: runtime_error{what_arg.c_str()}, code_{code, cat}
{ }
system_error::system_error(int code, const error_category& cat,
const char* what_arg)
: runtime_error{what_arg}, code_{code, cat}
{ }
system_error::system_error(int code, const error_category& cat)
: runtime_error{"system_error"}, code_{code, cat}
{ }
const error_code& system_error::code() const noexcept
{
return code_;
}
}
HelenOS homepage, sources at GitHub