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,
15 USERVER_NAMESPACE::utils::void_t<decltype(T::init_)>>
16 : std::true_type {};
17
18template <typename T>
19struct BufferParserBase {
20 using ValueType = T;
21
22 ValueType& value;
23 explicit BufferParserBase(ValueType& v) : value{v} {
24 using PgMapping = CppToPg<ValueType>;
25 if constexpr (ShouldInitMapping<PgMapping>{}) {
26 ForceReference(PgMapping::init_);
27 }
28 }
29};
30
31template <typename T>
32struct BufferParserBase<T&&> {
33 using ValueType = T;
34
35 ValueType value;
36 explicit BufferParserBase(ValueType&& v) : value{std::move(v)} {
37 using PgMapping = CppToPg<ValueType>;
38 if constexpr (ShouldInitMapping<PgMapping>{}) {
39 ForceReference(PgMapping::init_);
40 }
41 }
42};
43
44template <typename T>
45struct BufferFormatterBase {
46 using ValueType = T;
47 const ValueType& value;
48 explicit BufferFormatterBase(const ValueType& v) : value{v} {}
49};
50
51} // namespace storages::postgres::io::detail
52
53USERVER_NAMESPACE_END