11 #ifndef PQXX_H_STRCONV
12 #define PQXX_H_STRCONV
21 #if __has_include(<charconv>)
25 #if defined(PQXX_HAVE_RANGES) && __has_include(<ranges>)
29 #include "pqxx/except.hxx"
30 #include "pqxx/util.hxx"
31 #include "pqxx/zview.hxx"
77 template<
typename TYPE>
88 template<
typename TYPE,
typename ENABLE =
void>
struct nullness
105 [[nodiscard]]
static TYPE
null();
138 [[nodiscard]]
static constexpr
bool is_null(TYPE
const &) noexcept
172 [[nodiscard]]
static inline zview
173 to_buf(
char *begin,
char *end, TYPE
const &value);
183 static inline char *
into_buf(
char *begin,
char *end, TYPE
const &value);
189 [[nodiscard]]
static inline TYPE
from_string(std::string_view text);
196 [[nodiscard]]
static inline std::size_t
202 template<
typename ENUM>
225 [[nodiscard]]
static constexpr
zview
226 to_buf(
char *begin,
char *end, ENUM
const &value)
231 static constexpr
char *
into_buf(
char *begin,
char *end, ENUM
const &value)
241 [[nodiscard]]
static std::size_t
size_buffer(ENUM
const &value) noexcept
248 static impl_type to_underlying(ENUM
const &value)
268 #define PQXX_DECLARE_ENUM_CONVERSION(ENUM) \
269 template<> struct string_traits<ENUM> : pqxx::internal::enum_traits<ENUM> \
271 template<> inline std::string const type_name<ENUM> { #ENUM }
289 template<
typename TYPE>
304 [[nodiscard]]
inline std::string_view
from_string(std::string_view text)
318 template<
typename T>
inline void from_string(std::string_view text, T &value)
320 value = from_string<T>(
text);
330 template<
typename TYPE>
inline std::string
to_string(TYPE
const &value);
341 template<
typename... TYPE>
342 [[nodiscard]]
inline std::vector<std::string_view>
343 to_buf(
char *here,
char const *end, TYPE... value)
345 return {[&here, end](
auto v) {
349 auto len{
static_cast<std::size_t
>(here - begin) - 1};
350 return std::string_view{begin, len};
358 template<
typename TYPE>
363 template<
typename TYPE>
364 [[nodiscard]]
inline bool is_null(TYPE
const &value) noexcept
374 template<
typename... TYPE>
375 [[nodiscard]]
inline std::size_t
size_buffer(TYPE
const &...value) noexcept
438 template<
typename TYPE>
447 return {begin, traits::into_buf(begin, end, value) - begin - 1};
451 #if defined(PQXX_HAVE_CONCEPTS)
460 concept binary = std::ranges::contiguous_range<TYPE> and
461 std::is_same_v<strip_t<value_type<TYPE>>, std::byte>;
467 #include "pqxx/internal/conversions.hxx"
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:23
std::string const type_name
A human-readable name for a type, used in error messages and such.
Definition: strconv.hxx:78
void into_string(TYPE const &value, std::string &out)
Convert a value to a readable string that PostgreSQL will understand.
std::remove_cv_t< std::remove_reference_t< TYPE > > strip_t
Remove any constness, volatile, and reference-ness from a type.
Definition: types.hxx:87
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:343
constexpr char array_separator
Element separator between SQL array elements of this type.
Definition: strconv.hxx:411
constexpr bool is_unquoted_safe
Can we use this type in arrays and composite types without quoting them?
Definition: strconv.hxx:406
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:375
zview generic_to_buf(char *begin, char *end, TYPE const &value)
Implement string_traits<TYPE>::to_buf by calling into_buf.
Definition: strconv.hxx:439
constexpr format param_format(TYPE const &)
What's the preferred format for passing non-null parameters of this type?
Definition: strconv.hxx:422
constexpr bool is_sql_array
Does this type translate to an SQL array?
Definition: strconv.hxx:389
std::string to_string(field const &value)
Convert a field to a string.
Definition: result.cxx:528
bool is_null(TYPE const &value) noexcept
Is value null?
Definition: strconv.hxx:364
T from_string(field const &value)
Convert a field's value to type T.
Definition: field.hxx:494
format
Format code: is data text or binary?
Definition: types.hxx:77
Internal items for libpqxx' own use. Do not use these yourself.
Definition: composite.hxx:80
std::string demangle_type_name(char const[])
Attempt to demangle std::type_info::name() to something human-readable.
Definition: strconv.cxx:229
Traits describing a type's "null value," if any.
Definition: strconv.hxx:89
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:91
static bool always_null
Is this type always null?
Definition: strconv.hxx:94
Nullness traits describing a type which does not have a null value.
Definition: strconv.hxx:111
static constexpr bool always_null
Are all values of this type null?
Definition: strconv.hxx:131
static constexpr bool has_null
Does TYPE have a "built-in null value"?
Definition: strconv.hxx:124
static constexpr bool is_null(TYPE const &) noexcept
Does a given value correspond to an SQL null value?
Definition: strconv.hxx:138
Traits class for use in string conversions.
Definition: strconv.hxx:153
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:745
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:221
static std::size_t size_buffer(ENUM const &value) noexcept
Definition: strconv.hxx:241
static constexpr zview to_buf(char *begin, char *end, ENUM const &value)
Definition: strconv.hxx:226
static constexpr char * into_buf(char *begin, char *end, ENUM const &value)
Definition: strconv.hxx:231
std::underlying_type_t< ENUM > impl_type
Definition: strconv.hxx:222
static ENUM from_string(std::string_view text)
Definition: strconv.hxx:236
Marker-type wrapper: zero-terminated std::string_view.
Definition: zview.hxx:38