Move to impl namespace
Some checks failed
PR Check / on-push-commit-check (push) Failing after 1m45s

This commit is contained in:
sha512sum 2025-01-02 22:30:07 +11:00
parent cda854553c
commit c5ad3720de
2 changed files with 81 additions and 80 deletions

View file

@ -58,19 +58,17 @@ struct Type : TypeVariant {
}; };
struct StanzaErrorBase : std::exception {}; struct StanzaErrorBase : std::exception {};
namespace impl {
// 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 :(
template <typename T, typename Default> template <typename T, typename Default>
struct StanzaErrorImpl : StanzaErrorBase { struct StanzaError : StanzaErrorBase {
static constexpr auto kDefaultName = "error"; static constexpr auto kDefaultName = "error";
static constexpr auto kDefaultNamespace = "urn:ietf:params:xml:ns:xmpp-stanzas"; static constexpr auto kDefaultNamespace = "urn:ietf:params:xml:ns:xmpp-stanzas";
static inline const auto kKebabCaseName = static_cast<std::string>(utils::ToKebabCaseName<T>()); static inline const auto kKebabCaseName = static_cast<std::string>(utils::ToKebabCaseName<T>());
constexpr StanzaErrorImpl(std::optional<std::string> by, Type type) : by(std::move(by)), type(std::move(type)) { constexpr StanzaError(std::optional<std::string> by, Type type) : by(std::move(by)), type(std::move(type)) {
} }
constexpr StanzaErrorImpl() = default; constexpr StanzaError() = default;
struct FieldInfo { struct FieldInfo {
using Main = StanzaErrorImpl; using Main = StanzaError;
using Info = serialization::MetaInfo<Main>; using Info = serialization::MetaInfo<Main>;
using Type = Type; using Type = Type;
static inline const std::string kName = "type"; static inline const std::string kName = "type";
@ -121,7 +119,7 @@ struct StanzaErrorImpl : StanzaErrorBase {
auto node = element->add_child_element(kKebabCaseName); auto node = element->add_child_element(kKebabCaseName);
node->set_namespace_declaration(kDefaultNamespace); node->set_namespace_declaration(kDefaultNamespace);
} }
constexpr auto operator==(const StanzaErrorImpl&) const -> bool { constexpr auto operator==(const StanzaError&) const -> bool {
return true; return true;
}; };
[[nodiscard]] constexpr auto what() const noexcept -> const char* override { [[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' // Helper class to prevent parsing response stream into an expected return type if its name is an 'error'
struct UnknownStanzaError : StanzaErrorBase { struct UnknownStanzaError : StanzaErrorBase {
static constexpr auto kDefaultName = "stream:error"; static constexpr auto kDefaultName = "stream:error";
@ -151,71 +151,71 @@ struct UnknownStanzaError : StanzaErrorBase {
} }
}; };
struct BadRequest : StanzaErrorImpl<BadRequest, type::Modify> { struct BadRequest : impl::StanzaError<BadRequest, type::Modify> {
using StanzaErrorImpl<BadRequest, type::Modify>::StanzaErrorImpl; using impl::StanzaError<BadRequest, type::Modify>::StanzaError;
}; };
struct Conflict : StanzaErrorImpl<Conflict, type::Cancel> { struct Conflict : impl::StanzaError<Conflict, type::Cancel> {
using StanzaErrorImpl<Conflict, type::Cancel>::StanzaErrorImpl; using impl::StanzaError<Conflict, type::Cancel>::StanzaError;
}; };
struct FeatureNotImplemented : StanzaErrorImpl<FeatureNotImplemented, type::Cancel> { struct FeatureNotImplemented : impl::StanzaError<FeatureNotImplemented, type::Cancel> {
using StanzaErrorImpl<FeatureNotImplemented, type::Cancel>::StanzaErrorImpl; using impl::StanzaError<FeatureNotImplemented, type::Cancel>::StanzaError;
}; };
struct Forbidden : StanzaErrorImpl<Forbidden, type::Auth> { struct Forbidden : impl::StanzaError<Forbidden, type::Auth> {
using StanzaErrorImpl<Forbidden, type::Auth>::StanzaErrorImpl; using impl::StanzaError<Forbidden, type::Auth>::StanzaError;
}; };
struct Gone : StanzaErrorImpl<Gone, type::Cancel> { struct Gone : impl::StanzaError<Gone, type::Cancel> {
using StanzaErrorImpl<Gone, type::Cancel>::StanzaErrorImpl; using impl::StanzaError<Gone, type::Cancel>::StanzaError;
}; };
struct InternalServerError : StanzaErrorImpl<InternalServerError, type::Cancel> { struct InternalServerError : impl::StanzaError<InternalServerError, type::Cancel> {
using StanzaErrorImpl<InternalServerError, type::Cancel>::StanzaErrorImpl; using impl::StanzaError<InternalServerError, type::Cancel>::StanzaError;
}; };
struct ItemNotFound : StanzaErrorImpl<ItemNotFound, type::Cancel> { struct ItemNotFound : impl::StanzaError<ItemNotFound, type::Cancel> {
using StanzaErrorImpl<ItemNotFound, type::Cancel>::StanzaErrorImpl; using impl::StanzaError<ItemNotFound, type::Cancel>::StanzaError;
}; };
struct JidMalformed : StanzaErrorImpl<JidMalformed, type::Modify> { struct JidMalformed : impl::StanzaError<JidMalformed, type::Modify> {
using StanzaErrorImpl<JidMalformed, type::Modify>::StanzaErrorImpl; using impl::StanzaError<JidMalformed, type::Modify>::StanzaError;
}; };
struct NotAcceptable : StanzaErrorImpl<NotAcceptable, type::Modify> { struct NotAcceptable : impl::StanzaError<NotAcceptable, type::Modify> {
using StanzaErrorImpl<NotAcceptable, type::Modify>::StanzaErrorImpl; using impl::StanzaError<NotAcceptable, type::Modify>::StanzaError;
}; };
struct NotAllowed : StanzaErrorImpl<NotAllowed, type::Cancel> { struct NotAllowed : impl::StanzaError<NotAllowed, type::Cancel> {
using StanzaErrorImpl<NotAllowed, type::Cancel>::StanzaErrorImpl; using impl::StanzaError<NotAllowed, type::Cancel>::StanzaError;
}; };
struct NotAuthorized : StanzaErrorImpl<NotAuthorized, type::Auth> { struct NotAuthorized : impl::StanzaError<NotAuthorized, type::Auth> {
using StanzaErrorImpl<NotAuthorized, type::Auth>::StanzaErrorImpl; using impl::StanzaError<NotAuthorized, type::Auth>::StanzaError;
}; };
struct PolicyViolation : StanzaErrorImpl<PolicyViolation, type::Modify> { struct PolicyViolation : impl::StanzaError<PolicyViolation, type::Modify> {
using StanzaErrorImpl<PolicyViolation, type::Modify>::StanzaErrorImpl; using impl::StanzaError<PolicyViolation, type::Modify>::StanzaError;
}; };
struct RecipientUnavailable : StanzaErrorImpl<RecipientUnavailable, type::Wait> { struct RecipientUnavailable : impl::StanzaError<RecipientUnavailable, type::Wait> {
using StanzaErrorImpl<RecipientUnavailable, type::Wait>::StanzaErrorImpl; using impl::StanzaError<RecipientUnavailable, type::Wait>::StanzaError;
}; };
struct Redirect : StanzaErrorImpl<Redirect, type::Modify> { struct Redirect : impl::StanzaError<Redirect, type::Modify> {
using StanzaErrorImpl<Redirect, type::Modify>::StanzaErrorImpl; using impl::StanzaError<Redirect, type::Modify>::StanzaError;
}; };
struct RegistrationRequired : StanzaErrorImpl<RegistrationRequired, type::Auth> { struct RegistrationRequired : impl::StanzaError<RegistrationRequired, type::Auth> {
using StanzaErrorImpl<RegistrationRequired, type::Auth>::StanzaErrorImpl; using impl::StanzaError<RegistrationRequired, type::Auth>::StanzaError;
}; };
struct RemoteServerNotFound : StanzaErrorImpl<RemoteServerNotFound, type::Cancel> { struct RemoteServerNotFound : impl::StanzaError<RemoteServerNotFound, type::Cancel> {
using StanzaErrorImpl<RemoteServerNotFound, type::Cancel>::StanzaErrorImpl; using impl::StanzaError<RemoteServerNotFound, type::Cancel>::StanzaError;
}; };
struct RemoteServerTimeout : StanzaErrorImpl<RemoteServerTimeout, type::Wait> { struct RemoteServerTimeout : impl::StanzaError<RemoteServerTimeout, type::Wait> {
using StanzaErrorImpl<RemoteServerTimeout, type::Wait>::StanzaErrorImpl; using impl::StanzaError<RemoteServerTimeout, type::Wait>::StanzaError;
}; };
struct ResourceConstraint : StanzaErrorImpl<ResourceConstraint, type::Wait> { struct ResourceConstraint : impl::StanzaError<ResourceConstraint, type::Wait> {
using StanzaErrorImpl<ResourceConstraint, type::Wait>::StanzaErrorImpl; using impl::StanzaError<ResourceConstraint, type::Wait>::StanzaError;
}; };
struct ServiceUnavailable : StanzaErrorImpl<ServiceUnavailable, type::Cancel> { struct ServiceUnavailable : impl::StanzaError<ServiceUnavailable, type::Cancel> {
using StanzaErrorImpl<ServiceUnavailable, type::Cancel>::StanzaErrorImpl; using impl::StanzaError<ServiceUnavailable, type::Cancel>::StanzaError;
}; };
struct SubscriptionRequired : StanzaErrorImpl<SubscriptionRequired, type::Auth> { struct SubscriptionRequired : impl::StanzaError<SubscriptionRequired, type::Auth> {
using StanzaErrorImpl<SubscriptionRequired, type::Auth>::StanzaErrorImpl; using impl::StanzaError<SubscriptionRequired, type::Auth>::StanzaError;
}; };
struct UndefinedCondition : StanzaErrorImpl<UndefinedCondition, type::Modify> { struct UndefinedCondition : impl::StanzaError<UndefinedCondition, type::Modify> {
using StanzaErrorImpl<UndefinedCondition, type::Modify>::StanzaErrorImpl; using impl::StanzaError<UndefinedCondition, type::Modify>::StanzaError;
}; };
struct UnexpectedRequest : StanzaErrorImpl<UnexpectedRequest, type::Modify> { struct UnexpectedRequest : impl::StanzaError<UnexpectedRequest, type::Modify> {
using StanzaErrorImpl<UnexpectedRequest, type::Modify>::StanzaErrorImpl; using impl::StanzaError<UnexpectedRequest, type::Modify>::StanzaError;
}; };
using StanzaError = std::variant<BadRequest, using StanzaError = std::variant<BadRequest,

View file

@ -10,10 +10,9 @@ namespace error::stream {
struct BaseError : std::exception {}; struct BaseError : 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 namespace impl {
// C++20 modules very unstable in clangd :(
template <typename T> template <typename T>
struct ErrorImpl : BaseError { struct Error : BaseError {
static constexpr auto kDefaultName = "stream:error"; static constexpr auto kDefaultName = "stream:error";
static inline const auto kKebabCaseName = static_cast<std::string>(utils::ToKebabCaseName<T>()); static inline const auto kKebabCaseName = static_cast<std::string>(utils::ToKebabCaseName<T>());
@ -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' // Helper class to prevent parsing response stream into an expected return type if its name is a 'stream:error'
struct UnknownXmppError : BaseError { struct UnknownXmppError : BaseError {
static constexpr auto kDefaultName = "stream:error"; static constexpr auto kDefaultName = "stream:error";
@ -59,31 +60,31 @@ struct UnknownXmppError : BaseError {
} }
}; };
struct BadFormat : ErrorImpl<BadFormat> {}; struct BadFormat : impl::Error<BadFormat> {};
struct BadNamespacePrefix : ErrorImpl<BadNamespacePrefix> {}; struct BadNamespacePrefix : impl::Error<BadNamespacePrefix> {};
struct Conflict : ErrorImpl<Conflict> {}; struct Conflict : impl::Error<Conflict> {};
struct ConnectionTimeout : ErrorImpl<ConnectionTimeout> {}; struct ConnectionTimeout : impl::Error<ConnectionTimeout> {};
struct HostGone : ErrorImpl<HostGone> {}; struct HostGone : impl::Error<HostGone> {};
struct HostUnknown : ErrorImpl<HostUnknown> {}; struct HostUnknown : impl::Error<HostUnknown> {};
struct ImproperAdressing : ErrorImpl<ImproperAdressing> {}; struct ImproperAdressing : impl::Error<ImproperAdressing> {};
struct InternalServerError : ErrorImpl<InternalServerError> {}; struct InternalServerError : impl::Error<InternalServerError> {};
struct InvalidFrom : ErrorImpl<InvalidFrom> {}; struct InvalidFrom : impl::Error<InvalidFrom> {};
struct InvalidNamespace : ErrorImpl<InvalidNamespace> {}; struct InvalidNamespace : impl::Error<InvalidNamespace> {};
struct InvalidXml : ErrorImpl<InvalidXml> {}; struct InvalidXml : impl::Error<InvalidXml> {};
struct NotAuthorized : ErrorImpl<NotAuthorized> {}; struct NotAuthorized : impl::Error<NotAuthorized> {};
struct NotWellFormed : ErrorImpl<NotWellFormed> {}; struct NotWellFormed : impl::Error<NotWellFormed> {};
struct PolicyViolation : ErrorImpl<PolicyViolation> {}; struct PolicyViolation : impl::Error<PolicyViolation> {};
struct RemoteConnectionFailed : ErrorImpl<RemoteConnectionFailed> {}; struct RemoteConnectionFailed : impl::Error<RemoteConnectionFailed> {};
struct Reset : ErrorImpl<Reset> {}; struct Reset : impl::Error<Reset> {};
struct ResourceConstraint : ErrorImpl<ResourceConstraint> {}; struct ResourceConstraint : impl::Error<ResourceConstraint> {};
struct RestrictedXml : ErrorImpl<RestrictedXml> {}; struct RestrictedXml : impl::Error<RestrictedXml> {};
struct SeeOtherHost : ErrorImpl<SeeOtherHost> {}; struct SeeOtherHost : impl::Error<SeeOtherHost> {};
struct SystemShutdown : ErrorImpl<SystemShutdown> {}; struct SystemShutdown : impl::Error<SystemShutdown> {};
struct UndefinedCondition : ErrorImpl<UndefinedCondition> {}; struct UndefinedCondition : impl::Error<UndefinedCondition> {};
struct UnsupportedEncoding : ErrorImpl<UnsupportedEncoding> {}; struct UnsupportedEncoding : impl::Error<UnsupportedEncoding> {};
struct UnsupportedFeature : ErrorImpl<UnsupportedFeature> {}; struct UnsupportedFeature : impl::Error<UnsupportedFeature> {};
struct UnsupportedStanzaType : ErrorImpl<UnsupportedStanzaType> {}; struct UnsupportedStanzaType : impl::Error<UnsupportedStanzaType> {};
struct UnsupportedVersion : ErrorImpl<UnsupportedVersion> {}; struct UnsupportedVersion : impl::Error<UnsupportedVersion> {};
} // namespace error::stream } // namespace error::stream