14 #include "pqxx/compiler-public.hxx" 15 #include "pqxx/internal/compiler-internal-pre.hxx" 25 #include <string_view> 26 #include <type_traits> 30 #include "pqxx/except.hxx" 31 #include "pqxx/internal/encodings.hxx" 32 #include "pqxx/types.hxx" 33 #include "pqxx/version.hxx" 40 #include <pqxx/internal/libpq-forward.hxx> 50 [[nodiscard]]
inline std::string
cat2(std::string_view x, std::string_view y)
53 auto const xs{std::size(x)}, ys{std::size(y)};
55 x.copy(buf.data(), xs);
56 y.copy(buf.data() + xs, ys);
74 template<
typename TO,
typename FROM>
75 inline TO
check_cast(FROM value, std::string_view description)
77 static_assert(std::is_arithmetic_v<FROM>);
78 static_assert(std::is_arithmetic_v<TO>);
79 static_assert(std::is_integral_v<FROM> == std::is_integral_v<TO>);
83 if constexpr (std::is_same_v<FROM, bool>)
84 return static_cast<TO
>(value);
90 using from_limits = std::numeric_limits<decltype(value)>;
91 using to_limits = std::numeric_limits<TO>;
92 if constexpr (std::is_signed_v<FROM>)
94 if constexpr (std::is_signed_v<TO>)
96 if (value < to_limits::lowest())
107 "Casting negative value to unsigned type: "sv, description)};
117 if constexpr (std::is_integral_v<FROM>)
119 using unsigned_from = std::make_unsigned_t<FROM>;
120 using unsigned_to = std::make_unsigned_t<TO>;
121 constexpr
auto from_max{
static_cast<unsigned_from
>((from_limits::max)())};
122 constexpr
auto to_max{
static_cast<unsigned_to
>((to_limits::max)())};
123 if constexpr (from_max > to_max)
125 if (static_cast<unsigned_from>(value) > to_max)
129 else if constexpr ((from_limits::max)() > (to_limits::max)())
131 if (value > (to_limits::max)())
135 return static_cast<TO
>(value);
142 template<
typename TYPE>
143 using strip_t = std::remove_cv_t<std::remove_reference_t<TYPE>>;
190 bool safe_libpq =
false;
199 bool safe_kerberos =
false;
233 [[nodiscard]] std::string
250 void const *old_guest, std::string_view old_class, std::string_view old_name,
251 void const *new_guest, std::string_view new_class,
252 std::string_view new_name);
260 void const *old_guest, std::string_view old_class, std::string_view old_name,
261 void const *new_guest, std::string_view new_class,
262 std::string_view new_name);
271 return 2 + (2 * binary_bytes) + 1;
280 return (escaped_bytes - 2) / 2;
291 esc_bin(std::string_view binary_data,
char buffer[]) noexcept;
295 std::string PQXX_LIBEXPORT
esc_bin(std::string_view binary_data);
300 unesc_bin(std::string_view escaped_data, std::byte buffer[]);
304 std::string PQXX_LIBEXPORT
unesc_bin(std::string_view escaped_data);
307 #include "pqxx/internal/compiler-internal-post.hxx" 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:75
Internal items for libpqxx' own use. Do not use these yourself.
Definition: composite.hxx:73
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
Descriptor of library's thread-safety model.
Definition: util.hxx:187
void esc_bin(std::string_view binary_data, char buffer[]) noexcept
Hex-escape binary data into a buffer.
Definition: util.cxx:122
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
std::remove_cv_t< std::remove_reference_t< TYPE > > strip_t
Remove any constness, volatile, and reference-ness from a type.
Definition: util.hxx:143
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:25
constexpr oid oid_none
The "null" oid.
Definition: util.hxx:211
thread_safety_model describe_thread_safety()
Describe thread safety available in this build.
Definition: util.cxx:30
int PQXX_VERSION_CHECK() noexcept
Library version check stub.
Definition: version.cxx:18
void check_version()
Definition: util.hxx:167
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:278
std::string cat2(std::string_view x, std::string_view y)
Efficiently concatenate two strings.
Definition: util.hxx:50
std::string description
A human-readable description of any thread-safety issues.
Definition: util.hxx:202
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
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:269
void ignore_unused(T &&...)
Suppress compiler warning about an unused item.
Definition: util.hxx:67
Something is out of range, similar to std::out_of_range.
Definition: except.hxx:192
void unesc_bin(std::string_view escaped_data, std::byte buffer[])
Reconstitute binary data from its escaped version.
Definition: util.cxx:152