14 #if !defined(PQXX_HEADER_PRE)
15 # error "Include libpqxx headers as <pqxx/header>, not <pqxx/header.hxx>."
27 #include <string_view>
28 #include <type_traits>
33 #if __has_include(<version>)
37 #include "pqxx/except.hxx"
38 #include "pqxx/internal/encodings.hxx"
39 #include "pqxx/types.hxx"
40 #include "pqxx/version.hxx"
47 #include <pqxx/internal/libpq-forward.hxx>
51 #if defined(PQXX_HAVE_UNREACHABLE)
53 # define PQXX_UNREACHABLE std::unreachable()
55 # define PQXX_UNREACHABLE assert(false)
65 template<
typename LEFT,
typename RIGHT>
66 inline constexpr
bool cmp_less(LEFT lhs, RIGHT rhs) noexcept
68 #if defined(PQXX_HAVE_CMP)
69 return std::cmp_less(lhs, rhs);
74 constexpr
bool left_signed{std::is_signed_v<LEFT>};
75 if constexpr (left_signed == std::is_signed_v<RIGHT>)
77 else if constexpr (std::is_signed_v<LEFT>)
78 return (lhs <= 0) ? true : (std::make_unsigned_t<LEFT>(lhs) < rhs);
80 return (rhs <= 0) ? false : (lhs < std::make_unsigned_t<RIGHT>(rhs));
87 template<
typename LEFT,
typename RIGHT>
88 inline constexpr
bool cmp_greater(LEFT lhs, RIGHT rhs) noexcept
90 #if defined(PQXX_HAVE_CMP)
91 return std::cmp_greater(lhs, rhs);
100 template<
typename LEFT,
typename RIGHT>
103 #if defined(PQXX_HAVE_CMP)
104 return std::cmp_less_equal(lhs, rhs);
113 template<
typename LEFT,
typename RIGHT>
116 #if defined(PQXX_HAVE_CMP)
117 return std::cmp_greater_equal(lhs, rhs);
128 [[nodiscard]]
inline std::string
cat2(std::string_view x, std::string_view y)
131 auto const xs{std::size(x)}, ys{std::size(y)};
133 x.copy(std::data(buf), xs);
134 y.copy(std::data(buf) + xs, ys);
142 using namespace std::literals;
145 template<
typename... T>
inline constexpr
void ignore_unused(T &&...) noexcept
153 template<
typename TO,
typename FROM>
154 inline TO
check_cast(FROM value, std::string_view description)
156 static_assert(std::is_arithmetic_v<FROM>);
157 static_assert(std::is_arithmetic_v<TO>);
158 static_assert(std::is_integral_v<FROM> == std::is_integral_v<TO>);
162 if constexpr (std::is_same_v<FROM, bool>)
163 return static_cast<TO
>(value);
169 using from_limits = std::numeric_limits<decltype(value)>;
170 using to_limits = std::numeric_limits<TO>;
171 if constexpr (std::is_signed_v<FROM>)
173 if constexpr (std::is_signed_v<TO>)
175 if (value < to_limits::lowest())
185 "Casting negative value to unsigned type: "sv, description)};
194 if constexpr (std::is_integral_v<FROM>)
196 using unsigned_from = std::make_unsigned_t<FROM>;
197 using unsigned_to = std::make_unsigned_t<TO>;
198 constexpr
auto from_max{
static_cast<unsigned_from
>((from_limits::max)())};
199 constexpr
auto to_max{
static_cast<unsigned_to
>((to_limits::max)())};
200 if constexpr (from_max > to_max)
206 else if constexpr ((from_limits::max)() > (to_limits::max)())
208 if (value > (to_limits::max)())
212 return static_cast<TO
>(value);
260 bool safe_libpq =
false;
269 bool safe_kerberos =
false;
280 #if defined(PQXX_HAVE_CONCEPTS)
281 # define PQXX_POTENTIAL_BINARY_ARG pqxx::potential_binary
283 # define PQXX_POTENTIAL_BINARY_ARG typename
305 template<PQXX_POTENTIAL_BINARY_ARG TYPE>
310 reinterpret_cast<std::byte
const *
>(
311 const_cast<strip_t<decltype(*std::data(data))
> const *>(
317 #if defined(PQXX_HAVE_CONCEPTS)
318 template<
typename CHAR>
319 concept char_sized = (
sizeof(CHAR) == 1);
320 # define PQXX_CHAR_SIZED_ARG char_sized
322 # define PQXX_CHAR_SIZED_ARG typename
333 template<PQXX_CHAR_SIZED_ARG CHAR,
typename SIZE>
334 std::basic_string_view<std::byte>
binary_cast(CHAR
const *data, SIZE size)
336 static_assert(
sizeof(CHAR) == 1);
338 reinterpret_cast<std::byte
const *
>(data),
339 check_cast<std::size_t>(size,
"binary data size")};
360 using namespace std::literals;
368 template<
typename CHAR>
inline constexpr
bool is_digit(CHAR c) noexcept
370 return (c >=
'0') and (c <=
'9');
377 [[nodiscard]] std::string
394 void const *old_guest, std::string_view old_class, std::string_view old_name,
395 void const *new_guest, std::string_view new_class,
396 std::string_view new_name);
404 void const *old_guest, std::string_view old_class, std::string_view old_name,
405 void const *new_guest, std::string_view new_class,
406 std::string_view new_name);
413 inline constexpr std::size_t
size_esc_bin(std::size_t binary_bytes) noexcept
415 return 2 + (2 * binary_bytes) + 1;
424 return (escaped_bytes - 2) / 2;
436 esc_bin(std::basic_string_view<std::byte> binary_data,
char buffer[]) noexcept;
440 std::string PQXX_LIBEXPORT
441 esc_bin(std::basic_string_view<std::byte> binary_data);
446 unesc_bin(std::string_view escaped_data, std::byte buffer[]);
450 std::basic_string<std::byte>
451 PQXX_LIBEXPORT
unesc_bin(std::string_view escaped_data);
455 template<
typename T>
auto ssize(T
const &c)
457 #if defined(__cpp_lib_ssize) && __cplusplus >= __cpp_lib_ssize
458 return std::ssize(c);
460 using signed_t = std::make_signed_t<decltype(std::size(c))>;
461 return static_cast<signed_t
>(std::size(c));
471 template<
typename RETURN,
typename... ARGS>
472 std::tuple<ARGS...>
args_f(RETURN (&func)(ARGS...));
480 template<
typename RETURN,
typename... ARGS>
481 std::tuple<ARGS...>
args_f(std::function<RETURN(ARGS...)>
const &);
489 template<
typename CLASS,
typename RETURN,
typename... ARGS>
498 template<
typename CLASS,
typename RETURN,
typename... ARGS>
499 std::tuple<ARGS...>
member_args_f(RETURN (CLASS::*)(ARGS...)
const);
509 template<
typename CALLABLE>
515 template<
typename CALLABLE>
523 template<
typename... TYPES>
524 std::tuple<strip_t<TYPES>...>
strip_types(std::tuple<TYPES...>
const &);
528 template<
typename... TYPES>
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:27
std::remove_cv_t< std::remove_reference_t< TYPE > > strip_t
Remove any constness, volatile, and reference-ness from a type.
Definition: types.hxx:91
strip_t< decltype(*std::begin(std::declval< CONTAINER >()))> value_type
The type of a container's elements.
Definition: types.hxx:107
void check_version() noexcept
Definition: util.hxx:237
thread_safety_model describe_thread_safety()
Describe thread safety available in this build.
Definition: util.cxx:33
constexpr void ignore_unused(T &&...) noexcept
Suppress compiler warning about an unused item.
Definition: util.hxx:145
std::basic_string_view< std::byte > binary_cast(TYPE const &data)
Cast binary data to a type that libpqxx will recognise as binary.
Definition: util.hxx:306
constexpr oid oid_none
The "null" oid.
Definition: util.hxx:344
TO check_cast(FROM value, std::string_view description)
Cast a numeric value to another type, or throw if it underflows/overflows.
Definition: util.hxx:154
Internal items for libpqxx' own use. Do not use these yourself.
Definition: composite.hxx:83
void unesc_bin(std::string_view escaped_data, std::byte buffer[])
Reconstitute binary data from its escaped version.
Definition: util.cxx:158
int PQXX_VERSION_CHECK() noexcept
Library version check stub.
Definition: version.cxx:23
void esc_bin(std::basic_string_view< std::byte > binary_data, char buffer[]) noexcept
Hex-escape binary data into a buffer.
Definition: util.cxx:126
constexpr std::size_t size_esc_bin(std::size_t binary_bytes) noexcept
Compute buffer size needed to escape binary data for use as a BYTEA.
Definition: util.hxx:413
std::tuple< strip_t< TYPES >... > strip_types(std::tuple< TYPES... > const &)
Helper: Apply strip_t to each of a tuple type's component types.
std::tuple< ARGS... > args_f(RETURN(&func)(ARGS...))
Helper for determining a function's parameter types.
std::tuple< ARGS... > member_args_f(RETURN(CLASS::*)(ARGS...))
Helper for determining a member function's parameter types.
constexpr bool cmp_less(LEFT lhs, RIGHT rhs) noexcept
Same as std::cmp_less, or a workaround where that's not available.
Definition: util.hxx:66
void check_unique_unregister(void const *old_guest, std::string_view old_class, std::string_view old_name, void const *new_guest, std::string_view new_class, std::string_view new_name)
Like check_unique_register, but for un-registering a guest.
Definition: util.cxx:78
decltype(strip_types(std::declval< TYPES... >())) strip_types_t
Take a tuple type and apply strip_t to its component types.
Definition: util.hxx:529
void check_unique_register(void const *old_guest, std::string_view old_class, std::string_view old_name, void const *new_guest, std::string_view new_class, std::string_view new_name)
Check validity of registering a new "guest" in a "host.".
Definition: util.cxx:61
std::string describe_object(std::string_view class_name, std::string_view name)
Describe an object for humans, based on class name and optional name.
Definition: util.cxx:51
constexpr bool cmp_greater(LEFT lhs, RIGHT rhs) noexcept
C++20 std::cmp_greater, or workaround if not available.
Definition: util.hxx:88
decltype(args_f(std::declval< CALLABLE >())) args_t
A callable's parameter types, as a tuple.
Definition: util.hxx:516
constexpr bool is_digit(CHAR c) noexcept
A safer and more generic replacement for std::isdigit.
Definition: util.hxx:368
constexpr bool cmp_greater_equal(LEFT lhs, RIGHT rhs) noexcept
C++20 std::cmp_greater_equal, or workaround if not available.
Definition: util.hxx:114
std::string cat2(std::string_view x, std::string_view y)
Efficiently concatenate two strings.
Definition: util.hxx:128
constexpr bool cmp_less_equal(LEFT lhs, RIGHT rhs) noexcept
C++20 std::cmp_less_equal, or workaround if not available.
Definition: util.hxx:101
auto ssize(T const &c)
Transitional: std::ssize(), or custom implementation if not available.
Definition: util.hxx:455
constexpr std::size_t size_unesc_bin(std::size_t escaped_bytes) noexcept
Compute binary size from the size of its escaped version.
Definition: util.hxx:422
Something is out of range, similar to std::out_of_range.
Definition: except.hxx:202
Descriptor of library's thread-safety model.
Definition: util.hxx:258
std::string description
A human-readable description of any thread-safety issues.
Definition: util.hxx:272