11 #ifndef PQXX_H_STRCONV 12 #define PQXX_H_STRCONV 14 #if !defined(PQXX_HEADER_PRE) 15 # error "Include libpqxx headers as <pqxx/header>, not <pqxx/header.hxx>." 25 #if __has_include(<charconv>) 29 #if defined(PQXX_HAVE_RANGES) && __has_include(<ranges>) 33 #include "pqxx/except.hxx" 34 #include "pqxx/util.hxx" 35 #include "pqxx/zview.hxx" 81 template<
typename TYPE>
92 template<
typename TYPE,
typename ENABLE =
void>
struct nullness 101 static bool is_null(TYPE
const &value);
109 [[nodiscard]]
static TYPE null();
127 static constexpr
bool has_null =
false;
133 static constexpr
bool always_null =
false;
140 [[nodiscard]]
static constexpr
bool is_null(TYPE
const &) noexcept
160 static constexpr
bool converts_to_string{
false};
166 static constexpr
bool converts_from_string{
false};
188 [[nodiscard]]
static inline zview 189 to_buf(
char *begin,
char *end, TYPE
const &value);
199 static inline char *into_buf(
char *begin,
char *end, TYPE
const &value);
215 [[nodiscard]]
static inline std::size_t
239 template<
typename TYPE> [[noreturn]]
251 static constexpr
bool converts_to_string{
false};
252 static constexpr
bool converts_from_string{
false};
254 { oops_forbidden_conversion<TYPE>(); }
255 [[noreturn]]
static char *
into_buf(
char *,
char *, TYPE
const &)
256 { oops_forbidden_conversion<TYPE>(); }
258 { oops_forbidden_conversion<TYPE>(); }
259 [[noreturn]]
static std::size_t
size_buffer(TYPE
const &) noexcept
260 { oops_forbidden_conversion<TYPE>(); }
336 template<
typename ENUM>
362 static constexpr
bool converts_to_string{
true};
363 static constexpr
bool converts_from_string{
true};
365 [[nodiscard]]
static constexpr
zview 366 to_buf(
char *begin,
char *end, ENUM
const &value)
371 static constexpr
char *
into_buf(
char *begin,
char *end, ENUM
const &value)
373 return impl_traits::into_buf(begin, end, to_underlying(value));
381 [[nodiscard]]
static std::size_t
size_buffer(ENUM
const &value) noexcept
388 static constexpr
impl_type to_underlying(ENUM
const &value) noexcept
412 #define PQXX_DECLARE_ENUM_CONVERSION(ENUM) \ 413 template<> struct string_traits<ENUM> : pqxx::internal::enum_traits<ENUM> \ 415 template<> inline std::string_view const type_name<ENUM> { #ENUM } 433 template<
typename TYPE>
448 [[nodiscard]]
inline std::string_view
from_string(std::string_view text)
462 template<
typename T>
inline void from_string(std::string_view text, T &value)
464 value = from_string<T>(text);
474 template<
typename TYPE>
inline std::string
to_string(TYPE
const &value);
485 template<
typename... TYPE>
486 [[nodiscard]]
inline std::vector<std::string_view>
487 to_buf(
char *here,
char const *end, TYPE... value)
489 return {[&here, end](
auto v) {
493 auto len{
static_cast<std::size_t
>(here - begin) - 1};
494 return std::string_view{begin, len};
502 template<
typename TYPE>
503 inline void into_string(TYPE
const &value, std::string &out);
507 template<
typename TYPE>
508 [[nodiscard]]
inline constexpr
bool is_null(TYPE
const &value) noexcept
518 template<
typename... TYPE>
519 [[nodiscard]]
inline std::size_t
size_buffer(TYPE
const &...value) noexcept
579 template<
typename TYPE>
588 return {begin, traits::into_buf(begin, end, value) - begin - 1};
592 #if defined(PQXX_HAVE_CONCEPTS) 601 concept
binary = std::ranges::contiguous_range<TYPE> and
602 std::is_same_v<strip_t<value_type<TYPE>>, std::byte>;
608 #include "pqxx/internal/conversions.hxx"
constexpr bool is_unquoted_safe
Can we use this type in arrays and composite types without quoting them?
Definition: strconv.hxx:548
std::string demangle_type_name(char const [])
Attempt to demangle std::type_info::name() to something human-readable.
Definition: strconv.cxx:230
static std::size_t size_buffer(TYPE const &) noexcept
Definition: strconv.hxx:259
std::string to_string(field const &value)
Convert a field to a string.
Definition: result.cxx:548
std::remove_cv_t< std::remove_reference_t< TYPE > > strip_t
Remove any constness, volatile, and reference-ness from a type.
Definition: types.hxx:91
static TYPE from_string(std::string_view)
Definition: strconv.hxx:257
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:32
constexpr bool is_null(TYPE const &value) noexcept
Is value null?
Definition: strconv.hxx:508
Marker-type wrapper: zero-terminated std::string_view.
Definition: zview.hxx:37
static ENUM from_string(std::string_view text)
Definition: strconv.hxx:376
std::size_t size_buffer(TYPE const &...value) noexcept
Estimate how much buffer space is needed to represent values as a string.
Definition: strconv.hxx:519
void into_string(TYPE const &value, std::string &out)
Convert a value to a readable string that PostgreSQL will understand.
Traits describing a type's "null value," if any.
Definition: strconv.hxx:92
constexpr bool is_sql_array
Does this type translate to an SQL array?
Definition: strconv.hxx:532
T from_string(field const &value)
Convert a field's value to type T.
Definition: field.hxx:520
std::string const type_name
A human-readable name for a type, used in error messages and such.
Definition: strconv.hxx:82
Traits class for use in string conversions.
Definition: strconv.hxx:154
constexpr format param_format(TYPE const &)
What's the preferred format for passing non-null parameters of this type?
Definition: strconv.hxx:563
static bool always_null
Is this type always null?
Definition: strconv.hxx:98
std::underlying_type_t< ENUM > impl_type
Definition: strconv.hxx:359
static std::size_t size_buffer(ENUM const &value) noexcept
Definition: strconv.hxx:381
zview generic_to_buf(char *begin, char *end, TYPE const &value)
Implement string_traits<TYPE>::to_buf by calling into_buf.
Definition: strconv.hxx:580
static constexpr bool is_null(TYPE const &) noexcept
Does a given value correspond to an SQL null value?
Definition: strconv.hxx:140
format
Format code: is data text or binary?
Definition: types.hxx:80
constexpr char array_separator
Element separator between SQL array elements of this type.
Definition: strconv.hxx:552
void from_string(std::string_view text, T &value)
Attempt to convert postgres-generated string to given built-in object.
Definition: strconv.hxx:462
Nullness traits describing a type which does not have a null value.
Definition: strconv.hxx:114
std::vector< std::string_view > to_buf(char *here, char const *end, TYPE... value)
Convert multiple values to strings inside a single buffer.
Definition: strconv.hxx:487
Helper class for defining enum conversions.
Definition: strconv.hxx:357
static TYPE from_string(std::string_view text)
Parse a string representation of a TYPE value.
Definition: strconv.cxx:740
static bool has_null
Does this type have a null value?
Definition: strconv.hxx:95
String traits for a forbidden type conversion.
Definition: strconv.hxx:249
Internal items for libpqxx' own use. Do not use these yourself.
Definition: composite.hxx:83
static constexpr zview to_buf(char *begin, char *end, ENUM const &value)
Definition: strconv.hxx:366
static zview to_buf(char *, char *, TYPE const &)
Definition: strconv.hxx:253
static char * into_buf(char *, char *, TYPE const &)
Definition: strconv.hxx:255
void oops_forbidden_conversion() noexcept
Nonexistent function to indicate a disallowed type conversion.
static constexpr char * into_buf(char *begin, char *end, ENUM const &value)
Definition: strconv.hxx:371