14 #include "pqxx/compiler-public.hxx" 15 #include "pqxx/internal/compiler-internal-pre.hxx" 25 #include <string_view> 26 #include <type_traits> 30 #if __has_include(<version>) 34 #include "pqxx/except.hxx" 35 #include "pqxx/internal/encodings.hxx" 36 #include "pqxx/types.hxx" 37 #include "pqxx/version.hxx" 44 #include <pqxx/internal/libpq-forward.hxx> 54 [[nodiscard]]
inline std::string
cat2(std::string_view x, std::string_view y)
57 auto const xs{std::size(x)}, ys{std::size(y)};
59 x.copy(buf.data(), xs);
60 y.copy(buf.data() + xs, ys);
78 template<
typename TO,
typename FROM>
79 inline TO
check_cast(FROM value, std::string_view description)
81 static_assert(std::is_arithmetic_v<FROM>);
82 static_assert(std::is_arithmetic_v<TO>);
83 static_assert(std::is_integral_v<FROM> == std::is_integral_v<TO>);
87 if constexpr (std::is_same_v<FROM, bool>)
88 return static_cast<TO
>(value);
94 using from_limits = std::numeric_limits<decltype(value)>;
95 using to_limits = std::numeric_limits<TO>;
96 if constexpr (std::is_signed_v<FROM>)
98 if constexpr (std::is_signed_v<TO>)
100 if (value < to_limits::lowest())
111 "Casting negative value to unsigned type: "sv, description)};
121 if constexpr (std::is_integral_v<FROM>)
123 using unsigned_from = std::make_unsigned_t<FROM>;
124 using unsigned_to = std::make_unsigned_t<TO>;
125 constexpr
auto from_max{
static_cast<unsigned_from
>((from_limits::max)())};
126 constexpr
auto to_max{
static_cast<unsigned_to
>((to_limits::max)())};
127 if constexpr (from_max > to_max)
129 if (static_cast<unsigned_from>(value) > to_max)
133 else if constexpr ((from_limits::max)() > (to_limits::max)())
135 if (value > (to_limits::max)())
139 return static_cast<TO
>(value);
146 template<
typename TYPE>
147 using strip_t = std::remove_cv_t<std::remove_reference_t<TYPE>>;
194 bool safe_libpq =
false;
203 bool safe_kerberos =
false;
237 [[nodiscard]] std::string
254 void const *old_guest, std::string_view old_class, std::string_view old_name,
255 void const *new_guest, std::string_view new_class,
256 std::string_view new_name);
264 void const *old_guest, std::string_view old_class, std::string_view old_name,
265 void const *new_guest, std::string_view new_class,
266 std::string_view new_name);
275 return 2 + (2 * binary_bytes) + 1;
284 return (escaped_bytes - 2) / 2;
295 esc_bin(std::string_view binary_data,
char buffer[]) noexcept;
299 std::string PQXX_LIBEXPORT
esc_bin(std::string_view binary_data);
304 unesc_bin(std::string_view escaped_data, std::byte buffer[]);
308 std::string PQXX_LIBEXPORT
unesc_bin(std::string_view escaped_data);
312 template<
typename T>
auto ssize(T
const &c)
314 #if defined(__cpp_lib_ssize) && __cplusplus >= __cpp_lib_ssize 315 return std::ssize(c);
317 using signed_t = std::make_signed_t<decltype(std::size(c))>;
318 return static_cast<signed_t
>(std::size(c));
319 #endif // __cpp_lib_ssize 323 #include "pqxx/internal/compiler-internal-post.hxx" constexpr oid oid_none
The "null" oid.
Definition: util.hxx:215
std::remove_cv_t< std::remove_reference_t< TYPE > > strip_t
Remove any constness, volatile, and reference-ness from a type.
Definition: util.hxx:147
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:25
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:58
void check_version()
Definition: util.hxx:171
Something is out of range, similar to std::out_of_range.
Definition: except.hxx:192
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:75
thread_safety_model describe_thread_safety()
Describe thread safety available in this build.
Definition: util.cxx:30
void esc_bin(std::string_view binary_data, char buffer[]) noexcept
Hex-escape binary data into a buffer.
Definition: util.cxx:122
Descriptor of library's thread-safety model.
Definition: util.hxx:191
std::string description
A human-readable description of any thread-safety issues.
Definition: util.hxx:206
auto ssize(T const &c)
Transitional: std::ssize(), or custom implementation if not available.
Definition: util.hxx:312
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:79
std::string cat2(std::string_view x, std::string_view y)
Efficiently concatenate two strings.
Definition: util.hxx:54
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:48
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:273
int PQXX_VERSION_CHECK() noexcept
Library version check stub.
Definition: version.cxx:18
void unesc_bin(std::string_view escaped_data, std::byte buffer[])
Reconstitute binary data from its escaped version.
Definition: util.cxx:152
void ignore_unused(T &&...)
Suppress compiler warning about an unused item.
Definition: util.hxx:71
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:282
Internal items for libpqxx' own use. Do not use these yourself.
Definition: composite.hxx:73