libpqxx
The C++ client library for PostgreSQL
util.hxx File Reference
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cmath>
#include <cstring>
#include <format>
#include <functional>
#include <iterator>
#include <limits>
#include <memory>
#include <stdexcept>
#include <string>
#include <string_view>
#include <type_traits>
#include <typeinfo>
#include <utility>
#include <vector>
#include "pqxx/except.hxx"
#include "pqxx/types.hxx"
#include "pqxx/version.hxx"
#include "pqxx/internal/ignore-deprecated-pre.hxx"
#include "pqxx/internal/ignore-deprecated-post.hxx"
+ Include dependency graph for util.hxx:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  pqxx::thread_safety_model
 Descriptor of library's thread-safety model. More...
 
struct  pqxx::byte_char_traits
 Custom std::char_trast if the compiler does not provide one. More...
 

Namespaces

 pqxx
 The home of all libpqxx classes, functions, templates, etc.
 
 pqxx::internal
 Private namespace for libpqxx's internal use; do not access.
 
 pqxx::internal::pq
 Placeholders for libpq declarations.
 

Macros

#define PQXX_UNREACHABLE   [[unlikely]] while (false)
 

Typedefs

using pqxx::bytes = std::vector< std::byte >
 Type alias for a container containing bytes. More...
 
template<typename CALLABLE >
using pqxx::internal::args_t = decltype(args_f(std::declval< CALLABLE >()))
 A callable's parameter types, as a tuple. More...
 
template<typename... TYPES>
using pqxx::internal::strip_types_t = decltype(strip_types(std::declval< TYPES... >()))
 Take a tuple type and apply std::remove_cvref_t to its component types. More...
 

Functions

template<typename TO , typename FROM >
TO pqxx::check_cast (FROM value, std::string_view description, sl loc=sl::current()) requires(std
 Cast a numeric value to another type, or throw if it underflows/overflows. More...
 
PQXX_LIBEXPORT thread_safety_model pqxx::describe_thread_safety ()
 Describe thread safety available in this build. More...
 
template<potential_binary TYPE>
bytes_view pqxx::binary_cast (TYPE const &data)
 Cast binary data to a type that libpqxx will recognise as binary. More...
 
template<char_sized CHAR, typename SIZE >
bytes_view pqxx::binary_cast (CHAR const *data, SIZE size)
 Construct a type that libpqxx will recognise as binary. More...
 
int pqxx::internal::check_libpqxx_version (int apps_major, int apps_minor, int apps_patch, std::string_view apps_version)
 Check library binary version against application's expectations. More...
 
constexpr PQXX_ZARGS char const * pqxx::internal::as_c_string (char const str[]) noexcept
 Get a raw C string pointer. More...
 
template<std::size_t N>
constexpr char const * pqxx::internal::as_c_string (char(&str)[N]) noexcept
 Get a raw C string pointer. More...
 
template<std::size_t N>
constexpr char const * pqxx::internal::as_c_string (char const (&str)[N]) noexcept
 Get a raw C string pointer. More...
 
constexpr char const * pqxx::internal::as_c_string (std::string const &str) noexcept
 Get a raw C string pointer. More...
 
template<typename CHAR >
constexpr bool pqxx::internal::is_digit (CHAR c) noexcept
 A safer and more generic replacement for std::isdigit. More...
 
std::string pqxx::internal::describe_object (std::string_view class_name, std::string_view name)
 Describe an object for humans, based on class name and optional name. More...
 
void pqxx::internal::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.". More...
 
void pqxx::internal::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. More...
 
constexpr PQXX_PURE std::size_t pqxx::internal::size_esc_bin (std::size_t binary_bytes) noexcept
 Compute buffer size needed to escape binary data for use as a BYTEA. More...
 
constexpr PQXX_PURE std::size_t pqxx::internal::size_unesc_bin (std::size_t escaped_bytes) noexcept
 Compute binary size from the size of its escaped version. More...
 
void pqxx::internal::esc_bin (bytes_view binary_data, std::span< char > buffer) noexcept
 Hex-escape binary data into a buffer. More...
 
template<binary T>
void pqxx::internal::esc_bin (T &&binary_data, std::span< char > buffer) noexcept
 Hex-escape binary data into a buffer. More...
 
std::string pqxx::internal::esc_bin (bytes_view binary_data)
 Hex-escape binary data into a std::string. More...
 
void pqxx::internal::unesc_bin (std::string_view escaped_data, std::span< std::byte > buffer, sl loc)
 Reconstitute binary data from its escaped version. More...
 
pqxx::bytes pqxx::internal::unesc_bin (std::string_view escaped_data, sl loc)
 Reconstitute binary data from its escaped version. More...
 
template<typename RETURN , typename... ARGS>
std::tuple< ARGS... > pqxx::internal::args_f (RETURN(&func)(ARGS...))
 Helper for determining a function's parameter types. More...
 
template<typename RETURN , typename... ARGS>
std::tuple< ARGS... > pqxx::internal::args_f (std::function< RETURN(ARGS...)> const &)
 Helper for determining a std::function's parameter types. More...
 
template<typename CLASS , typename RETURN , typename... ARGS>
std::tuple< ARGS... > pqxx::internal::member_args_f (RETURN(CLASS::*)(ARGS...))
 Helper for determining a member function's parameter types. More...
 
template<typename CALLABLE >
auto pqxx::internal::args_f (CALLABLE const &f) -> decltype(member_args_f(&CALLABLE::operator()))
 Helper for determining a callable type's parameter types. More...
 
template<typename... TYPES>
std::tuple< std::remove_cvref_t< TYPES >... > pqxx::internal::strip_types (std::tuple< TYPES... > const &)
 Apply std::remove_cvref_t to each of a tuple type's component types. More...
 
constexpr PQXX_PURE char pqxx::internal::unescape_char (char escaped) noexcept
 Return original byte for escaped character. More...
 
PQXX_COLD char const * pqxx::internal::make_strerror_rs_result (int err_result, std::span< char > buffer)
 Helper for avoiding type trouble with strerror_r()/strerror_s(). More...
 
PQXX_COLD PQXX_ZARGS char const * pqxx::internal::make_strerror_rs_result (char const *err_result, std::span< char >)
 Helper for avoiding type trouble with strerror_r()/strerror_s(). More...
 
PQXX_COLD char const * pqxx::internal::error_string ([[maybe_unused]] int err_num, [[maybe_unused]] std::span< char > buffer)
 Get error string for a given errno value. More...
 
template<bool terminate>
std::size_t pqxx::internal::copy_chars (std::string_view src, std::span< char > dst, std::size_t dst_offset, sl loc)
 Copy text from src into buf at offset dst_offset. More...
 
void pqxx::internal::pq::pqfreemem (void const *) noexcept
 Wrapper for PQfreemem(), with C++ linkage. More...
 

Variables

constexpr oid pqxx::oid_none {0}
 The "null" oid. More...
 

Class Documentation

◆ pqxx::thread_safety_model

struct pqxx::thread_safety_model

Descriptor of library's thread-safety model.

This describes what the library knows about various risks to thread-safety.

Class Members
string description A human-readable description of any thread-safety issues.
bool safe_kerberos Is Kerberos thread-safe?
Warning
Is currently always false.

If your application uses Kerberos, all accesses to libpqxx or Kerberos must be serialized. Confine their use to a single thread, or protect it with a global lock.

bool safe_libpq Is the underlying libpq build thread-safe?

Macro Definition Documentation

◆ PQXX_UNREACHABLE

#define PQXX_UNREACHABLE   [[unlikely]] while (false)