userver: userver/storages/postgres/io/buffer_io_base.hpp Source File
Loading...
Searching...
No Matches
buffer_io_base.hpp
1#pragma once
2
3#include <userver/storages/postgres/io/type_mapping.hpp>
4#include <userver/utils/void_t.hpp>
5
6USERVER_NAMESPACE_BEGIN
7
8namespace storages::postgres::io::detail {
9
10template <typename T, typename = USERVER_NAMESPACE::utils::void_t<>>
11struct ShouldInitMapping : std::false_type {};
12
13template <typename T>
14struct ShouldInitMapping<T, USERVER_NAMESPACE::utils::void_t<decltype(T::init_)>> : std::true_type {};
15
16template <typename T>
17struct BufferParserBase {
18 using ValueType = T;
19
20 ValueType& value;
21 explicit BufferParserBase(ValueType& v) : value{v} {
22 using PgMapping = CppToPg<ValueType>;
23 if constexpr (ShouldInitMapping<PgMapping>{}) {
24 ForceReference(PgMapping::init_);
25 }
26 }
27};
28
29template <typename T>
30struct BufferParserBase<T&&> {
31 using ValueType = T;
32
33 ValueType value;
34 explicit BufferParserBase(ValueType&& v) : value{std::move(v)} {
35 using PgMapping = CppToPg<ValueType>;
36 if constexpr (ShouldInitMapping<PgMapping>{}) {
37 ForceReference(PgMapping::init_);
38 }
39 }
40};
41
42template <typename T>
43struct BufferFormatterBase {
44 using ValueType = T;
45 const ValueType& value;
46 explicit BufferFormatterBase(const ValueType& v) : value{v} {}
47};
48
49} // namespace storages::postgres::io::detail
50
51USERVER_NAMESPACE_END