OZO 「お象」
Boost.Asio and libpq based asynchronous PostgreSQL unofficial header-only C++17 client library.
size_of.h
1 #pragma once
2 
3 #include <ozo/type_traits.h>
4 
22 namespace ozo {
23 
53 template <typename T, typename = std::void_t<>>
54 struct size_of_impl;
55 
56 namespace detail {
57 
58 template <typename T, typename = std::void_t<>>
59 struct size_of_default_impl {
60  static constexpr auto apply(const T&) noexcept {
61  return typename type_traits<T>::size{};
62  }
63 };
64 
65 template <typename T>
66 struct size_of_default_impl<T, Require<DynamicSize<T>>> {
67  static constexpr auto apply(const T& v) noexcept(noexcept(std::size(v))){
68  return std::size(v) * sizeof(decltype(*std::begin(v)));
69  }
70 };
71 
72 template <typename T, typename = std::void_t<>>
73 struct size_of_impl_dispatcher { using type = size_of_impl<std::decay_t<T>>; };
74 
75 template <typename T, typename Tag>
76 struct size_of_impl_dispatcher<strong_typedef_wrapper<T, Tag>> { using type = size_of_impl<std::decay_t<T>>; };
77 
78 template <typename T>
79 using get_size_of_impl = typename size_of_impl_dispatcher<unwrap_type<T>>::type;
80 
81 } // namespace detail
82 
104 template <typename T>
105 constexpr size_type size_of(const T& v) {
106  static_assert(HasDefinition<T>, "the type has not been defined with PostgreSQL type traits");
107  return ozo::is_null(v) ? null_state_size : detail::get_size_of_impl<T>::apply(ozo::unwrap(v));
108 }
109 
110 template <typename T, typename>
111 struct size_of_impl : detail::size_of_default_impl<T> {};
112 
126 template <typename T>
127 constexpr size_type data_frame_size(const T& v) {
128  return sizeof(ozo::size_type) + std::max(size_of(v), 0);
129 }
130 
145 template <typename T>
146 constexpr size_type frame_size(const T& v) {
147  return sizeof(ozo::oid_t) + data_frame_size(v);
148 }
149 
150 } // namespace ozo
ozo::unwrap
constexpr decltype(auto) unwrap(T &&v) noexcept(noexcept(unwrap_impl< std::decay_t< T >>::apply(std::forward< T >(v))))
Unwraps argument underlying value or forwards the argument.
Definition: unwrap.h:57
HasDefinition
Condition indicates if type has corresponding type traits for PostgreSQL.
ozo::size_of
constexpr size_type size_of(const T &v)
Returns size of object binary representation in bytes.
Definition: size_of.h:105
ozo::frame_size
constexpr size_type frame_size(const T &v)
Returns size of full IO frame.
Definition: size_of.h:146
ozo::DynamicSize
constexpr auto DynamicSize
Condition indicates if the specified type is has dynamic size.
Definition: type_traits.h:318
ozo::size_of_impl
ozo::size_of implementation functor
Definition: size_of.h:54
ozo::Require
Type Require
Concept requirement emulation.
Definition: concept.h:54
ozo::type_traits
Type traits template forward declaration.
Definition: type_traits.h:208
ozo::size_type
std::int32_t size_type
PostgreSQL size type.
Definition: type_traits.h:265
ozo::begin
decltype(auto) begin(ConnectionProvider &&provider, TimeConstraint time_constraint, CompletionToken &&token)
Start new transaction.
ozo::is_null
constexpr decltype(auto) is_null(const T &v) noexcept(noexcept(is_null_impl< T >::apply(v)))
Indicates if value is in null state.
Definition: nullable.h:85
ozo::oid_t
::Oid oid_t
PostgreSQL OID type - object identifier.
Definition: type_traits.h:70
ozo::data_frame_size
constexpr size_type data_frame_size(const T &v)
Returns size of IO data frame.
Definition: size_of.h:127