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/types.hxx" 31 #include "pqxx/version.hxx" 38 #include <pqxx/internal/libpq-forward.hxx> 51 template<
typename TO,
typename FROM>
52 inline TO
check_cast(FROM value,
char const description[])
54 static_assert(std::is_arithmetic_v<FROM>);
55 static_assert(std::is_arithmetic_v<TO>);
56 static_assert(std::is_integral_v<FROM> == std::is_integral_v<TO>);
60 if constexpr (std::is_same_v<FROM, bool>)
61 return static_cast<TO
>(value);
67 using from_limits = std::numeric_limits<decltype(value)>;
68 using to_limits = std::numeric_limits<TO>;
69 if constexpr (std::is_signed_v<FROM>)
71 if constexpr (std::is_signed_v<TO>)
73 if (value < (to_limits::min)())
74 throw range_error(std::string{
"Cast underflow: "} + description);
83 std::string{
"Casting negative value to unsigned type: "} +
93 if constexpr (std::is_integral_v<FROM>)
95 using unsigned_from = std::make_unsigned_t<FROM>;
96 using unsigned_to = std::make_unsigned_t<TO>;
97 constexpr
auto from_max{
static_cast<unsigned_from
>((from_limits::max)())};
98 constexpr
auto to_max{
static_cast<unsigned_to
>((to_limits::max)())};
99 if constexpr (from_max > to_max)
101 if (static_cast<unsigned_from>(value) > to_max)
102 throw range_error(std::string{
"Cast overflow: "} + description);
105 else if constexpr ((from_limits::max)() > (to_limits::max)())
107 if (value > (to_limits::max)())
108 throw range_error(std::string{
"Cast overflow: "} + description);
111 return static_cast<TO
>(value);
118 template<
typename TYPE>
119 using strip_t = std::remove_cv_t<std::remove_reference_t<TYPE>>;
166 bool safe_libpq =
false;
175 bool safe_kerberos =
false;
219 explicit namedclass(std::string_view classname) : m_classname{classname} {}
221 namedclass(std::string_view classname, std::string_view name) :
222 m_classname{classname}, m_name{name}
226 m_classname{classname}, m_name{name}
230 m_classname{classname}, m_name{std::move(name)}
234 std::string
const &
name() const noexcept {
return m_name; }
237 std::string
const &
classname() const noexcept {
return m_classname; }
240 std::string description()
const;
243 std::string m_classname, m_name;
260 constexpr
unique() =
default;
264 rhs.m_guest =
nullptr;
269 m_guest = rhs.m_guest;
270 rhs.m_guest =
nullptr;
274 constexpr GUEST *
get()
const noexcept {
return m_guest; }
278 check_unique_registration(G, m_guest);
284 check_unique_unregistration(G, m_guest);
289 GUEST *m_guest =
nullptr;
293 #include "pqxx/internal/compiler-internal-post.hxx" Something is out of range, similar to std::out_of_range.
Definition: except.hxx:193
Private namespace for libpqxx's internal use; do not access.
Definition: connection.hxx:60
namedclass(std::string_view classname)
Definition: util.hxx:219
constexpr void register_guest(GUEST *G)
Definition: util.hxx:276
void check_unique_unregistration(namedclass const *new_ptr, namedclass const *old_ptr)
Definition: util.cxx:76
constexpr unique & operator=(unique &&rhs)
Definition: util.hxx:267
namedclass(std::string_view classname, std::string &&name)
Definition: util.hxx:229
TO check_cast(FROM value, char const description[])
Cast a numeric value to another type, or throw if it underflows/overflows.
Definition: util.hxx:52
namedclass(std::string_view classname, char const name[])
Definition: util.hxx:225
std::remove_cv_t< std::remove_reference_t< TYPE > > strip_t
Remove any constness, volatile, and reference-ness from a type.
Definition: util.hxx:119
std::string const & name() const noexcept
Object name, or the empty string if no name was given.
Definition: util.hxx:234
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:25
constexpr oid oid_none
The "null" oid.
Definition: util.hxx:187
Helper base class: object descriptions for error messages and such.
Definition: util.hxx:216
void check_unique_registration(namedclass const *new_ptr, namedclass const *old_ptr)
Definition: util.cxx:60
namedclass(std::string_view classname, std::string_view name)
Definition: util.hxx:221
thread_safety_model describe_thread_safety()
Describe thread safety available in this build.
Definition: util.cxx:26
constexpr unique(unique &&rhs)
Definition: util.hxx:262
std::string description
A human-readable description of any thread-safety issues.
Definition: util.hxx:178
int PQXX_VERSION_CHECK() noexcept
Library version check stub.
Definition: version.cxx:18
void check_version()
Definition: util.hxx:143
Descriptor of library's thread-safety model.
Definition: util.hxx:163
void ignore_unused(T &&...)
Suppress compiler warning about an unused item.
Definition: util.hxx:44
std::string const & classname() const noexcept
Class name.
Definition: util.hxx:237
Ensure proper opening/closing of GUEST objects related to a "host" object.
Definition: util.hxx:257
constexpr void unregister_guest(GUEST *G)
Definition: util.hxx:282