libpqxx
The C++ client library for PostgreSQL
strconv.hxx File Reference
#include <algorithm>
#include <charconv>
#include <cstring>
#include <limits>
#include <ranges>
#include <sstream>
#include <stdexcept>
#include <typeinfo>
#include "pqxx/encoding_group.hxx"
#include "pqxx/except.hxx"
#include "pqxx/util.hxx"
#include "pqxx/zview.hxx"
#include "pqxx/internal/conversions.hxx"
+ Include dependency graph for strconv.hxx:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  pqxx::nullness< TYPE, ENABLE >
 Traits describing a type's "null value," if any. More...
 
struct  pqxx::no_null< TYPE >
 Nullness traits describing a type which does not have a null value. More...
 
struct  pqxx::all_null< TYPE, null_value >
 Nullness traits describing a type whose values are always null. More...
 
struct  pqxx::conversion_context
 Contextual parameters for string conversions implementations. More...
 
struct  pqxx::string_traits< TYPE >
 Traits class for use in string conversions. More...
 
struct  pqxx::forbidden_conversion< TYPE >
 String traits for a forbidden type conversion. More...
 
struct  pqxx::string_traits< char >
 You cannot convert a char to/from SQL. More...
 
struct  pqxx::string_traits< unsigned char >
 You cannot convert an unsigned char to/from SQL. More...
 
struct  pqxx::string_traits< signed char >
 You cannot convert a signed char to/from SQL. More...
 
struct  pqxx::string_traits< std::byte >
 You cannot convert a std::byte to/from SQL. More...
 
struct  pqxx::nullness< ENUM >
 Nullness: Enums do not have an inherent null value. More...
 
struct  pqxx::internal::enum_traits< ENUM >
 Helper class for defining enum conversions. More...
 

Namespaces

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

Macros

#define PQXX_DECLARE_ENUM_CONVERSION(ENUM)
 Macro: Define a string conversion for an enum type. More...
 

Typedefs

using pqxx::ctx = conversion_context const &
 Convenience alias: const reference to a pqxx::conversion_context. More...
 

Functions

template<typename... TYPE>
constexpr std::size_t pqxx::size_buffer (TYPE const &...value) noexcept
 Estimate how much buffer space is needed to represent values as a string. More...
 
template<typename TYPE >
 pqxx::requires (pqxx::internal::to_buf_7< TYPE > or pqxx::internal::to_buf_8< TYPE >) const eval bool supports_to_buf_8()
 Is the libpqxx 8 version of to_buf() supported for TYPE? More...
 
template<typename TYPE >
std::string_view pqxx::to_buf (std::span< char > buf, TYPE const &value, ctx c={})
 Represent value as SQL text, optionally using buf as storage. More...
 
template<typename TYPE >
std::size_t pqxx::into_buf (std::span< char > buf, TYPE const &value, ctx c={})
 Write an SQL representation of value into buf. More...
 
template<typename TYPE >
 pqxx::requires (pqxx::internal::from_string_7< TYPE > or pqxx::internal::from_string_8< TYPE >) const eval bool supports_from_string_8()
 Is the libpqxx 8 version of from_string() supported for TYPE? More...
 
template<typename TYPE >
TYPE pqxx::from_string (std::string_view text, ctx c={})
 Parse a value in postgres' text format as a TYPE. More...
 
template<>
std::string_view pqxx::from_string (std::string_view text, ctx)
 "Convert" a std::string_view to a std::string_view. More...
 
template<typename T >
void pqxx::from_string (std::string_view text, T &value, ctx c={})
 Attempt to convert postgres-generated string to given built-in object. More...
 
template<typename TYPE >
std::string pqxx::to_string (TYPE const &value, ctx c={})
 Convert a value to a readable string that PostgreSQL will understand. More...
 
template<typename... TYPE>
std::vector< std::string_view > pqxx::to_buf (char *begin, char const *end, TYPE... value)
 Convert multiple values to strings inside a single buffer. More...
 
template<typename... TYPE>
std::vector< std::string_view > pqxx::to_buf_multi (ctx c, std::span< char > buf, TYPE... value)
 Convert multiple values to strings inside a single buffer. More...
 
template<typename... TYPE>
std::vector< std::string_view > pqxx::to_buf_multi (std::span< char > buf, TYPE... value)
 Convert multiple values to strings inside a single buffer. More...
 
template<typename TYPE >
void pqxx::into_string (TYPE const &value, std::string &out)
 Convert a value to a readable string that PostgreSQL will understand. More...
 
template<typename TYPE >
constexpr bool pqxx::has_null () noexcept
 Does TYPE have one or more inherent null values? More...
 
template<typename TYPE >
constexpr bool pqxx::always_null () noexcept
 Is a value of TYPE always null? More...
 
template<typename TYPE >
constexpr bool pqxx::is_null (TYPE const &value) noexcept
 Is value a null? More...
 
template<typename TYPE >
constexpr TYPE pqxx::make_null () requires(pqxx
 Return a null value of TYPE. More...
 
template<typename TYPE >
constexpr format pqxx::param_format (TYPE const &)
 What's the preferred format for passing non-null parameters of this type? More...
 

Variables

template<typename TYPE >
concept pqxx::internal::to_buf_7
 Signature for string_traits<TYPE>::to_buf() in libpqxx 7. More...
 
template<typename TYPE >
concept pqxx::internal::to_buf_8
 Signature for string_traits<TYPE>::to_buf() in libpqxx 8. More...
 
template<typename TYPE >
concept pqxx::internal::from_string_8
 Signature for string_traits<TYPE>::from_string() in libpqxx 8. More...
 
template<typename TYPE >
concept pqxx::internal::from_string_7
 Signature for string_traits<TYPE>::from_string() in libpqxx 7. More...
 
template<typename TYPE >
constexpr bool pqxx::is_sql_array {false}
 Does this type translate to an SQL array? More...
 
template<typename TYPE >
constexpr bool pqxx::is_unquoted_safe {false}
 Can we use this type in arrays and composite types without quoting them? More...
 
template<typename T >
constexpr char pqxx::array_separator {','}
 Element separator between SQL array elements of this type. More...
 

Macro Definition Documentation

◆ PQXX_DECLARE_ENUM_CONVERSION

#define PQXX_DECLARE_ENUM_CONVERSION (   ENUM)
Value:
template<> \
[[maybe_unused, deprecated("Use name_type() instead of type_name.")]] \
constexpr inline std::string_view type_name<ENUM>{#ENUM}; \
template<> inline constexpr std::string_view name_type<ENUM>() noexcept \
{ \
return #ENUM; \
} \
template<> \
struct string_traits<ENUM> final : pqxx::internal::enum_traits<ENUM> \
{}
Helper class for defining enum conversions.
Definition: strconv.hxx:575

Macro: Define a string conversion for an enum type.

This specialises the pqxx::string_traits and pqxx::name_type templates, so use it in the pqxx namespace.

For example:

 #include <iostream>
 #include <pqxx/strconv>
 enum X { xa, xb };
 namespace pqxx { PQXX_DECLARE_ENUM_CONVERSION(x); }
 int main() { std::cout << pqxx::to_string(xa) << std::endl; }