2010-05-12 03:42:16 +08:00
|
|
|
//===---------------------- system_error.cpp ------------------------------===//
|
|
|
|
//
|
2010-05-12 05:36:01 +08:00
|
|
|
// The LLVM Compiler Infrastructure
|
2010-05-12 03:42:16 +08:00
|
|
|
//
|
2010-11-17 06:09:02 +08:00
|
|
|
// This file is dual licensed under the MIT and the University of Illinois Open
|
|
|
|
// Source Licenses. See LICENSE.TXT for details.
|
2010-05-12 03:42:16 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-03-18 04:13:54 +08:00
|
|
|
#define _LIBCPP_BUILDING_SYSTEM_ERROR
|
2014-09-03 04:34:23 +08:00
|
|
|
#include "__config"
|
2010-05-12 03:42:16 +08:00
|
|
|
#include "system_error"
|
|
|
|
#include "string"
|
|
|
|
#include "cstring"
|
|
|
|
|
|
|
|
_LIBCPP_BEGIN_NAMESPACE_STD
|
|
|
|
|
|
|
|
// class error_category
|
|
|
|
|
2011-05-27 03:48:01 +08:00
|
|
|
error_category::error_category() _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-05-27 03:48:01 +08:00
|
|
|
error_category::~error_category() _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
error_condition
|
2011-05-27 03:48:01 +08:00
|
|
|
error_category::default_error_condition(int ev) const _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
return error_condition(ev, *this);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2011-05-27 03:48:01 +08:00
|
|
|
error_category::equivalent(int code, const error_condition& condition) const _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
return default_error_condition(code) == condition;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2011-05-27 03:48:01 +08:00
|
|
|
error_category::equivalent(const error_code& code, int condition) const _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
return *this == code.category() && code.value() == condition;
|
|
|
|
}
|
|
|
|
|
|
|
|
string
|
|
|
|
__do_message::message(int ev) const
|
|
|
|
{
|
|
|
|
return string(strerror(ev));
|
|
|
|
}
|
|
|
|
|
|
|
|
class _LIBCPP_HIDDEN __generic_error_category
|
|
|
|
: public __do_message
|
|
|
|
{
|
|
|
|
public:
|
2011-05-27 03:48:01 +08:00
|
|
|
virtual const char* name() const _NOEXCEPT;
|
2010-05-12 03:42:16 +08:00
|
|
|
virtual string message(int ev) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
const char*
|
2011-05-27 03:48:01 +08:00
|
|
|
__generic_error_category::name() const _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
return "generic";
|
|
|
|
}
|
|
|
|
|
|
|
|
string
|
|
|
|
__generic_error_category::message(int ev) const
|
|
|
|
{
|
2014-09-03 04:34:23 +08:00
|
|
|
#ifdef _LIBCPP_ELAST
|
|
|
|
if (ev > _LIBCPP_ELAST)
|
2010-05-25 01:49:41 +08:00
|
|
|
return string("unspecified generic_category error");
|
2014-09-03 04:34:23 +08:00
|
|
|
#endif // _LIBCPP_ELAST
|
2010-05-25 01:49:41 +08:00
|
|
|
return __do_message::message(ev);
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const error_category&
|
2011-05-27 03:48:01 +08:00
|
|
|
generic_category() _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
static __generic_error_category s;
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
class _LIBCPP_HIDDEN __system_error_category
|
|
|
|
: public __do_message
|
|
|
|
{
|
|
|
|
public:
|
2011-05-27 03:48:01 +08:00
|
|
|
virtual const char* name() const _NOEXCEPT;
|
2010-05-12 03:42:16 +08:00
|
|
|
virtual string message(int ev) const;
|
2011-05-27 03:48:01 +08:00
|
|
|
virtual error_condition default_error_condition(int ev) const _NOEXCEPT;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const char*
|
2011-05-27 03:48:01 +08:00
|
|
|
__system_error_category::name() const _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
return "system";
|
|
|
|
}
|
|
|
|
|
|
|
|
string
|
|
|
|
__system_error_category::message(int ev) const
|
|
|
|
{
|
2014-09-03 04:34:23 +08:00
|
|
|
#ifdef _LIBCPP_ELAST
|
|
|
|
if (ev > _LIBCPP_ELAST)
|
2014-05-29 13:02:22 +08:00
|
|
|
return string("unspecified system_category error");
|
2014-09-03 04:34:23 +08:00
|
|
|
#endif // _LIBCPP_ELAST
|
2010-05-25 01:49:41 +08:00
|
|
|
return __do_message::message(ev);
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
error_condition
|
2011-05-27 03:48:01 +08:00
|
|
|
__system_error_category::default_error_condition(int ev) const _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2014-09-03 04:34:23 +08:00
|
|
|
#ifdef _LIBCPP_ELAST
|
|
|
|
if (ev > _LIBCPP_ELAST)
|
2014-05-29 13:02:22 +08:00
|
|
|
return error_condition(ev, system_category());
|
2014-09-03 04:34:23 +08:00
|
|
|
#endif // _LIBCPP_ELAST
|
2010-05-25 01:49:41 +08:00
|
|
|
return error_condition(ev, generic_category());
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const error_category&
|
2011-05-27 03:48:01 +08:00
|
|
|
system_category() _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
static __system_error_category s;
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
// error_condition
|
|
|
|
|
|
|
|
string
|
|
|
|
error_condition::message() const
|
|
|
|
{
|
|
|
|
return __cat_->message(__val_);
|
|
|
|
}
|
|
|
|
|
|
|
|
// error_code
|
|
|
|
|
|
|
|
string
|
|
|
|
error_code::message() const
|
|
|
|
{
|
|
|
|
return __cat_->message(__val_);
|
|
|
|
}
|
|
|
|
|
|
|
|
// system_error
|
|
|
|
|
|
|
|
string
|
|
|
|
system_error::__init(const error_code& ec, string what_arg)
|
|
|
|
{
|
|
|
|
if (ec)
|
|
|
|
{
|
|
|
|
if (!what_arg.empty())
|
|
|
|
what_arg += ": ";
|
|
|
|
what_arg += ec.message();
|
|
|
|
}
|
2011-07-01 05:18:19 +08:00
|
|
|
return _VSTD::move(what_arg);
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
system_error::system_error(error_code ec, const string& what_arg)
|
|
|
|
: runtime_error(__init(ec, what_arg)),
|
|
|
|
__ec_(ec)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
system_error::system_error(error_code ec, const char* what_arg)
|
|
|
|
: runtime_error(__init(ec, what_arg)),
|
|
|
|
__ec_(ec)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
system_error::system_error(error_code ec)
|
|
|
|
: runtime_error(__init(ec, "")),
|
|
|
|
__ec_(ec)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
system_error::system_error(int ev, const error_category& ecat, const string& what_arg)
|
|
|
|
: runtime_error(__init(error_code(ev, ecat), what_arg)),
|
|
|
|
__ec_(error_code(ev, ecat))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
system_error::system_error(int ev, const error_category& ecat, const char* what_arg)
|
|
|
|
: runtime_error(__init(error_code(ev, ecat), what_arg)),
|
|
|
|
__ec_(error_code(ev, ecat))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
system_error::system_error(int ev, const error_category& ecat)
|
|
|
|
: runtime_error(__init(error_code(ev, ecat), "")),
|
|
|
|
__ec_(error_code(ev, ecat))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-05-27 03:48:01 +08:00
|
|
|
system_error::~system_error() _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
__throw_system_error(int ev, const char* what_arg)
|
|
|
|
{
|
2010-08-12 01:04:31 +08:00
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
2010-05-12 03:42:16 +08:00
|
|
|
throw system_error(error_code(ev, system_category()), what_arg);
|
2013-03-29 02:56:26 +08:00
|
|
|
#else
|
|
|
|
(void)ev;
|
|
|
|
(void)what_arg;
|
2010-08-12 01:04:31 +08:00
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
_LIBCPP_END_NAMESPACE_STD
|