10#include <userver/storages/postgres/exceptions.hpp>
11#include <userver/storages/postgres/io/buffer_io.hpp>
12#include <userver/storages/postgres/io/buffer_io_base.hpp>
13#include <userver/storages/postgres/io/type_mapping.hpp>
15#include <userver/utils/flags.hpp>
17USERVER_NAMESPACE_BEGIN
23template <
typename BitContainer>
26template <
typename Enum>
29template <std::size_t N>
32template <std::size_t N>
36inline constexpr bool kIsBitStringCompatible = IsBitStringCompatible<T>::value;
38template <
typename BitContainer,
typename Enable =
void>
39struct BitContainerTraits;
51 static_assert(
N > 0,
"Length for bit container must be at least 1");
61 static_assert(
N > 0,
"Length for bit container must be at least 1");
71enum class BitStringType { kBit, kBitVarying };
75enum class BitContainerInterface { kCommon, kFlags };
77template <
typename BitContainerRef, BitContainerInterface, BitStringType>
78struct BitStringRefWrapper {
79 static_assert(std::is_reference<BitContainerRef>::value,
"The container must be passed by reference");
81 using BitContainer = std::decay_t<BitContainerRef>;
83 io::traits::kIsBitStringCompatible<BitContainer>,
84 "This C++ type cannot be used with PostgreSQL 'bit' and 'bit "
93template <
typename BitContainer, BitStringType>
95 static_assert(!std::is_reference<BitContainer>::value,
"The container must not be passed by reference");
98 io::
traits::kIsBitStringCompatible<BitContainer>,
99 "This C++ type cannot be used with PostgreSQL 'bit' and 'bit "
106template <BitStringType kBitStringType,
typename BitContainer>
107constexpr detail::BitStringRefWrapper<
const BitContainer&, detail::BitContainerInterface::kCommon, kBitStringType>
108BitString(
const BitContainer& bits) {
112template <BitStringType kBitStringType,
typename BitContainer>
113constexpr detail::BitStringRefWrapper<BitContainer&, detail::BitContainerInterface::kCommon, kBitStringType> BitString(
119template <BitStringType kBitStringType,
typename Enum>
120constexpr detail::BitStringRefWrapper<
121 const USERVER_NAMESPACE::
utils::Flags<Enum>&,
122 detail::BitContainerInterface::kFlags,
124BitString(
const USERVER_NAMESPACE::
utils::Flags<Enum>& bits) {
128template <BitStringType kBitStringType,
typename Enum>
130 BitStringRefWrapper<USERVER_NAMESPACE::
utils::Flags<Enum>&, detail::BitContainerInterface::kFlags, kBitStringType>
131 BitString(USERVER_NAMESPACE::
utils::Flags<Enum>& bits) {
135template <
typename BitContainer>
136constexpr auto Varbit(BitContainer&& bits) {
137 return BitString<BitStringType::kBitVarying>(std::forward<BitContainer>(bits));
140template <
typename BitContainer>
141constexpr auto Bit(BitContainer&& bits) {
142 return BitString<BitStringType::kBit>(std::forward<BitContainer>(bits));
233 template <
typename Buffer>
267 template <
typename Buffer>
279 template <
typename Buffer>
293 template <
typename Buffer>
299template <
typename BitContainer,
postgres::detail::BitContainerInterface kContainerInterface>
301 postgres::detail::BitStringRefWrapper<BitContainer, kContainerInterface,
postgres::BitStringType::kBitVarying>>
302 : PredefinedOid<PredefinedOids::kVarbit> {};
303template <
typename BitContainer>
305 : PredefinedOid<PredefinedOids::kVarbit> {};
307template <
typename BitContainer,
postgres::detail::BitContainerInterface kContainerInterface>
309 postgres::detail::BitStringRefWrapper<BitContainer, kContainerInterface,
postgres::BitStringType::kBit>>
310 : PredefinedOid<PredefinedOids::kBit> {};
311template <
typename BitContainer>
313 : PredefinedOid<PredefinedOids::kBit> {};
315template <std::size_t N>
316struct CppToSystemPg<std::bitset<N>> : PredefinedOid<PredefinedOids::kVarbit> {};