From 5c1d821bc2ad9c5a42ddc4cc050a3bf3ecda7f2c Mon Sep 17 00:00:00 2001 From: ADAM David Alan Martin Date: Sun, 16 Oct 2022 11:36:09 -0400 Subject: [PATCH] Moving towards type-linked exception storage. --- Exception.h | 45 ++++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/Exception.h b/Exception.h index 31a4519..063df73 100644 --- a/Exception.h +++ b/Exception.h @@ -163,13 +163,25 @@ namespace Alepha::Hydrogen template< typename T > concept DerivedFromException= std::is_base_of_v< Exception, T >; - - class NamedResourceThrowable - : public virtual bases< Throwable > + class NamedResourceStorage; + class NamedResourceInterface { public: + using storage_type= NamedResourceStorage; + + virtual ~NamedResourceInterface()= default; virtual std::string_view resourceName() const noexcept= 0; }; + class NamedResourceStorage + : virtual public NamedResourceInterface + { + private: + std::string storage; + + public: + std::string_view resourceName() const noexcept final { return storage; } + }; + class NamedResourceThrowable : virtual public bases< Throwable, NamedResourceInterface > {}; class AnyTaggedNamedResourceThrowable : virtual public bases< NamedResourceThrowable, AnyTaggedThrowable > {}; template< typename tag > @@ -209,12 +221,25 @@ namespace Alepha::Hydrogen : public virtual bases< AnyTaggedNamedResourceViolation, TaggedViolation< tag >, TaggedNamedResourceThrowable< tag > > {}; - class AllocationThrowable - : public virtual bases< Throwable > + class AllocationAmountStorage; + class AllocationAmountInterface { public: + using storage_type= AllocationAmountStorage; + virtual ~AllocationAmountInterface()= default; virtual std::size_t allocationAmount() const noexcept= 0; }; + class AllocationAmountStorage + : virtual public AllocationAmountInterface + { + private: + std::size_t amount; + + public: + std::size_t allocationAmount() const noexcept final { return amount; } + }; + class AllocationThrowable + : public virtual bases< Throwable, AllocationAmountInterface > {}; class AnyTaggedAllocationThrowable : public virtual bases< AllocationThrowable, AnyTaggedThrowable > {}; template< typename tag > @@ -257,16 +282,6 @@ namespace Alepha::Hydrogen const char *message() const noexcept { return storage.c_str(); } }; - class AllocationAmountStorage - : virtual public AllocationThrowable - { - private: - std::size_t storage; - - public: - std::size_t allocationAmount() const noexcept final { return storage; } - }; - class AllocationExceptionBridge : virtual public std::bad_alloc, public virtual ExceptionBridgeInterface, virtual public Exception {