util.hxx
#ifndef PQXX_H_UTIL
#define PQXX_H_UTIL
#include "pqxx/compiler-public.hxx"
#include <cstdio>
#include <cctype>
#include <iterator>
#include <memory>
#include <stdexcept>
#include <string>
#include <type_traits>
#include <typeinfo>
#include <vector>
#include "pqxx/strconv.hxx"
namespace pqxx {}
#include <pqxx/internal/libpq-forward.hxx>
namespace pqxx
{
template<typename T> inline void ignore_unused(T) {}
struct PQXX_LIBEXPORT thread_safety_model
{
bool have_safe_strerror = true;
bool safe_libpq;
bool safe_query_cancel = true;
bool safe_result_copy = true;
bool safe_kerberos;
std::string description;
};
PQXX_LIBEXPORT thread_safety_model describe_thread_safety() noexcept;
constexpr oid oid_none = 0;
template<typename ITER, typename ACCESS> inline
std::string separated_list( //[t00]
const std::string &sep,
ITER begin,
ITER end,
ACCESS access)
{
std::string result;
if (begin != end)
{
result = to_string(access(begin));
for (++begin; begin != end; ++begin)
{
result += sep;
result += to_string(access(begin));
}
}
return result;
}
template<typename ITER> inline std::string
separated_list(const std::string &sep, ITER begin, ITER end) //[t00]
{ return separated_list(sep, begin, end, [](ITER i){ return *i; }); }
template<typename CONTAINER> inline auto
separated_list(const std::string &sep, const CONTAINER &c) //[t10]
/*
Always std::string; necessary because SFINAE doesn't work with the
contents of function bodies, so the check for iterability has to be in
the signature.
*/
-> typename std::enable_if<
(
not std::is_void<decltype(std::begin(c))>::value
and not std::is_void<decltype(std::end(c))>::value
),
std::string
>::type
{
return separated_list(sep, std::begin(c), std::end(c));
}
template<
typename TUPLE,
std::size_t INDEX=0,
typename ACCESS,
typename std::enable_if<
(INDEX == std::tuple_size<TUPLE>::value-1),
int
>::type=0
>
inline std::string
separated_list(
const std::string & /* sep */,
const TUPLE &t,
const ACCESS& access
)
{
return to_string(access(&std::get<INDEX>(t)));
}
template<
typename TUPLE,
std::size_t INDEX=0,
typename ACCESS,
typename std::enable_if<
(INDEX < std::tuple_size<TUPLE>::value-1),
int
>::type=0
>
inline std::string
separated_list(const std::string &sep, const TUPLE &t, const ACCESS& access)
{
return
to_string(access(&std::get<INDEX>(t))) +
sep +
separated_list<TUPLE, INDEX+1>(sep, t, access);
}
template<
typename TUPLE,
std::size_t INDEX=0,
typename std::enable_if<
(INDEX <= std::tuple_size<TUPLE>::value),
int
>::type=0
>
inline std::string
separated_list(const std::string &sep, const TUPLE &t)
{
return separated_list(sep, t, [](const TUPLE &tup){return *tup;});
}
namespace internal
{
PQXX_LIBEXPORT void freepqmem(const void *) noexcept;
template<typename P> inline void freepqmem_templated(P *p) noexcept
{
freepqmem(p);
}
PQXX_LIBEXPORT void freemallocmem(const void *) noexcept;
template<typename P> inline void freemallocmem_templated(P *p) noexcept
{
freemallocmem(p);
}
class PQXX_LIBEXPORT namedclass
{
public:
explicit namedclass(const std::string &Classname) :
m_classname{Classname},
m_name{}
{
}
namedclass(const std::string &Classname, const std::string &Name) :
m_classname{Classname},
m_name{Name}
{
}
const std::string &name() const noexcept { return m_name; } //[t01]
const std::string &classname() const noexcept //[t73]
{ return m_classname; }
std::string description() const;
private:
std::string m_classname, m_name;
};
PQXX_PRIVATE void CheckUniqueRegistration(
const namedclass *New, const namedclass *Old);
PQXX_PRIVATE void CheckUniqueUnregistration(
const namedclass *New, const namedclass *Old);
template<typename GUEST>
class unique
{
public:
unique() =default;
unique(const unique &) =delete;
unique &operator=(const unique &) =delete;
GUEST *get() const noexcept { return m_guest; }
void register_guest(GUEST *G)
{
CheckUniqueRegistration(G, m_guest);
m_guest = G;
}
void unregister_guest(GUEST *G)
{
CheckUniqueUnregistration(G, m_guest);
m_guest = nullptr;
}
private:
GUEST *m_guest = nullptr;
};
PQXX_LIBEXPORT void sleep_seconds(int);
} // namespace internal
} // namespace pqxx
#endif
pqxx::internal
Private namespace for libpqxx's internal use; do not access.
Definition: connection_base.hxx:43
pqxx::internal::namedclass::classname
const std::string & classname() const noexcept
Class name.
Definition: util.hxx:252
pqxx::internal::CheckUniqueUnregistration
void CheckUniqueUnregistration(const namedclass *New, const namedclass *Old)
Definition: util.cxx:88
pqxx::internal::namedclass::name
const std::string & name() const noexcept
Object name, or the empty string if no name was given.
Definition: util.hxx:249
pqxx::internal::sleep_seconds
void sleep_seconds(int)
Sleep for the given number of seconds.
Definition: util.cxx:118
pqxx::internal::namedclass::description
std::string description() const
Combination of class name and object name; or just class name.
Definition: util.cxx:55
pqxx::result
Result set containing data returned by a query or command.
Definition: result.hxx:69
pqxx::ignore_unused
void ignore_unused(T)
Suppress compiler warning about an unused item.
Definition: util.hxx:38
pqxx::internal::freepqmem_templated
void freepqmem_templated(P *p) noexcept
Definition: util.hxx:208
pqxx::internal::unique::get
GUEST * get() const noexcept
Definition: util.hxx:281
pqxx::thread_safety_model::safe_kerberos
bool safe_kerberos
Is Kerberos thread-safe?
Definition: util.hxx:65
pqxx::thread_safety_model::description
std::string description
A human-readable description of any thread-safety issues.
Definition: util.hxx:68
pqxx::internal::namedclass::namedclass
namedclass(const std::string &Classname)
Definition: util.hxx:236
pqxx::internal::freemallocmem
void freemallocmem(const void *) noexcept
Definition: util.cxx:112
pqxx::separated_list
std::string separated_list(const std::string &sep, ITER begin, ITER end, ACCESS access)
Represent sequence of values as a string, joined by a given separator.
Definition: util.hxx:95
pqxx::internal::CheckUniqueRegistration
void CheckUniqueRegistration(const namedclass *New, const namedclass *Old)
Definition: util.cxx:72
pqxx::internal_error
Internal error in libpqxx library.
Definition: except.hxx:207
pqxx::internal::unique::register_guest
void register_guest(GUEST *G)
Definition: util.hxx:283
pqxx::describe_thread_safety
thread_safety_model describe_thread_safety() noexcept
Describe thread safety available in this build.
Definition: util.cxx:31
pqxx::oid_none
constexpr oid oid_none
The "null" oid.
Definition: util.hxx:77
pqxx::internal::namedclass::namedclass
namedclass(const std::string &Classname, const std::string &Name)
Definition: util.hxx:242
pqxx::thread_safety_model::safe_libpq
bool safe_libpq
Is the underlying libpq build thread-safe?
Definition: util.hxx:50
pqxx::internal::namedclass
Helper base class: object descriptions for error messages and such.
Definition: util.hxx:233
pqxx::internal::freepqmem
void freepqmem(const void *) noexcept
Definition: util.cxx:106
pqxx::internal::unique::unregister_guest
void unregister_guest(GUEST *G)
Definition: util.hxx:289
pqxx::to_string
std::string to_string(const field &Obj)
Convert a field to a string.
Definition: result.cxx:451
pqxx::thread_safety_model
Descriptor of library's thread-safety model.
Definition: util.hxx:44
pqxx::internal::freemallocmem_templated
void freemallocmem_templated(P *p) noexcept
Definition: util.hxx:214
pqxx
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:25
pqxx::usage_error
Error in usage of libpqxx library, similar to std::logic_error.
Definition: except.hxx:218
pqxx::internal::unique
Ensure proper opening/closing of GUEST objects related to a "host" object.
Definition: util.hxx:274