Boost.Redis: include/boost/redis/adapter/any_adapter.hpp Source File

Boost.Redis 1.84.0 A redis client library

Loading...
Searching...
No Matches
any_adapter.hpp
1/* Copyright (c) 2018-2023 Marcelo Zimbres Silva (mzimbres@gmail.com)
2 *
3 * Distributed under the Boost Software License, Version 1.0. (See
4 * accompanying file LICENSE.txt)
5 */
6
7#ifndef BOOST_REDIS_ANY_ADAPTER_HPP
8#define BOOST_REDIS_ANY_ADAPTER_HPP
9
10
11#include <boost/redis/resp3/node.hpp>
12#include <boost/redis/adapter/adapt.hpp>
13#include <boost/system/error_code.hpp>
14#include <cstddef>
15#include <functional>
16#include <string_view>
17#include <type_traits>
18
19namespace boost::redis {
20
21namespace detail {
22
23// Forward decl
24template <class Executor>
25class basic_connection;
26
27}
28
42 class any_adapter
43{
44 using fn_type = std::function<void(std::size_t, resp3::basic_node<std::string_view> const&, system::error_code&)>;
45
46 struct impl_t {
47 fn_type adapt_fn;
48 std::size_t supported_response_size;
49 } impl_;
50
51 template <class T>
52 static auto create_impl(T& resp) -> impl_t
53 {
54 using namespace boost::redis::adapter;
55 auto adapter = boost_redis_adapt(resp);
56 std::size_t size = adapter.get_supported_response_size();
57 return { std::move(adapter), size };
58 }
59
60 template <class Executor>
61 friend class basic_connection;
62
63public:
74 template <class T, class = std::enable_if_t<!std::is_same_v<T, any_adapter>>>
75 explicit any_adapter(T& resp) : impl_(create_impl(resp)) {}
76};
77
78}
79
80#endif
boost::redis::any_adapter
A type-erased reference to a response.
Definition any_adapter.hpp:43
boost::redis::any_adapter::any_adapter
any_adapter(T &resp)
Constructor.
Definition any_adapter.hpp:75
boost::redis::basic_connection
A SSL connection to the Redis server.
Definition connection.hpp:478
boost::redis::resp3::basic_node
A node in the response tree.
Definition node.hpp:28