Use PublicCast from utempl instead custom implementation

This commit is contained in:
sha512sum 2024-10-20 00:09:14 +00:00
parent cfd566d52a
commit efba236215
3 changed files with 9 additions and 40 deletions

View file

@ -176,13 +176,13 @@ target_include_directories(larra_xmpp PUBLIC
if(TARGET Boost::pfr) if(TARGET Boost::pfr)
target_link_libraries(larra_xmpp PUBLIC target_link_libraries(larra_xmpp PUBLIC
Boost::asio Boost::serialization utempl::utempl pugixml::pugixml Boost::asio Boost::serialization utempl::utempl pugixml::pugixml
OpenSSL::SSL nameof::nameof OpenSSL::SSL nameof::nameof fmt::fmt
OpenSSL::Crypto spdlog xmlplusplus ${LIBXML2_LIBRARIES}) OpenSSL::Crypto spdlog xmlplusplus ${LIBXML2_LIBRARIES})
else() else()
find_package(Boost 1.85.0 COMPONENTS serialization REQUIRED) find_package(Boost 1.85.0 COMPONENTS serialization REQUIRED)
target_link_libraries(larra_xmpp PUBLIC target_link_libraries(larra_xmpp PUBLIC
utempl::utempl ${Boost_LIBRARIES} pugixml::pugixml OpenSSL::SSL utempl::utempl ${Boost_LIBRARIES} pugixml::pugixml OpenSSL::SSL
nameof::nameof nameof::nameof fmt::fmt
OpenSSL::Crypto spdlog xmlplusplus ${LIBXML2_LIBRARIES}) OpenSSL::Crypto spdlog xmlplusplus ${LIBXML2_LIBRARIES})
endif() endif()

View file

@ -1,34 +0,0 @@
#pragma once
#include <cstddef>
#include <type_traits>
namespace larra::xmpp::impl {
template <typename T, std::size_t I = 0>
struct PublicCastTag {
friend constexpr auto MagicGetPrivateMember(PublicCastTag);
};
template <auto ptr, std::size_t I = 0>
struct PublicCast {};
template <typename T, typename R, R T::*ptr, std::size_t I>
struct PublicCast<ptr, I> {
friend constexpr auto MagicGetPrivateMember(PublicCastTag<T, I>) {
return ptr;
}
};
template <typename T, typename R, typename... Args, R (T::*ptr)(Args...), std::size_t I>
struct PublicCast<ptr, I> {
friend constexpr auto MagicGetPrivateMember(PublicCastTag<T, I>) {
return ptr;
}
};
template <typename T, std::size_t I = 0>
constexpr auto GetPrivateMember(const T&) {
return MagicGetPrivateMember(PublicCastTag<std::decay_t<T>, I>{});
};
} // namespace larra::xmpp::impl

View file

@ -1,20 +1,23 @@
#include <libxml/parser.h> #include <libxml/parser.h>
#include <larra/impl/public_cast.hpp>
#include <larra/utils.hpp> #include <larra/utils.hpp>
#include <larra/xml_stream.hpp> #include <larra/xml_stream.hpp>
#include <ranges> #include <ranges>
#include <span> #include <utempl/public_cast.hpp>
namespace larra::xmpp::impl { namespace utempl {
template struct PublicCast<&xmlpp::SaxParser::sax_handler_>; template struct PublicCast<&xmlpp::SaxParser::sax_handler_>;
}
namespace larra::xmpp::impl {
auto Parser::ParseChunk(std::string_view str) -> const xmlError* { auto Parser::ParseChunk(std::string_view str) -> const xmlError* {
xmlResetLastError(); xmlResetLastError();
if(!context_) { if(!context_) {
this->context_ = xmlCreatePushParserCtxt((this->*GetPrivateMember(static_cast<xmlpp::SaxParser&>(*this))).get(), this->context_ = xmlCreatePushParserCtxt((this->*utempl::GetPrivateMember<"sax_handler_">(static_cast<xmlpp::SaxParser&>(*this))).get(),
nullptr, // user_data nullptr, // user_data
nullptr, // chunk nullptr, // chunk
0, // size 0, // size