123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769 |
- #ifndef BOOST_OUTCOME_SYSTEM_ERROR2_STATUS_CODE_HPP
- #define BOOST_OUTCOME_SYSTEM_ERROR2_STATUS_CODE_HPP
- #include "status_code_domain.hpp"
- #if(__cplusplus >= 201700 || _HAS_CXX17) && !defined(BOOST_OUTCOME_SYSTEM_ERROR2_DISABLE_STD_IN_PLACE)
- #include <utility> // for in_place
- BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE_BEGIN
- using in_place_t = std::in_place_t;
- using std::in_place;
- BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE_END
- #else
- BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE_BEGIN
- struct in_place_t
- {
- explicit in_place_t() = default;
- };
- constexpr in_place_t in_place{};
- BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE_END
- #endif
- BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE_BEGIN
- namespace mixins
- {
- template <class Base, class T> struct mixin : public Base
- {
- using Base::Base;
- };
- }
- namespace detail
- {
- BOOST_OUTCOME_SYSTEM_ERROR2_TEMPLATE(class ErasedType)
- BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES(BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(traits::is_move_bitcopying<ErasedType>::value))
- struct erased
- {
- using value_type = ErasedType;
- };
- }
- template <class ErasedType>
- using status_code_erased_tag_type = detail::erased<ErasedType>;
- template <class Enum> struct quick_status_code_from_enum;
- namespace detail
- {
- template <class T> struct is_status_code
- {
- static constexpr bool value = false;
- };
- template <class T> struct is_status_code<status_code<T>>
- {
- static constexpr bool value = true;
- };
- template <class T> struct is_erased_status_code
- {
- static constexpr bool value = false;
- };
- template <class T> struct is_erased_status_code<status_code<detail::erased<T>>>
- {
- static constexpr bool value = true;
- };
- #if !defined(__GNUC__) || defined(__clang__) || __GNUC__ >= 8
-
- namespace impl
- {
- template <typename... Ts> struct make_void
- {
- using type = void;
- };
- template <typename... Ts> using void_t = typename make_void<Ts...>::type;
- template <class...> struct types
- {
- using type = types;
- };
- template <template <class...> class T, class types, class = void> struct test_apply
- {
- using type = void;
- };
- template <template <class...> class T, class... Ts> struct test_apply<T, types<Ts...>, void_t<T<Ts...>>>
- {
- using type = T<Ts...>;
- };
- }
- template <template <class...> class T, class... Ts> using test_apply = impl::test_apply<T, impl::types<Ts...>>;
- template <class T, class... Args> using get_make_status_code_result = decltype(make_status_code(std::declval<T>(), std::declval<Args>()...));
- template <class... Args> using safe_get_make_status_code_result = test_apply<get_make_status_code_result, Args...>;
- #else
-
-
- namespace impl
- {
- template <typename... Ts> struct make_void
- {
- using type = void;
- };
- template <typename... Ts> using void_t = typename make_void<Ts...>::type;
- template <class...> struct types
- {
- using type = types;
- };
- template <typename Types, typename = void> struct make_status_code_rettype
- {
- using type = void;
- };
- template <typename... Args> using get_make_status_code_result = decltype(make_status_code(std::declval<Args>()...));
- template <typename... Args> struct make_status_code_rettype<types<Args...>, void_t<get_make_status_code_result<Args...>>>
- {
- using type = get_make_status_code_result<Args...>;
- };
- }
- template <class... Args> struct safe_get_make_status_code_result
- {
- using type = typename impl::make_status_code_rettype<impl::types<Args...>>::type;
- };
- #endif
- }
- template <class T> struct is_status_code
- {
- static constexpr bool value =
- detail::is_status_code<typename std::decay<T>::type>::value || detail::is_erased_status_code<typename std::decay<T>::type>::value;
- };
- template <> class BOOST_OUTCOME_SYSTEM_ERROR2_TRIVIAL_ABI status_code<void>
- {
- template <class T> friend class status_code;
- public:
-
- using domain_type = void;
-
- using value_type = void;
-
- using string_ref = typename status_code_domain::string_ref;
- protected:
- const status_code_domain *_domain{nullptr};
- protected:
-
- status_code() = default;
-
- status_code(const status_code &) = default;
-
- status_code(status_code &&) = default;
-
- status_code &operator=(const status_code &) = default;
-
- status_code &operator=(status_code &&) = default;
-
- ~status_code() = default;
-
- constexpr explicit status_code(const status_code_domain *v) noexcept
- : _domain(v)
- {
- }
-
- constexpr const status_code_domain *_domain_ptr() const noexcept { return _domain; }
- public:
-
- constexpr const status_code_domain &domain() const noexcept { return *_domain; }
-
- BOOST_OUTCOME_SYSTEM_ERROR2_NODISCARD constexpr bool empty() const noexcept { return _domain == nullptr; }
-
- BOOST_OUTCOME_SYSTEM_ERROR2_CONSTEXPR20 string_ref message() const noexcept
- {
-
- if(_domain != nullptr)
- {
- return _domain->_do_message(*this);
- }
- return string_ref("(empty)");
- }
-
- BOOST_OUTCOME_SYSTEM_ERROR2_CONSTEXPR20 bool success() const noexcept { return (_domain != nullptr) ? !_domain->_do_failure(*this) : false; }
-
- BOOST_OUTCOME_SYSTEM_ERROR2_CONSTEXPR20 bool failure() const noexcept { return (_domain != nullptr) ? _domain->_do_failure(*this) : false; }
-
- template <class T> BOOST_OUTCOME_SYSTEM_ERROR2_CONSTEXPR14 bool strictly_equivalent(const status_code<T> &o) const noexcept
- {
- if(_domain && o._domain)
- {
- return _domain->_do_equivalent(*this, o);
- }
-
- if(!_domain && !o._domain)
- {
- return true;
- }
-
- return false;
- }
-
- template <class T> BOOST_OUTCOME_SYSTEM_ERROR2_CONSTEXPR14 inline bool equivalent(const status_code<T> &o) const noexcept;
- #if defined(_CPPUNWIND) || defined(__EXCEPTIONS) || defined(BOOST_OUTCOME_STANDARDESE_IS_IN_THE_HOUSE)
-
- BOOST_OUTCOME_SYSTEM_ERROR2_NORETURN void throw_exception() const
- {
- _domain->_do_throw_exception(*this);
- abort();
- }
- #endif
- };
- namespace detail
- {
- template <class DomainType> struct get_domain_value_type
- {
- using domain_type = DomainType;
- using value_type = typename domain_type::value_type;
- };
- template <class ErasedType> struct get_domain_value_type<erased<ErasedType>>
- {
- using domain_type = status_code_domain;
- using value_type = ErasedType;
- };
- template <class DomainType> class BOOST_OUTCOME_SYSTEM_ERROR2_TRIVIAL_ABI status_code_storage : public status_code<void>
- {
- static_assert(!std::is_void<DomainType>::value, "status_code_storage<void> should never occur!");
- using _base = status_code<void>;
- public:
-
- using domain_type = typename get_domain_value_type<DomainType>::domain_type;
-
- using value_type = typename get_domain_value_type<DomainType>::value_type;
-
- using string_ref = typename domain_type::string_ref;
- #ifndef NDEBUG
- static_assert(std::is_move_constructible<value_type>::value || std::is_copy_constructible<value_type>::value,
- "DomainType::value_type is neither move nor copy constructible!");
- static_assert(!std::is_default_constructible<value_type>::value || std::is_nothrow_default_constructible<value_type>::value,
- "DomainType::value_type is not nothrow default constructible!");
- static_assert(!std::is_move_constructible<value_type>::value || std::is_nothrow_move_constructible<value_type>::value,
- "DomainType::value_type is not nothrow move constructible!");
- static_assert(std::is_nothrow_destructible<value_type>::value, "DomainType::value_type is not nothrow destructible!");
- #endif
-
-
- constexpr const domain_type &domain() const noexcept { return *static_cast<const domain_type *>(this->_domain); }
-
- BOOST_OUTCOME_SYSTEM_ERROR2_CONSTEXPR14 void clear() noexcept
- {
- this->_value.~value_type();
- this->_domain = nullptr;
- new(std::addressof(this->_value)) value_type();
- }
- #if __cplusplus >= 201400 || _MSC_VER >= 1910
-
- constexpr value_type &value() & noexcept { return this->_value; }
-
- constexpr value_type &&value() && noexcept { return static_cast<value_type &&>(this->_value); }
- #endif
-
- constexpr const value_type &value() const & noexcept { return this->_value; }
-
- constexpr const value_type &&value() const && noexcept { return static_cast<const value_type &&>(this->_value); }
- protected:
- status_code_storage() = default;
- status_code_storage(const status_code_storage &) = default;
- BOOST_OUTCOME_SYSTEM_ERROR2_CONSTEXPR14 status_code_storage(status_code_storage &&o) noexcept
- : _base(static_cast<status_code_storage &&>(o))
- , _value(static_cast<status_code_storage &&>(o)._value)
- {
- o._domain = nullptr;
- }
- status_code_storage &operator=(const status_code_storage &) = default;
- BOOST_OUTCOME_SYSTEM_ERROR2_CONSTEXPR14 status_code_storage &operator=(status_code_storage &&o) noexcept
- {
- this->~status_code_storage();
- new(this) status_code_storage(static_cast<status_code_storage &&>(o));
- return *this;
- }
- ~status_code_storage() = default;
- value_type _value{};
- struct _value_type_constructor
- {
- };
- template <class... Args>
- constexpr status_code_storage(_value_type_constructor , const status_code_domain *v, Args &&...args)
- : _base(v)
- , _value(static_cast<Args &&>(args)...)
- {
- }
- };
- template <class DomainType> struct has_stateful_mixin
- {
- static constexpr bool value = (sizeof(status_code_storage<DomainType>) != sizeof(mixins::mixin<status_code_storage<DomainType>, DomainType>));
- };
- template <class ToDomain, class FromDomain> struct domain_value_type_erasure_is_safe
- {
- using to_value_type = typename get_domain_value_type<ToDomain>::value_type;
- using from_value_type = typename get_domain_value_type<FromDomain>::value_type;
- static constexpr bool value = traits::is_move_bitcopying<to_value_type>::value
- && traits::is_move_bitcopying<from_value_type>::value
- && sizeof(status_code_storage<FromDomain>) <= sizeof(status_code_storage<ToDomain>)
- && !has_stateful_mixin<FromDomain>::value;
- };
- template <class ToDomain> struct domain_value_type_erasure_is_safe<ToDomain, void>
- {
- static constexpr bool value = false;
- };
- }
- namespace traits
- {
-
- template <class StatusCode> using has_stateful_mixin = detail::has_stateful_mixin<typename detail::remove_cvref<StatusCode>::type::value_type>;
-
- template <class To, class From>
- using is_type_erasable_to =
- detail::domain_value_type_erasure_is_safe<typename detail::remove_cvref<To>::type::domain_type, typename detail::remove_cvref<From>::type::domain_type>;
- }
- template <class DomainType> class BOOST_OUTCOME_SYSTEM_ERROR2_TRIVIAL_ABI status_code : public mixins::mixin<detail::status_code_storage<DomainType>, DomainType>
- {
- template <class T> friend class status_code;
- using _base = mixins::mixin<detail::status_code_storage<DomainType>, DomainType>;
- public:
-
- using domain_type = DomainType;
-
- using value_type = typename domain_type::value_type;
-
- using string_ref = typename domain_type::string_ref;
- protected:
- using _base::_base;
- public:
-
- status_code() = default;
-
- status_code(const status_code &) = default;
-
- status_code(status_code &&) = default;
-
- status_code &operator=(const status_code &) = default;
-
- status_code &operator=(status_code &&) = default;
- ~status_code() = default;
-
- BOOST_OUTCOME_SYSTEM_ERROR2_CONSTEXPR14 status_code clone() const { return *this; }
-
-
- BOOST_OUTCOME_SYSTEM_ERROR2_TEMPLATE(
- class T, class... Args,
- class MakeStatusCodeResult =
- typename detail::safe_get_make_status_code_result<T, Args...>::type)
- BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES(BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(!std::is_same<typename std::decay<T>::type, status_code>::value
- && !std::is_same<typename std::decay<T>::type, in_place_t>::value
- && is_status_code<MakeStatusCodeResult>::value
- && std::is_constructible<status_code, MakeStatusCodeResult>::value))
- constexpr status_code(T &&v, Args &&...args) noexcept(noexcept(make_status_code(std::declval<T>(), std::declval<Args>()...)))
- : status_code(make_status_code(static_cast<T &&>(v), static_cast<Args &&>(args)...))
- {
- }
-
- BOOST_OUTCOME_SYSTEM_ERROR2_TEMPLATE(class Enum,
- class QuickStatusCodeType = typename quick_status_code_from_enum<Enum>::code_type)
- BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES(BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(std::is_constructible<status_code, QuickStatusCodeType>::value))
- constexpr status_code(Enum &&v) noexcept(std::is_nothrow_constructible<status_code, QuickStatusCodeType>::value)
- : status_code(QuickStatusCodeType(static_cast<Enum &&>(v)))
- {
- }
-
- template <class... Args>
- constexpr explicit status_code(in_place_t , Args &&...args) noexcept(std::is_nothrow_constructible<value_type, Args &&...>::value)
- : _base(typename _base::_value_type_constructor{}, &domain_type::get(), static_cast<Args &&>(args)...)
- {
- }
-
- template <class T, class... Args>
- constexpr explicit status_code(in_place_t , std::initializer_list<T> il,
- Args &&...args) noexcept(std::is_nothrow_constructible<value_type, std::initializer_list<T>, Args &&...>::value)
- : _base(typename _base::_value_type_constructor{}, &domain_type::get(), il, static_cast<Args &&>(args)...)
- {
- }
-
- constexpr explicit status_code(const value_type &v) noexcept(std::is_nothrow_copy_constructible<value_type>::value)
- : _base(typename _base::_value_type_constructor{}, &domain_type::get(), v)
- {
- }
-
- constexpr explicit status_code(value_type &&v) noexcept(std::is_nothrow_move_constructible<value_type>::value)
- : _base(typename _base::_value_type_constructor{}, &domain_type::get(), static_cast<value_type &&>(v))
- {
- }
-
- BOOST_OUTCOME_SYSTEM_ERROR2_TEMPLATE(class ErasedType)
- BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES(BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(detail::domain_value_type_erasure_is_safe<domain_type, detail::erased<ErasedType>>::value))
- constexpr explicit status_code(const status_code<detail::erased<ErasedType>> &v) noexcept(std::is_nothrow_copy_constructible<value_type>::value)
- : status_code(detail::erasure_cast<value_type>(v.value()))
- {
- #if __cplusplus >= 201400
- assert(v.domain() == this->domain());
- #endif
- }
-
- BOOST_OUTCOME_SYSTEM_ERROR2_CONSTEXPR20 string_ref message() const noexcept
- {
-
- if(this->_domain != nullptr)
- {
- return string_ref(this->domain()._do_message(*this));
- }
- return string_ref("(empty)");
- }
- };
- namespace traits
- {
- template <class DomainType> struct is_move_bitcopying<status_code<DomainType>>
- {
- static constexpr bool value = is_move_bitcopying<typename DomainType::value_type>::value;
- };
- }
- template <class ErasedType>
- class BOOST_OUTCOME_SYSTEM_ERROR2_TRIVIAL_ABI status_code<detail::erased<ErasedType>>
- : public mixins::mixin<detail::status_code_storage<detail::erased<ErasedType>>, detail::erased<ErasedType>>
- {
- template <class T> friend class status_code;
- using _base = mixins::mixin<detail::status_code_storage<detail::erased<ErasedType>>, detail::erased<ErasedType>>;
- public:
-
- using domain_type = void;
-
- using value_type = ErasedType;
-
- using string_ref = typename _base::string_ref;
- public:
-
- status_code() = default;
-
- status_code(const status_code &) = delete;
-
- status_code(status_code &&) = default;
-
- status_code &operator=(const status_code &) = delete;
-
- status_code &operator=(status_code &&) = default;
- BOOST_OUTCOME_SYSTEM_ERROR2_CONSTEXPR20 ~status_code()
- {
- if(nullptr != this->_domain)
- {
- status_code_domain::payload_info_t info{sizeof(value_type), sizeof(status_code), alignof(status_code)};
- this->_domain->_do_erased_destroy(*this, info);
- }
- }
-
- BOOST_OUTCOME_SYSTEM_ERROR2_CONSTEXPR20 status_code clone() const
- {
- if(nullptr == this->_domain)
- {
- return {};
- }
- status_code x;
- if(!this->_domain->_do_erased_copy(x, *this, this->_domain->payload_info()))
- {
- abort();
- }
- return x;
- }
-
-
-
- BOOST_OUTCOME_SYSTEM_ERROR2_TEMPLATE(class DomainType)
- BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES(BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(detail::domain_value_type_erasure_is_safe<detail::erased<ErasedType>, DomainType>::value),
- BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(!detail::is_erased_status_code<status_code<typename std::decay<DomainType>::type>>::value))
- constexpr status_code(const status_code<DomainType> &v) noexcept
- : _base(typename _base::_value_type_constructor{}, v._domain_ptr(), detail::erasure_cast<value_type>(v.value()))
- {
- }
-
- BOOST_OUTCOME_SYSTEM_ERROR2_TEMPLATE(class DomainType)
- BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES(BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(detail::domain_value_type_erasure_is_safe<detail::erased<ErasedType>, DomainType>::value))
- BOOST_OUTCOME_SYSTEM_ERROR2_CONSTEXPR14 status_code(status_code<DomainType> &&v) noexcept
- : _base(typename _base::_value_type_constructor{}, v._domain_ptr(), detail::erasure_cast<value_type>(v.value()))
- {
- alignas(alignof(typename DomainType::value_type)) char buffer[sizeof(typename DomainType::value_type)];
- new(buffer) typename DomainType::value_type(static_cast<status_code<DomainType> &&>(v).value());
-
- (void) buffer;
- v._domain = nullptr;
- }
-
- BOOST_OUTCOME_SYSTEM_ERROR2_TEMPLATE(
- class T, class... Args,
- class MakeStatusCodeResult =
- typename detail::safe_get_make_status_code_result<T, Args...>::type)
- BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES(BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(!std::is_same<typename std::decay<T>::type, status_code>::value
- && !std::is_same<typename std::decay<T>::type, value_type>::value
- && is_status_code<MakeStatusCodeResult>::value
- && std::is_constructible<status_code, MakeStatusCodeResult>::value))
- constexpr status_code(T &&v, Args &&...args) noexcept(noexcept(make_status_code(std::declval<T>(), std::declval<Args>()...)))
- : status_code(make_status_code(static_cast<T &&>(v), static_cast<Args &&>(args)...))
- {
- }
-
- BOOST_OUTCOME_SYSTEM_ERROR2_TEMPLATE(class Enum,
- class QuickStatusCodeType = typename quick_status_code_from_enum<Enum>::code_type)
- BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES(BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(std::is_constructible<status_code, QuickStatusCodeType>::value))
- constexpr status_code(Enum &&v) noexcept(std::is_nothrow_constructible<status_code, QuickStatusCodeType>::value)
- : status_code(QuickStatusCodeType(static_cast<Enum &&>(v)))
- {
- }
- #if defined(_CPPUNWIND) || defined(__EXCEPTIONS) || defined(BOOST_OUTCOME_STANDARDESE_IS_IN_THE_HOUSE)
-
-
- explicit BOOST_OUTCOME_SYSTEM_ERROR2_CONSTEXPR14 status_code(in_place_t, const status_code<void> &v)
- : _base(typename _base::_value_type_constructor{}, v._domain_ptr(), value_type{})
- {
- status_code_domain::payload_info_t info{sizeof(value_type), sizeof(status_code), alignof(status_code)};
- if(this->_domain->_do_erased_copy(*this, v, info))
- {
- return;
- }
- struct _ final : public std::exception
- {
- virtual const char *what() const noexcept override { return "status_code: source domain's erased copy function returned failure or refusal"; }
- };
- throw _{};
- }
- #endif
-
-
- BOOST_OUTCOME_SYSTEM_ERROR2_CONSTEXPR20 status_code(std::nothrow_t, const status_code<void> &v) noexcept
- : _base(typename _base::_value_type_constructor{}, v._domain_ptr(), value_type{})
- {
- #if defined(_CPPUNWIND) || defined(__EXCEPTIONS) || defined(BOOST_OUTCOME_STANDARDESE_IS_IN_THE_HOUSE)
- try
- #endif
- {
- status_code_domain::payload_info_t info{sizeof(value_type), sizeof(status_code), alignof(status_code)};
- if(this->_domain->_do_erased_copy(*this, v, info))
- {
- return;
- }
- this->_domain = nullptr;
- }
- #if defined(_CPPUNWIND) || defined(__EXCEPTIONS) || defined(BOOST_OUTCOME_STANDARDESE_IS_IN_THE_HOUSE)
- catch(...)
- {
- this->_domain = nullptr;
- }
- #endif
- }
-
-
- BOOST_OUTCOME_SYSTEM_ERROR2_CONSTEXPR14 void clear() noexcept { *this = status_code(); }
-
- constexpr value_type value() const noexcept { return this->_value; }
- };
- template <class ErasedType> using erased_status_code = status_code<detail::erased<ErasedType>>;
- namespace traits
- {
- template <class ErasedType> struct is_move_bitcopying<status_code<detail::erased<ErasedType>>>
- {
- static constexpr bool value = true;
- };
- }
- BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE_END
- #ifndef BOOST_OUTCOME_SYSTEM_ERROR2_DISABLE_INLINE_GDB_PRETTY_PRINTERS
- #if defined(__ELF__)
- __asm__(
- ".pushsection \".debug_gdb_scripts\", \"MS\",@progbits,1\n"
- ".byte 4 /* Python Text */\n"
- ".ascii \"gdb.inlined-script\\n\"\n"
- ".ascii \"import gdb.printing\\n\"\n"
- ".ascii \"import gdb\\n\"\n"
- ".ascii \"import os\\n\"\n"
- ".ascii \"def synthesise_gdb_value_from_string(s):\\n\"\n"
- ".ascii \" '''For when you want to return a synthetic string from children()'''\\n\"\n"
- ".ascii \" return gdb.Value(s + '\\0').cast(gdb.lookup_type('char').pointer())\\n\"\n"
- ".ascii \"class StatusCodePrinter(object):\\n\"\n"
- ".ascii \" '''Print a system_error2::status_code<T>'''\\n\"\n"
- ".ascii \" def __init__(self, val):\\n\"\n"
- ".ascii \" self.val = val\\n\"\n"
- ".ascii \" def children(self):\\n\"\n"
- ".ascii \" s = str(self.val['_domain'])\\n\"\n"
- ".ascii \" if 'posix_code_domain' in s or 'generic_code_domain' in s:\\n\"\n"
- ".ascii \" yield ('msg', synthesise_gdb_value_from_string(str(self.val['_value']) + ' (' + os.strerror(int(self.val['_value'])) + ')'))\\n\"\n"
- ".ascii \" yield ('domain', self.val['_domain'])\\n\"\n"
- ".ascii \" yield ('value', self.val['_value'])\\n\"\n"
- ".ascii \" def display_hint(self):\\n\"\n"
- ".ascii \" return None\\n\"\n"
- ".ascii \" def to_string(self):\\n\"\n"
- ".ascii \" s = str(self.val['_domain'])\\n\"\n"
- ".ascii \" if 'posix_code_domain' in s or 'generic_code_domain' in s:\\n\"\n"
- ".ascii \" return str(self.val['_value']) + ' (' + os.strerror(int(self.val['_value'])) + ')'\\n\"\n"
- ".ascii \" else:\\n\"\n"
- ".ascii \" return self.val['_value']\\n\"\n"
- ".ascii \"def build_pretty_printer():\\n\"\n"
- ".ascii \" pp = gdb.printing.RegexpCollectionPrettyPrinter('system_error2')\\n\"\n"
- ".ascii \" pp.add_printer('system_error2::status_code', '^(boost::)?system_error2::status_code<.*>$', StatusCodePrinter)\\n\"\n"
- ".ascii \" return pp\\n\"\n"
- ".ascii \"def register_printers(obj = None):\\n\"\n"
- ".ascii \" gdb.printing.register_pretty_printer(obj, build_pretty_printer(), replace = True)\\n\"\n"
- ".ascii \"register_printers(gdb.current_objfile())\\n\"\n"
- ".byte 0\n"
- ".popsection\n");
- #endif
- #endif
- #endif
|