From c5ad3720de7209deb560232b4d4ad84a3ff890f7 Mon Sep 17 00:00:00 2001 From: sha512sum Date: Thu, 2 Jan 2025 22:30:07 +1100 Subject: [PATCH] Move to impl namespace --- library/include/larra/stanza_error.hpp | 104 ++++++++++++------------- library/include/larra/stream_error.hpp | 57 +++++++------- 2 files changed, 81 insertions(+), 80 deletions(-) diff --git a/library/include/larra/stanza_error.hpp b/library/include/larra/stanza_error.hpp index 5ba6e23..4a8cef7 100644 --- a/library/include/larra/stanza_error.hpp +++ b/library/include/larra/stanza_error.hpp @@ -58,19 +58,17 @@ struct Type : TypeVariant { }; struct StanzaErrorBase : std::exception {}; - -// DO NOT MOVE TO ANOTHER NAMESPACE(where no heirs). VIA friend A FUNCTION IS ADDED THAT VIA ADL WILL BE SEARCHED FOR HEIRS -// C++20 modules very unstable in clangd :( +namespace impl { template -struct StanzaErrorImpl : StanzaErrorBase { +struct StanzaError : StanzaErrorBase { static constexpr auto kDefaultName = "error"; static constexpr auto kDefaultNamespace = "urn:ietf:params:xml:ns:xmpp-stanzas"; static inline const auto kKebabCaseName = static_cast(utils::ToKebabCaseName()); - constexpr StanzaErrorImpl(std::optional by, Type type) : by(std::move(by)), type(std::move(type)) { + constexpr StanzaError(std::optional by, Type type) : by(std::move(by)), type(std::move(type)) { } - constexpr StanzaErrorImpl() = default; + constexpr StanzaError() = default; struct FieldInfo { - using Main = StanzaErrorImpl; + using Main = StanzaError; using Info = serialization::MetaInfo
; using Type = Type; static inline const std::string kName = "type"; @@ -121,7 +119,7 @@ struct StanzaErrorImpl : StanzaErrorBase { auto node = element->add_child_element(kKebabCaseName); node->set_namespace_declaration(kDefaultNamespace); } - constexpr auto operator==(const StanzaErrorImpl&) const -> bool { + constexpr auto operator==(const StanzaError&) const -> bool { return true; }; [[nodiscard]] constexpr auto what() const noexcept -> const char* override { @@ -129,6 +127,8 @@ struct StanzaErrorImpl : StanzaErrorBase { } }; +} // namespace impl + // Helper class to prevent parsing response stream into an expected return type if its name is an 'error' struct UnknownStanzaError : StanzaErrorBase { static constexpr auto kDefaultName = "stream:error"; @@ -151,71 +151,71 @@ struct UnknownStanzaError : StanzaErrorBase { } }; -struct BadRequest : StanzaErrorImpl { - using StanzaErrorImpl::StanzaErrorImpl; +struct BadRequest : impl::StanzaError { + using impl::StanzaError::StanzaError; }; -struct Conflict : StanzaErrorImpl { - using StanzaErrorImpl::StanzaErrorImpl; +struct Conflict : impl::StanzaError { + using impl::StanzaError::StanzaError; }; -struct FeatureNotImplemented : StanzaErrorImpl { - using StanzaErrorImpl::StanzaErrorImpl; +struct FeatureNotImplemented : impl::StanzaError { + using impl::StanzaError::StanzaError; }; -struct Forbidden : StanzaErrorImpl { - using StanzaErrorImpl::StanzaErrorImpl; +struct Forbidden : impl::StanzaError { + using impl::StanzaError::StanzaError; }; -struct Gone : StanzaErrorImpl { - using StanzaErrorImpl::StanzaErrorImpl; +struct Gone : impl::StanzaError { + using impl::StanzaError::StanzaError; }; -struct InternalServerError : StanzaErrorImpl { - using StanzaErrorImpl::StanzaErrorImpl; +struct InternalServerError : impl::StanzaError { + using impl::StanzaError::StanzaError; }; -struct ItemNotFound : StanzaErrorImpl { - using StanzaErrorImpl::StanzaErrorImpl; +struct ItemNotFound : impl::StanzaError { + using impl::StanzaError::StanzaError; }; -struct JidMalformed : StanzaErrorImpl { - using StanzaErrorImpl::StanzaErrorImpl; +struct JidMalformed : impl::StanzaError { + using impl::StanzaError::StanzaError; }; -struct NotAcceptable : StanzaErrorImpl { - using StanzaErrorImpl::StanzaErrorImpl; +struct NotAcceptable : impl::StanzaError { + using impl::StanzaError::StanzaError; }; -struct NotAllowed : StanzaErrorImpl { - using StanzaErrorImpl::StanzaErrorImpl; +struct NotAllowed : impl::StanzaError { + using impl::StanzaError::StanzaError; }; -struct NotAuthorized : StanzaErrorImpl { - using StanzaErrorImpl::StanzaErrorImpl; +struct NotAuthorized : impl::StanzaError { + using impl::StanzaError::StanzaError; }; -struct PolicyViolation : StanzaErrorImpl { - using StanzaErrorImpl::StanzaErrorImpl; +struct PolicyViolation : impl::StanzaError { + using impl::StanzaError::StanzaError; }; -struct RecipientUnavailable : StanzaErrorImpl { - using StanzaErrorImpl::StanzaErrorImpl; +struct RecipientUnavailable : impl::StanzaError { + using impl::StanzaError::StanzaError; }; -struct Redirect : StanzaErrorImpl { - using StanzaErrorImpl::StanzaErrorImpl; +struct Redirect : impl::StanzaError { + using impl::StanzaError::StanzaError; }; -struct RegistrationRequired : StanzaErrorImpl { - using StanzaErrorImpl::StanzaErrorImpl; +struct RegistrationRequired : impl::StanzaError { + using impl::StanzaError::StanzaError; }; -struct RemoteServerNotFound : StanzaErrorImpl { - using StanzaErrorImpl::StanzaErrorImpl; +struct RemoteServerNotFound : impl::StanzaError { + using impl::StanzaError::StanzaError; }; -struct RemoteServerTimeout : StanzaErrorImpl { - using StanzaErrorImpl::StanzaErrorImpl; +struct RemoteServerTimeout : impl::StanzaError { + using impl::StanzaError::StanzaError; }; -struct ResourceConstraint : StanzaErrorImpl { - using StanzaErrorImpl::StanzaErrorImpl; +struct ResourceConstraint : impl::StanzaError { + using impl::StanzaError::StanzaError; }; -struct ServiceUnavailable : StanzaErrorImpl { - using StanzaErrorImpl::StanzaErrorImpl; +struct ServiceUnavailable : impl::StanzaError { + using impl::StanzaError::StanzaError; }; -struct SubscriptionRequired : StanzaErrorImpl { - using StanzaErrorImpl::StanzaErrorImpl; +struct SubscriptionRequired : impl::StanzaError { + using impl::StanzaError::StanzaError; }; -struct UndefinedCondition : StanzaErrorImpl { - using StanzaErrorImpl::StanzaErrorImpl; +struct UndefinedCondition : impl::StanzaError { + using impl::StanzaError::StanzaError; }; -struct UnexpectedRequest : StanzaErrorImpl { - using StanzaErrorImpl::StanzaErrorImpl; +struct UnexpectedRequest : impl::StanzaError { + using impl::StanzaError::StanzaError; }; using StanzaError = std::variant -struct ErrorImpl : BaseError { +struct Error : BaseError { static constexpr auto kDefaultName = "stream:error"; static inline const auto kKebabCaseName = static_cast(utils::ToKebabCaseName()); @@ -40,6 +39,8 @@ struct ErrorImpl : BaseError { } }; +} // namespace impl + // Helper class to prevent parsing response stream into an expected return type if its name is a 'stream:error' struct UnknownXmppError : BaseError { static constexpr auto kDefaultName = "stream:error"; @@ -59,31 +60,31 @@ struct UnknownXmppError : BaseError { } }; -struct BadFormat : ErrorImpl {}; -struct BadNamespacePrefix : ErrorImpl {}; -struct Conflict : ErrorImpl {}; -struct ConnectionTimeout : ErrorImpl {}; -struct HostGone : ErrorImpl {}; -struct HostUnknown : ErrorImpl {}; -struct ImproperAdressing : ErrorImpl {}; -struct InternalServerError : ErrorImpl {}; -struct InvalidFrom : ErrorImpl {}; -struct InvalidNamespace : ErrorImpl {}; -struct InvalidXml : ErrorImpl {}; -struct NotAuthorized : ErrorImpl {}; -struct NotWellFormed : ErrorImpl {}; -struct PolicyViolation : ErrorImpl {}; -struct RemoteConnectionFailed : ErrorImpl {}; -struct Reset : ErrorImpl {}; -struct ResourceConstraint : ErrorImpl {}; -struct RestrictedXml : ErrorImpl {}; -struct SeeOtherHost : ErrorImpl {}; -struct SystemShutdown : ErrorImpl {}; -struct UndefinedCondition : ErrorImpl {}; -struct UnsupportedEncoding : ErrorImpl {}; -struct UnsupportedFeature : ErrorImpl {}; -struct UnsupportedStanzaType : ErrorImpl {}; -struct UnsupportedVersion : ErrorImpl {}; +struct BadFormat : impl::Error {}; +struct BadNamespacePrefix : impl::Error {}; +struct Conflict : impl::Error {}; +struct ConnectionTimeout : impl::Error {}; +struct HostGone : impl::Error {}; +struct HostUnknown : impl::Error {}; +struct ImproperAdressing : impl::Error {}; +struct InternalServerError : impl::Error {}; +struct InvalidFrom : impl::Error {}; +struct InvalidNamespace : impl::Error {}; +struct InvalidXml : impl::Error {}; +struct NotAuthorized : impl::Error {}; +struct NotWellFormed : impl::Error {}; +struct PolicyViolation : impl::Error {}; +struct RemoteConnectionFailed : impl::Error {}; +struct Reset : impl::Error {}; +struct ResourceConstraint : impl::Error {}; +struct RestrictedXml : impl::Error {}; +struct SeeOtherHost : impl::Error {}; +struct SystemShutdown : impl::Error {}; +struct UndefinedCondition : impl::Error {}; +struct UnsupportedEncoding : impl::Error {}; +struct UnsupportedFeature : impl::Error {}; +struct UnsupportedStanzaType : impl::Error {}; +struct UnsupportedVersion : impl::Error {}; } // namespace error::stream