8#ifndef INCLUDED_BSLSTL_ERROR
9#define INCLUDED_BSLSTL_ERROR
76#include <bslscm_version.h>
101#ifndef BDE_DONT_ALLOW_TRANSITIVE_INCLUDES
105#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
107#include <system_error>
111using std::error_category;
112using std::error_code;
113using std::error_condition;
114using std::generic_category;
115using std::system_category;
116using std::make_error_code;
117using std::make_error_condition;
121#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_BASELINE_LIBRARY
126struct hash<error_code> : std::hash<error_code>
131struct hash<error_condition> : std::hash<error_condition>
145class error_condition;
155class error_category {
159 error_category(
const error_category&);
162 error_category& operator=(
const error_category&);
171 virtual ~error_category();
177 virtual error_condition default_error_condition(
int value)
const
182 virtual bool equivalent(
int code,
const error_condition& condition)
const
184 virtual bool equivalent(
const error_code& code,
int condition)
const
189 virtual std::string message(
int value)
const = 0;
216 typedef BloombergLP::bsls::UnspecifiedBool<error_code> UnspecifiedBool;
217 typedef UnspecifiedBool::BoolType BoolType;
228 error_code(
int value,
const error_category& category);
235 template <
class ERROR_CODE_ENUM>
236 error_code(ERROR_CODE_ENUM value,
237 typename enable_if<is_error_code_enum<ERROR_CODE_ENUM>::value,
238 BoolType>::type = 0);
243 void assign(
int value,
const error_category& category);
251 template <
class ERROR_CODE_ENUM>
252 typename enable_if<is_error_code_enum<ERROR_CODE_ENUM>::value,
254 operator=(ERROR_CODE_ENUM value);
262 const error_category& category()
const;
266 error_condition default_error_condition()
const;
269 std::string message()
const;
275 operator BoolType()
const;
280 const error_category *d_category_p;
290class error_condition {
294 typedef BloombergLP::bsls::UnspecifiedBool<error_condition>
296 typedef UnspecifiedBool::BoolType BoolType;
307 error_condition(
int value,
const error_category& category);
314 template <
class ERROR_CONDITION_ENUM>
315 error_condition(ERROR_CONDITION_ENUM value,
317 is_error_condition_enum<ERROR_CONDITION_ENUM>::value,
318 BoolType>::type = 0);
323 void assign(
int value,
const error_category& category);
329 template <
class ERROR_CONDITION_ENUM>
330 typename enable_if<is_error_condition_enum<ERROR_CONDITION_ENUM>::value,
331 error_condition&>::type
332 operator=(ERROR_CONDITION_ENUM value);
340 const error_category& category()
const;
343 std::string message()
const;
349 operator BoolType()
const;
354 const error_category *d_category_p;
360const error_category& generic_category();
363const error_category& system_category();
368error_code make_error_code(errc::Enum value);
372error_condition make_error_condition(errc::Enum value);
375template <
class HASHALG>
376void hashAppend(HASHALG& hashAlgorithm,
const error_code&
object);
379template <
class HASHALG>
380void hashAppend(HASHALG& hashAlgorithm,
const error_condition&
object);
385bool operator==(
const error_code& lhs,
const error_code& rhs);
386bool operator==(
const error_code& lhs,
const error_condition& rhs);
387bool operator==(
const error_condition& lhs,
const error_code& rhs);
388bool operator==(
const error_condition& lhs,
const error_condition& rhs);
391bool operator!=(
const error_code&,
const error_code&);
392bool operator!=(
const error_code&,
const error_condition&);
393bool operator!=(
const error_condition&,
const error_code&);
394bool operator!=(
const error_condition&,
const error_condition&);
398bool operator<(
const error_code& lhs,
const error_code& rhs);
399bool operator<(
const error_condition& lhs,
const error_condition& rhs);
402template <
class CHAR_TYPE,
class CHAR_TRAITS>
404std::basic_ostream<CHAR_TYPE, CHAR_TRAITS>&
operator<<(
405 std::basic_ostream<CHAR_TYPE, CHAR_TRAITS>& stream,
406 const error_code& code);
418error_category::error_category()
424error_condition error_category::default_error_condition(
427 return error_condition(value, *
this);
431bool error_category::equivalent(
435 return default_error_condition(code) == condition;
439bool error_category::equivalent(
440 const error_code& code,
443 return *
this == code.category() && code.value() == condition;
447std::string error_category::message(
int value)
const
449 return strerror(value);
455 return "error_category";
459bool error_category::operator==(
462 return this == &other;
466bool error_category::operator!=(
469 return !(*
this == other);
473bool error_category::operator<(
476 return std::less<const error_category *>()(
this, &other);
485error_code::error_code()
487, d_category_p(&system_category())
492error_code::error_code(
int value,
const error_category& category)
494, d_category_p(&category)
498template <
class ERROR_CODE_ENUM>
500error_code::error_code(ERROR_CODE_ENUM value,
502 is_error_code_enum<ERROR_CODE_ENUM>::value,
504: d_value(make_error_code(value).value())
505, d_category_p(&make_error_code(value).category())
512void error_code::assign(
int value,
const error_category& category)
515 d_category_p = &category;
519void error_code::clear()
522 d_category_p = &system_category();
525template <
class ERROR_CODE_ENUM>
527typename enable_if<is_error_code_enum<ERROR_CODE_ENUM>::value,
529error_code::operator=(ERROR_CODE_ENUM value)
531 d_value = make_error_code(value).value();
532 d_category_p = &make_error_code(value).category();
538const error_category& error_code::category()
const
540 return *d_category_p;
544error_condition error_code::default_error_condition()
const
546 return category().default_error_condition(value());
550std::string error_code::message()
const
552 return category().message(value());
556int error_code::value()
const
562error_code::operator BoolType()
const
564 return UnspecifiedBool::makeValue(value());
568template <
class HASHALG>
569void hashAppend(HASHALG& hashAlgorithm,
const error_code&
object)
571 using ::BloombergLP::bslh::hashAppend;
572 hashAppend(hashAlgorithm,
static_cast<const void *
>(&
object.category()));
577error_code make_error_code(errc::Enum value)
579 return error_code(
static_cast<int>(value), generic_category());
583template <
class CHAR_TYPE,
class CHAR_TRAITS>
585std::basic_ostream<CHAR_TYPE, CHAR_TRAITS>&
operator<<(
586 std::basic_ostream<CHAR_TYPE, CHAR_TRAITS>& stream,
587 const error_code& code)
589 return stream << code.category().name() <<
':' << code.value();
598error_condition::error_condition()
600, d_category_p(&generic_category())
605error_condition::error_condition(
int value,
const error_category& category)
607, d_category_p(&category)
611template <
class ERROR_CONDITION_ENUM>
613error_condition::error_condition(
614 ERROR_CONDITION_ENUM value,
615 typename enable_if<is_error_condition_enum<ERROR_CONDITION_ENUM>::value,
617: d_value(make_error_condition(value).value())
618, d_category_p(&make_error_condition(value).category())
624void error_condition::assign(
int value,
const error_category& category)
627 d_category_p = &category;
631void error_condition::clear()
634 d_category_p = &generic_category();
637template <
class ERROR_CONDITION_ENUM>
639typename enable_if<is_error_condition_enum<ERROR_CONDITION_ENUM>::value,
640 error_condition&>::type
641error_condition::operator=(ERROR_CONDITION_ENUM value)
643 d_value = make_error_condition(value).value();
644 d_category_p = &make_error_condition(value).category();
650const error_category& error_condition::category()
const
652 return *d_category_p;
656std::string error_condition::message()
const
658 return category().message(value());
662int error_condition::value()
const
668error_condition::operator BoolType()
const
670 return UnspecifiedBool::makeValue(value());
674template <
class HASHALG>
675void hashAppend(HASHALG& hashAlgorithm,
const error_condition&
object)
677 using ::BloombergLP::bslh::hashAppend;
678 hashAppend(hashAlgorithm,
static_cast<const void *
>(&
object.category()));
683error_condition make_error_condition(errc::Enum value)
685 return error_condition(
static_cast<int>(value), generic_category());
690bool operator==(
const error_code& lhs,
const error_code& rhs)
692 return lhs.category() == rhs.category() && lhs.value() == rhs.value();
696bool operator==(
const error_code& lhs,
const error_condition& rhs)
698 return lhs.category().equivalent(lhs.value(), rhs) ||
699 rhs.category().equivalent(lhs, rhs.value());
703bool operator==(
const error_condition& lhs,
const error_code& rhs)
705 return rhs.category().equivalent(rhs.value(), lhs) ||
706 lhs.category().equivalent(rhs, lhs.value());
710bool operator==(
const error_condition& lhs,
const error_condition& rhs)
712 return lhs.category() == rhs.category() && lhs.value() == rhs.value();
716bool operator!=(
const error_code& lhs,
const error_code& rhs)
718 return !(lhs == rhs);
722bool operator!=(
const error_code& lhs,
const error_condition& rhs)
724 return !(lhs == rhs);
728bool operator!=(
const error_condition& lhs,
const error_code& rhs)
730 return !(lhs == rhs);
734bool operator!=(
const error_condition& lhs,
const error_condition& rhs)
736 return !(lhs == rhs);
740bool operator<(
const error_code& lhs,
const error_code& rhs)
742 return lhs.category() < rhs.category() ||
743 (lhs.category() == rhs.category() && lhs.value() < rhs.value());
747bool operator<(
const error_condition& lhs,
const error_condition& rhs)
749 return lhs.category() < rhs.category() ||
750 (lhs.category() == rhs.category() && lhs.value() < rhs.value());
754struct hash<
bsl::error_code> : BloombergLP::bslh::Hash<>
759struct hash<
bsl::error_condition> : BloombergLP::bslh::Hash<>
767#if !defined(BSLS_PLATFORM_OS_DARWIN) || defined (BSLS_PLATFORM_CMP_GNU)
772 template <
class TYPE>
777struct hash<
bsl::error_code> : BloombergLP::bslh::Hash<>
782struct hash<
bsl::error_condition> : BloombergLP::bslh::Hash<>
bsl::ostream & operator<<(bsl::ostream &stream, const bdlat_AttributeInfo &attributeInfo)
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
#define BSLS_KEYWORD_NOEXCEPT
Definition bsls_keyword.h:632
bool operator!=(const FileCleanerConfiguration &lhs, const FileCleanerConfiguration &rhs)
bool operator==(const FileCleanerConfiguration &lhs, const FileCleanerConfiguration &rhs)
void hashAppend(HASH_ALGORITHM &hashAlg, const baljsn::EncoderTestAddress &object)
Definition baljsn_encoder_testtypes.h:9236
bool operator<(const MetricId &lhs, const MetricId &rhs)
int assign(LHS_TYPE *lhs, const RHS_TYPE &rhs)
Definition bdlb_printmethods.h:283
Definition bdldfp_decimal.h:5188