14#if !defined(PQXX_HEADER_PRE)
15# error "Include libpqxx headers as <pqxx/header>, not <pqxx/header.hxx>."
35#include "pqxx/except.hxx"
36#include "pqxx/types.hxx"
37#include "pqxx/version.hxx"
44#include <pqxx/internal/libpq-forward.hxx>
48#if pqxx_have_unreachable
50# define PQXX_UNREACHABLE std::unreachable()
52# define PQXX_UNREACHABLE assert(false)
62template<
typename LEFT,
typename RIGHT>
63inline constexpr bool cmp_less(LEFT lhs, RIGHT rhs)
noexcept
65#if defined(PQXX_HAVE_CMP)
66 return std::cmp_less(lhs, rhs);
71 constexpr bool left_signed{std::is_signed_v<LEFT>};
72 if constexpr (left_signed == std::is_signed_v<RIGHT>)
74 else if constexpr (std::is_signed_v<LEFT>)
75 return (lhs <= 0) ? true : (std::make_unsigned_t<LEFT>(lhs) < rhs);
77 return (rhs <= 0) ? false : (lhs < std::make_unsigned_t<RIGHT>(rhs));
84template<
typename LEFT,
typename RIGHT>
85inline constexpr bool cmp_greater(LEFT lhs, RIGHT rhs)
noexcept
87#if defined(PQXX_HAVE_CMP)
88 return std::cmp_greater(lhs, rhs);
97template<
typename LEFT,
typename RIGHT>
100#if defined(PQXX_HAVE_CMP)
101 return std::cmp_less_equal(lhs, rhs);
110template<
typename LEFT,
typename RIGHT>
113#if defined(PQXX_HAVE_CMP)
114 return std::cmp_greater_equal(lhs, rhs);
125[[nodiscard]]
inline std::string
cat2(std::string_view x, std::string_view y)
128 auto const xs{std::size(x)}, ys{std::size(y)};
130 x.copy(std::data(buf), xs);
131 y.copy(std::data(buf) + xs, ys);
139using namespace std::literals;
142template<
typename... T>
inline constexpr void ignore_unused(T &&...) noexcept
150template<
typename TO,
typename FROM>
151inline TO
check_cast(FROM value, std::string_view description)
153 static_assert(std::is_arithmetic_v<FROM>);
154 static_assert(std::is_arithmetic_v<TO>);
155 static_assert(std::is_integral_v<FROM> == std::is_integral_v<TO>);
159 if constexpr (std::is_same_v<FROM, bool>)
160 return static_cast<TO
>(value);
166 using from_limits = std::numeric_limits<
decltype(value)>;
167 using to_limits = std::numeric_limits<TO>;
168 if constexpr (std::is_signed_v<FROM>)
170 if constexpr (std::is_signed_v<TO>)
172 if (value < to_limits::lowest())
182 "Casting negative value to unsigned type: "sv, description)};
191 if constexpr (std::is_integral_v<FROM>)
193 using unsigned_from = std::make_unsigned_t<FROM>;
194 using unsigned_to = std::make_unsigned_t<TO>;
195 constexpr auto from_max{
static_cast<unsigned_from
>((from_limits::max)())};
196 constexpr auto to_max{
static_cast<unsigned_to
>((to_limits::max)())};
197 if constexpr (from_max > to_max)
203 else if constexpr ((from_limits::max)() > (to_limits::max)())
205 if (value > (to_limits::max)())
209 return static_cast<TO
>(value);
257 bool safe_libpq =
false;
266 bool safe_kerberos =
false;
277#if defined(PQXX_HAVE_CONCEPTS)
278# define PQXX_POTENTIAL_BINARY_ARG pqxx::potential_binary
280# define PQXX_POTENTIAL_BINARY_ARG typename
302template<PQXX_POTENTIAL_BINARY_ARG TYPE>
308 reinterpret_cast<std::byte
const *
>(
309 const_cast<strip_t<decltype(*std::data(data))
> const *>(
315#if defined(PQXX_HAVE_CONCEPTS)
316template<
typename CHAR>
317concept char_sized = (
sizeof(CHAR) == 1);
318# define PQXX_CHAR_SIZED_ARG char_sized
320# define PQXX_CHAR_SIZED_ARG typename
331template<PQXX_CHAR_SIZED_ARG CHAR,
typename SIZE>
332std::basic_string_view<std::byte>
binary_cast(CHAR
const *data, SIZE size)
334 static_assert(
sizeof(CHAR) == 1);
336 reinterpret_cast<std::byte
const *
>(data),
337 check_cast<std::size_t>(size,
"binary data size")};
358using namespace std::literals;
366template<
typename CHAR>
inline constexpr bool is_digit(CHAR c)
noexcept
368 return (c >=
'0') and (c <=
'9');
375[[nodiscard]] std::string
392 void const *old_guest, std::string_view old_class, std::string_view old_name,
393 void const *new_guest, std::string_view new_class,
394 std::string_view new_name);
402 void const *old_guest, std::string_view old_class, std::string_view old_name,
403 void const *new_guest, std::string_view new_class,
404 std::string_view new_name);
411inline constexpr std::size_t
size_esc_bin(std::size_t binary_bytes)
noexcept
413 return 2 + (2 * binary_bytes) + 1;
422 return (escaped_bytes - 2) / 2;
434esc_bin(std::basic_string_view<std::byte> binary_data,
char buffer[])
noexcept;
438std::string PQXX_LIBEXPORT
439esc_bin(std::basic_string_view<std::byte> binary_data);
444unesc_bin(std::string_view escaped_data, std::byte buffer[]);
448std::basic_string<std::byte>
449 PQXX_LIBEXPORT
unesc_bin(std::string_view escaped_data);
453template<
typename T>
auto ssize(T
const &c)
456 return std::ssize(c);
458 using signed_t = std::make_signed_t<
decltype(std::size(c))>;
459 return static_cast<signed_t
>(std::size(c));
469template<
typename RETURN,
typename... ARGS>
470std::tuple<ARGS...>
args_f(RETURN (&func)(ARGS...));
478template<
typename RETURN,
typename... ARGS>
479std::tuple<ARGS...>
args_f(std::function<RETURN(ARGS...)>
const &);
487template<
typename CLASS,
typename RETURN,
typename... ARGS>
496template<
typename CLASS,
typename RETURN,
typename... ARGS>
497std::tuple<ARGS...>
member_args_f(RETURN (CLASS::*)(ARGS...) const);
507template<
typename CALLABLE>
513template<
typename CALLABLE>
521template<
typename... TYPES>
522std::tuple<strip_t<TYPES>...>
strip_types(std::tuple<TYPES...>
const &);
526template<
typename... TYPES>
536 PQXX_UNLIKELY
return '\b';
538 PQXX_UNLIKELY
return '\f';
556template<std::
size_t BYTES>
563#if defined(PQXX_HAVE_STERROR_S) || defined(PQXX_HAVE_STRERROR_R)
564# if defined(PQXX_HAVE_STRERROR_S)
565 auto const err_result{strerror_s(std::data(buffer), BYTES, err_num)};
567 auto const err_result{strerror_r(err_num, std::data(buffer), BYTES)};
569 if constexpr (std::is_same_v<
pqxx::strip_t<
decltype(err_result)>,
char *>)
581 return std::data(buffer);
583 return "Compound errors.";
589 return "(No error information available.)";
598PQXX_LIBEXPORT
void pqfreemem(
void const *)
noexcept;
The home of all libpqxx classes, functions, templates, etc.
Definition array.hxx:33
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
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:303
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:234
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:142
constexpr oid oid_none
The "null" oid.
Definition util.hxx:342
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:151
Internal items for libpqxx' own use. Do not use these yourself.
Definition composite.hxx:84
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
char const *PQXX_COLD error_string(int err_num, std::array< char, BYTES > &buffer)
Get error string for a given errno value.
Definition util.hxx:558
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:411
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:63
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:527
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::tuple< strip_t< TYPES >... > strip_types(std::tuple< TYPES... > const &)
Helper: Apply strip_t to each of a tuple type's component types.
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
std::tuple< ARGS... > args_f(RETURN(&func)(ARGS...))
Helper for determining a function's parameter types.
constexpr bool cmp_greater(LEFT lhs, RIGHT rhs) noexcept
C++20 std::cmp_greater, or workaround if not available.
Definition util.hxx:85
decltype(args_f(std::declval< CALLABLE >())) args_t
A callable's parameter types, as a tuple.
Definition util.hxx:514
constexpr bool is_digit(CHAR c) noexcept
A safer and more generic replacement for std::isdigit.
Definition util.hxx:366
constexpr char unescape_char(char escaped) noexcept
Return original byte for escaped character.
Definition util.hxx:531
constexpr bool cmp_greater_equal(LEFT lhs, RIGHT rhs) noexcept
C++20 std::cmp_greater_equal, or workaround if not available.
Definition util.hxx:111
std::string cat2(std::string_view x, std::string_view y)
Efficiently concatenate two strings.
Definition util.hxx:125
constexpr bool cmp_less_equal(LEFT lhs, RIGHT rhs) noexcept
C++20 std::cmp_less_equal, or workaround if not available.
Definition util.hxx:98
auto ssize(T const &c)
Transitional: std::ssize(), or custom implementation if not available.
Definition util.hxx:453
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:420
void pqfreemem(void const *) noexcept
Wrapper for PQfreemem(), with C++ linkage.
Definition util.cxx:199
Something is out of range, similar to std::out_of_range.
Definition except.hxx:326
Descriptor of library's thread-safety model.
Definition util.hxx:255
std::string description
A human-readable description of any thread-safety issues.
Definition util.hxx:269