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;
220 explicit namedclass(std::string_view classname) : m_classname{classname} {}
222 namedclass(std::string_view classname, std::string_view name) :
223 m_classname{classname}, m_name{name}
227 m_classname{classname}, m_name{name}
231 m_classname{classname}, m_name{std::move(name)}
235 std::string
const &
name() const noexcept {
return m_name; }
238 std::string
const &
classname() const noexcept {
return m_classname; }
241 std::string description()
const;
244 std::string m_classname, m_name;
249 namedclass
const *new_ptr, namedclass
const *old_ptr);
251 namedclass
const *new_ptr, namedclass
const *old_ptr);
261 constexpr
unique() =
default;
265 rhs.m_guest =
nullptr;
270 m_guest = rhs.m_guest;
271 rhs.m_guest =
nullptr;
275 constexpr GUEST *
get()
const noexcept {
return m_guest; }
290 GUEST *m_guest =
nullptr;
300 return 2 + (2 * binary_bytes) + 1;
309 return (escaped_bytes - 2) / 2;
320 esc_bin(std::string_view binary_data,
char buffer[]) noexcept;
324 std::string PQXX_LIBEXPORT
esc_bin(std::string_view binary_data);
329 unesc_bin(std::string_view escaped_data, std::byte buffer[]);
333 std::string PQXX_LIBEXPORT
unesc_bin(std::string_view escaped_data);
336 #include "pqxx/internal/compiler-internal-post.hxx" Descriptor of library's thread-safety model.
Definition: util.hxx:164
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:230
Ensure proper opening/closing of GUEST objects related to a "host" object.
Definition: util.hxx:258
std::string const & classname() const noexcept
Class name.
Definition: util.hxx:238
namedclass(std::string_view classname)
Definition: util.hxx:220
void esc_bin(std::string_view binary_data, char buffer[]) noexcept
Hex-escape binary data into a buffer.
Definition: util.cxx:123
constexpr void unregister_guest(GUEST *G)
Definition: util.hxx:283
namedclass(std::string_view classname, char const name[])
Definition: util.hxx:226
void check_unique_unregistration(namedclass const *new_ptr, namedclass const *old_ptr)
Definition: util.cxx:76
constexpr unique(unique &&rhs)
Definition: util.hxx:263
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
void check_unique_registration(namedclass const *new_ptr, namedclass const *old_ptr)
Definition: util.cxx:60
thread_safety_model describe_thread_safety()
Describe thread safety available in this build.
Definition: util.cxx:26
namedclass(std::string_view classname, std::string_view name)
Definition: util.hxx:222
void check_version()
Definition: util.hxx:144
Private namespace for libpqxx's internal use; do not access.
Definition: composite.hxx:70
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()=default
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:307
std::string const & name() const noexcept
Object name, or the empty string if no name was given.
Definition: util.hxx:235
constexpr oid oid_none
The "null" oid.
Definition: util.hxx:188
void ignore_unused(T &&...)
Suppress compiler warning about an unused item.
Definition: util.hxx:45
int PQXX_VERSION_CHECK() noexcept
Library version check stub.
Definition: version.cxx:18
constexpr unique & operator=(unique const &)=delete
Helper base class: object descriptions for error messages and such.
Definition: util.hxx:217
constexpr void register_guest(GUEST *G)
Definition: util.hxx:277
Something is out of range, similar to std::out_of_range.
Definition: except.hxx:192
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:25
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:298
constexpr unique & operator=(unique &&rhs)
Definition: util.hxx:268
void unesc_bin(std::string_view escaped_data, std::byte buffer[])
Reconstitute binary data from its escaped version.
Definition: util.cxx:153