11 #ifndef PQXX_H_STRINGCONV
12 #define PQXX_H_STRINGCONV
14 #include "pqxx/compiler-public.hxx"
23 #if __has_include(<charconv>)
27 #include "pqxx/except.hxx"
28 #include "pqxx/util.hxx"
29 #include "pqxx/zview.hxx"
75 template<
typename TYPE>
86 template<
typename TYPE,
typename ENABLE =
void>
struct nullness
103 [[nodiscard]]
static TYPE
null();
134 [[nodiscard]]
static constexpr
bool is_null(TYPE
const &) noexcept
168 [[nodiscard]]
static inline zview
169 to_buf(
char *begin,
char *end, TYPE
const &value);
179 static inline char *
into_buf(
char *begin,
char *end, TYPE
const &value);
185 [[nodiscard]]
static inline TYPE
from_string(std::string_view text);
192 [[nodiscard]]
static inline std::size_t
198 template<
typename ENUM>
221 [[nodiscard]]
static constexpr
zview
222 to_buf(
char *begin,
char *end, ENUM
const &value)
227 static constexpr
char *
into_buf(
char *begin,
char *end, ENUM
const &value)
237 [[nodiscard]]
static std::size_t
size_buffer(ENUM
const &value) noexcept
257 #define PQXX_DECLARE_ENUM_CONVERSION(ENUM) \
258 template<> struct string_traits<ENUM> : pqxx::internal::enum_traits<ENUM> \
260 template<> inline std::string const type_name<ENUM> { #ENUM }
278 template<
typename TYPE>
293 [[nodiscard]]
inline std::string_view
from_string(std::string_view text)
307 template<
typename T>
inline void from_string(std::string_view text, T &value)
309 value = from_string<T>(text);
319 template<
typename TYPE>
inline std::string
to_string(TYPE
const &value);
330 template<
typename... TYPE>
331 [[nodiscard]]
inline std::vector<std::string_view>
332 to_buf(
char *here,
char const *end, TYPE... value)
334 return std::vector<std::string_view>{[&here, end](
auto v) {
338 auto len{
static_cast<std::size_t
>(here - begin) - 1};
339 return std::string_view{begin, len};
347 template<
typename TYPE>
352 template<
typename TYPE>
353 [[nodiscard]]
inline bool is_null(TYPE
const &value) noexcept
363 template<
typename... TYPE>
364 [[nodiscard]]
inline std::size_t
size_buffer(TYPE
const &...value) noexcept
402 #include "pqxx/internal/conversions.hxx"
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:26
std::string const type_name
A human-readable name for a type, used in error messages and such.
Definition: strconv.hxx:76
void into_string(TYPE const &value, std::string &out)
Convert a value to a readable string that PostgreSQL will understand.
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:332
constexpr char array_separator
Element separator between SQL array elements of this type.
Definition: strconv.hxx:397
constexpr bool is_unquoted_safe
Can we use this type in arrays and composite types without quoting them?
Definition: strconv.hxx:393
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:364
constexpr bool is_sql_array
Does this type translate to an SQL array?
Definition: strconv.hxx:377
std::string to_string(field const &value)
Convert a field to a string.
Definition: result.cxx:503
bool is_null(TYPE const &value) noexcept
Is value null?
Definition: strconv.hxx:353
T from_string(field const &value)
Convert a field's value to type T.
Definition: field.hxx:491
Internal items for libpqxx' own use. Do not use these yourself.
Definition: composite.hxx:74
std::string demangle_type_name(char const[])
Attempt to demangle std::type_info::name() to something human-readable.
Definition: strconv.cxx:222
Traits describing a type's "null value," if any.
Definition: strconv.hxx:87
static bool is_null(TYPE const &value)
Is value a null?
static bool has_null
Does this type have a null value?
Definition: strconv.hxx:89
static bool always_null
Is this type always null?
Definition: strconv.hxx:92
Nullness traits describing a type which does not have a null value.
Definition: strconv.hxx:109
static constexpr bool always_null
Are all values of this type null?
Definition: strconv.hxx:127
static constexpr bool has_null
Does TYPE have a "built-in null value"?
Definition: strconv.hxx:121
static constexpr bool is_null(TYPE const &) noexcept
Does a given value correspond to an SQL null value?
Definition: strconv.hxx:134
Traits class for use in string conversions.
Definition: strconv.hxx:149
static std::size_t size_buffer(TYPE const &value) noexcept
Estimate how much buffer space is needed to represent value.
static zview to_buf(char *begin, char *end, TYPE const &value)
Return a string_view representing value, plus terminating zero.
static TYPE from_string(std::string_view text)
Parse a string representation of a TYPE value.
Definition: strconv.cxx:717
static char * into_buf(char *begin, char *end, TYPE const &value)
Write value's string representation into buffer at begin.
Helper class for defining enum conversions.
Definition: strconv.hxx:217
static std::size_t size_buffer(ENUM const &value) noexcept
Definition: strconv.hxx:237
static constexpr zview to_buf(char *begin, char *end, ENUM const &value)
Definition: strconv.hxx:222
static constexpr char * into_buf(char *begin, char *end, ENUM const &value)
Definition: strconv.hxx:227
std::underlying_type_t< ENUM > impl_type
Definition: strconv.hxx:218
static ENUM from_string(std::string_view text)
Definition: strconv.hxx:232
Marker-type wrapper: zero-terminated std::string_view.
Definition: zview.hxx:38