14 #include "pqxx/compiler-public.hxx" 15 #include "pqxx/internal/compiler-internal-pre.hxx" 24 #include <string_view> 25 #include <type_traits> 29 #include "pqxx/except.hxx" 30 #include "pqxx/internal/encodings.hxx" 31 #include "pqxx/types.hxx" 32 #include "pqxx/version.hxx" 39 #include <pqxx/internal/libpq-forward.hxx> 52 template<
typename TO,
typename FROM>
53 inline TO
check_cast(FROM value,
char const description[])
55 static_assert(std::is_arithmetic_v<FROM>);
56 static_assert(std::is_arithmetic_v<TO>);
57 static_assert(std::is_integral_v<FROM> == std::is_integral_v<TO>);
61 if constexpr (std::is_same_v<FROM, bool>)
62 return static_cast<TO
>(value);
68 using from_limits = std::numeric_limits<decltype(value)>;
69 using to_limits = std::numeric_limits<TO>;
70 if constexpr (std::is_signed_v<FROM>)
72 if constexpr (std::is_signed_v<TO>)
74 if (value < to_limits::lowest())
75 throw range_error(std::string{
"Cast underflow: "} + description);
84 std::string{
"Casting negative value to unsigned type: "} +
94 if constexpr (std::is_integral_v<FROM>)
96 using unsigned_from = std::make_unsigned_t<FROM>;
97 using unsigned_to = std::make_unsigned_t<TO>;
98 constexpr
auto from_max{
static_cast<unsigned_from
>((from_limits::max)())};
99 constexpr
auto to_max{
static_cast<unsigned_to
>((to_limits::max)())};
100 if constexpr (from_max > to_max)
102 if (static_cast<unsigned_from>(value) > to_max)
103 throw range_error(std::string{
"Cast overflow: "} + description);
106 else if constexpr ((from_limits::max)() > (to_limits::max)())
108 if (value > (to_limits::max)())
109 throw range_error(std::string{
"Cast overflow: "} + description);
112 return static_cast<TO
>(value);
119 template<
typename TYPE>
120 using strip_t = std::remove_cv_t<std::remove_reference_t<TYPE>>;
167 bool safe_libpq =
false;
176 bool safe_kerberos =
false;
221 explicit namedclass(std::string_view classname) : m_classname{classname} {}
223 namedclass(std::string_view classname, std::string_view name) :
224 m_classname{classname}, m_name{name}
228 m_classname{classname}, m_name{name}
232 m_classname{classname}, m_name{std::move(name)}
236 std::string
const &
name() const noexcept {
return m_name; }
239 std::string
const &
classname() const noexcept {
return m_classname; }
242 std::string description()
const;
245 std::string m_classname, m_name;
262 constexpr
unique() =
default;
266 rhs.m_guest =
nullptr;
271 m_guest = rhs.m_guest;
272 rhs.m_guest =
nullptr;
276 constexpr GUEST *
get()
const noexcept {
return m_guest; }
280 check_unique_registration(G, m_guest);
286 check_unique_unregistration(G, m_guest);
291 GUEST *m_guest =
nullptr;
301 return 2 + (2 * binary_bytes) + 1;
310 return (escaped_bytes - 2) / 2;
321 esc_bin(std::string_view binary_data,
char buffer[]) noexcept;
325 std::string PQXX_LIBEXPORT
esc_bin(std::string_view binary_data);
330 unesc_bin(std::string_view escaped_data, std::byte buffer[]);
334 std::string PQXX_LIBEXPORT unesc_bin(std::string_view escaped_data);
337 #include "pqxx/internal/compiler-internal-post.hxx" Private namespace for libpqxx's internal use; do not access.
Definition: composite.hxx:70
void check_unique_unregistration(namedclass const *new_ptr, namedclass const *old_ptr)
Definition: util.cxx:88
std::string const & classname() const noexcept
Class name.
Definition: util.hxx:239
void esc_bin(std::string_view binary_data, char buffer[]) noexcept
Hex-escape binary data into a buffer.
Definition: util.cxx:135
namedclass(std::string_view classname, std::string_view name)
Definition: util.hxx:223
TO check_cast(FROM value, char const description[])
Cast a numeric value to another type, or throw if it underflows/overflows.
Definition: util.hxx:53
constexpr unique & operator=(unique &&rhs)
Definition: util.hxx:269
constexpr void register_guest(GUEST *G)
Definition: util.hxx:278
Helper base class: object descriptions for error messages and such.
Definition: util.hxx:218
std::remove_cv_t< std::remove_reference_t< TYPE > > strip_t
Remove any constness, volatile, and reference-ness from a type.
Definition: util.hxx:120
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:25
constexpr oid oid_none
The "null" oid.
Definition: util.hxx:188
namedclass(std::string_view classname)
Definition: util.hxx:221
void check_unique_registration(namedclass const *new_ptr, namedclass const *old_ptr)
Definition: util.cxx:72
namedclass(std::string_view classname, char const name[])
Definition: util.hxx:227
thread_safety_model describe_thread_safety()
Describe thread safety available in this build.
Definition: util.cxx:26
std::string description
A human-readable description of any thread-safety issues.
Definition: util.hxx:179
namedclass(std::string_view classname, std::string &&name)
Definition: util.hxx:231
int PQXX_VERSION_CHECK() noexcept
Library version check stub.
Definition: version.cxx:18
Descriptor of library's thread-safety model.
Definition: util.hxx:164
void check_version()
Definition: util.hxx:144
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:308
constexpr unique(unique &&rhs)
Definition: util.hxx:264
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:299
constexpr void unregister_guest(GUEST *G)
Definition: util.hxx:284
Ensure proper opening/closing of GUEST objects related to a "host" object.
Definition: util.hxx:259
std::string const & name() const noexcept
Object name, or the empty string if no name was given.
Definition: util.hxx:236
void ignore_unused(T &&...)
Suppress compiler warning about an unused item.
Definition: util.hxx:45
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:165