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)
22 : value{v}
23 {
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)
37 : value{std::move(v)}
38 {
39 using PgMapping = CppToPg<ValueType>;
40 if constexpr (ShouldInitMapping<PgMapping>{}) {
41 ForceReference(PgMapping::init);
42 }
43 }
44};
45
46template <typename T>
47struct BufferFormatterBase {
48 using ValueType = T;
49 const ValueType& value;
50 explicit BufferFormatterBase(const ValueType& v)
51 : value{v}
52 {}
53};
54
55} // namespace storages::postgres::io::detail
56
57USERVER_NAMESPACE_END