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);
116 template<
typename TYPE>
117 using strip_t = std::remove_cv_t<std::remove_reference_t<TYPE>>;
164 bool safe_libpq =
false;
173 bool safe_kerberos =
false;
217 explicit namedclass(std::string_view classname) : m_classname{classname} {}
219 namedclass(std::string_view classname, std::string_view name) :
220 m_classname{classname},
225 m_classname{classname},
230 m_classname{classname},
231 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;
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; }
279 check_unique_registration(G, m_guest);
285 check_unique_unregistration(G, m_guest);
290 GUEST *m_guest =
nullptr;
294 #include "pqxx/internal/compiler-internal-post.hxx" Something is out of range, similar to std::out_of_range.
Definition: except.hxx:192
Private namespace for libpqxx's internal use; do not access.
Definition: connection.hxx:60
namedclass(std::string_view classname)
Definition: util.hxx:217
constexpr void register_guest(GUEST *G)
Definition: util.hxx:277
void check_unique_unregistration(namedclass const *new_ptr, namedclass const *old_ptr)
Definition: util.cxx:75
constexpr unique & operator=(unique &&rhs)
Definition: util.hxx:268
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:224
std::remove_cv_t< std::remove_reference_t< TYPE > > strip_t
Remove any constness, volatile, and reference-ness from a type.
Definition: util.hxx:117
std::string const & name() const noexcept
Object name, or the empty string if no name was given.
Definition: util.hxx:235
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:25
constexpr oid oid_none
The "null" oid.
Definition: util.hxx:185
Helper base class: object descriptions for error messages and such.
Definition: util.hxx:214
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:219
thread_safety_model describe_thread_safety()
Describe thread safety available in this build.
Definition: util.cxx:26
constexpr unique(unique &&rhs)
Definition: util.hxx:263
std::string description
A human-readable description of any thread-safety issues.
Definition: util.hxx:176
int PQXX_VERSION_CHECK() noexcept
Library version check stub.
Definition: version.cxx:18
void check_version()
Definition: util.hxx:141
Descriptor of library's thread-safety model.
Definition: util.hxx:161
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:238
Ensure proper opening/closing of GUEST objects related to a "host" object.
Definition: util.hxx:258
constexpr void unregister_guest(GUEST *G)
Definition: util.hxx:283