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
92 static bool is_null(TYPE
const &value);
100 [[nodiscard]]
static TYPE
null();
108 [[nodiscard]]
static constexpr
bool is_null(TYPE
const &) noexcept
139 [[nodiscard]]
static inline zview
140 to_buf(
char *begin,
char *end, TYPE
const &value);
150 static inline char *
into_buf(
char *begin,
char *end, TYPE
const &value);
156 [[nodiscard]]
static inline TYPE
from_string(std::string_view text);
163 [[nodiscard]]
static inline size_t size_buffer(TYPE
const &value);
168 template<
typename ENUM>
191 [[nodiscard]]
static constexpr
zview
192 to_buf(
char *begin,
char *end, ENUM
const &value)
197 static constexpr
char *
into_buf(
char *begin,
char *end, ENUM
const &value)
227 #define PQXX_DECLARE_ENUM_CONVERSION(ENUM) \
228 template<> struct string_traits<ENUM> : pqxx::internal::enum_traits<ENUM> \
230 template<> std::string const type_name<ENUM> { #ENUM }
248 template<
typename T>[[nodiscard]]
inline T
from_string(std::string_view text)
262 template<
typename T>
inline void from_string(std::string_view text, T &value)
264 value = from_string<T>(text);
274 template<
typename TYPE>
inline std::string
to_string(TYPE
const &value);
281 template<
typename TYPE>
282 inline void into_string(TYPE
const &value, std::string &out);
286 template<
typename TYPE>[[nodiscard]]
inline bool is_null(TYPE
const &value)
316 #include "pqxx/internal/conversions.hxx"
void ignore_unused(T &&)
Suppress compiler warning about an unused item.
Definition: util.hxx:43
bool is_null(TYPE const &value)
Is value null?
Definition: strconv.hxx:286
std::string demangle_type_name(char const[])
Attempt to demangle std::type_info::name() to something human-readable.
Definition: strconv.cxx:223
Nullness traits describing a type which does not have a null value.
Definition: strconv.hxx:105
Value conversion failed, e.g. when converting "Hello" to int.
Definition: except.hxx:178
std::string to_string_float(T value)
Floating-point implementations for pqxx::to_string().
Definition: strconv.cxx:600
static bool is_null(TYPE const &value)
Is value a null?
static size_t size_buffer(ENUM const &value)
Definition: strconv.hxx:207
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:25
std::string to_string(field const &value)
Convert a field to a string.
Definition: result.cxx:478
encoding_group enc_group(int libpq_enc_id)
Definition: encodings.cxx:585
std::string state_buffer_overrun(int have_bytes, int need_bytes)
Definition: strconv.cxx:247
void throw_null_conversion(std::string const &type)
Definition: strconv.cxx:241
static constexpr zview to_buf(char *begin, char *end, ENUM const &value)
Definition: strconv.hxx:192
Private namespace for libpqxx's internal use; do not access.
Definition: connection.hxx:59
result_difference_type difference_type
Definition: cursor.hxx:44
Result set containing data returned by a query or command.
Definition: result.hxx:70
static zview to_buf(char *begin, char *end, TYPE const &value)
Return a string_view representing value, plus terminating zero.
void into_string(TYPE const &value, std::string &out)
Convert a value to a readable string that PostgreSQL will understand.
static constexpr bool is_null(TYPE const &) noexcept
Definition: strconv.hxx:108
Marker-type wrapper: zero-terminated std::string_view.
Definition: zview.hxx:32
constexpr char array_separator
Element separator between SQL array elements of this type.
Definition: strconv.hxx:311
std::string to_dumb_stringstream(dumb_stringstream< F > &s, F value)
Definition: strconv.cxx:591
T from_string(field const &value)
Convert a field's string contents to another type.
Definition: field.hxx:355
const std::string type_name
A human-readable name for a type, used in error messages and such.
Definition: strconv.hxx:76
static constexpr char * into_buf(char *begin, char *end, ENUM const &value)
Definition: strconv.hxx:197
constexpr bool is_sql_array
Does this type translate to an SQL array?
Definition: strconv.hxx:307
Traits describing a type's "null value," if any.
Definition: strconv.hxx:86
static ENUM from_string(std::string_view text)
Definition: strconv.hxx:202
static constexpr bool has_null
Definition: strconv.hxx:107
Helper class for defining enum conversions.
Definition: strconv.hxx:186
std::underlying_type_t< ENUM > impl_type
Definition: strconv.hxx:188
Traits class for use in string conversions.
Definition: strconv.hxx:119
Could not convert value to string: not enough buffer space.
Definition: except.hxx:185
static size_t size_buffer(TYPE const &value)
Estimate how much buffer space is needed to represent value.
static TYPE from_string(std::string_view text)
Parse a string representation of a TYPE value.
Definition: strconv.cxx:678
static char * into_buf(char *begin, char *end, TYPE const &value)
Write value's string representation into buffer at begin.
static bool has_null
Does this type have a null value?
Definition: strconv.hxx:89