11 #ifndef PQXX_H_STRINGCONV 12 #define PQXX_H_STRINGCONV 14 #include "pqxx/compiler-public.hxx" 44 [[noreturn]] PQXX_LIBEXPORT
void throw_null_conversion(
45 const std::string &type);
56 #define PQXX_DECLARE_STRING_TRAITS_SPECIALIZATION(T) \ 57 template<> struct PQXX_LIBEXPORT string_traits<T> \ 59 static constexpr const char *name() noexcept { return #T; } \ 60 static constexpr bool has_null() noexcept { return false; } \ 61 static bool is_null(T) { return false; } \ 62 [[noreturn]] static T null() \ 63 { internal::throw_null_conversion(name()); } \ 64 static void from_string(const char Str[], T &Obj); \ 65 static std::string to_string(T Obj); \ 83 #undef PQXX_DECLARE_STRING_TRAITS_SPECIALIZATION 88 static constexpr
const char *
name() noexcept {
return "const char *"; }
89 static constexpr
bool has_null() noexcept {
return true; }
90 static bool is_null(
const char *t) {
return !t; }
91 static const char *
null() {
return nullptr; }
92 static void from_string(
const char Str[],
const char *&Obj) { Obj = Str; }
93 static std::string
to_string(
const char *Obj) {
return Obj; }
99 static constexpr
const char *
name() noexcept {
return "char *"; }
100 static constexpr
bool has_null() noexcept {
return true; }
101 static bool is_null(
const char *t) {
return !t; }
102 static const char *
null() {
return nullptr; }
113 static constexpr
const char *
name() noexcept {
return "char[]"; }
114 static constexpr
bool has_null() noexcept {
return true; }
115 static bool is_null(
const char t[]) {
return !t; }
116 static const char *
null() {
return nullptr; }
117 static std::string
to_string(
const char Obj[]) {
return Obj; }
122 static constexpr
const char *
name() noexcept {
return "string"; }
123 static constexpr
bool has_null() noexcept {
return false; }
124 static bool is_null(
const std::string &) {
return false; }
127 static void from_string(
const char Str[], std::string &Obj) { Obj=Str; }
128 static std::string
to_string(
const std::string &Obj) {
return Obj; }
133 static constexpr
const char *
name() noexcept {
return "const string"; }
134 static constexpr
bool has_null() noexcept {
return false; }
135 static bool is_null(
const std::string &) {
return false; }
136 static const std::string
null()
138 static const std::string
to_string(
const std::string &Obj) {
return Obj; }
143 static constexpr
const char *
name() noexcept {
return "stringstream"; }
144 static constexpr
bool has_null() noexcept {
return false; }
145 static bool is_null(
const std::stringstream &) {
return false; }
146 static std::stringstream
null()
153 { Obj.clear(); Obj << Str; }
154 static std::string
to_string(
const std::stringstream &Obj)
155 {
return Obj.str(); }
177 if (!Str)
throw std::runtime_error(
"Attempt to read null string");
189 template<
typename T>
inline void from_string(
const char Str[], T &Obj,
size_t)
195 inline void from_string<std::string>(
200 if (!Str)
throw std::runtime_error(
"Attempt to read null string");
201 Obj.assign(Str, len);
212 template<>
inline void 222 {
return static_cast<char>(i+
'0'); }
231 template<
typename T>
inline std::string
to_string(
const T &Obj)
static constexpr const char * name() noexcept
Definition: strconv.hxx:143
static std::string to_string(char *Obj)
Definition: strconv.hxx:107
static constexpr const char * name() noexcept
Definition: strconv.hxx:113
static bool is_null(const std::stringstream &)
Definition: strconv.hxx:145
static std::string to_string(const char Obj[])
Definition: strconv.hxx:117
std::string to_string(const T &Obj)
Convert built-in type to a readable string that PostgreSQL will understand.
Definition: strconv.hxx:231
static const char * null()
Definition: strconv.hxx:102
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:22
char number_to_digit(int i) noexcept
Definition: strconv.hxx:221
void from_string(const std::string &Str, std::string &Obj)
Definition: strconv.hxx:213
static void from_string(const char Str[], const char *&Obj)
Definition: strconv.hxx:92
static constexpr const char * name() noexcept
Definition: strconv.hxx:88
static bool is_null(const char t[])
Definition: strconv.hxx:115
static std::string null()
Definition: strconv.hxx:125
static constexpr bool has_null() noexcept
Definition: strconv.hxx:89
int digit_to_number(char c) noexcept
Compute numeric value of given textual digit (assuming that it is a digit)
Definition: strconv.hxx:220
void throw_null_conversion(const std::string &type)
Throw exception for attempt to convert null to given type.
Definition: strconv.cxx:266
static const std::string null()
Definition: strconv.hxx:136
static void from_string(const char Str[], std::stringstream &Obj)
Definition: strconv.hxx:152
static constexpr const char * name() noexcept
Definition: strconv.hxx:122
static std::stringstream null()
Definition: strconv.hxx:146
void from_string(const field &F, T &Obj)
Convert a field's string contents to another type.
Definition: field.hxx:347
static const std::string to_string(const std::string &Obj)
Definition: strconv.hxx:138
static bool is_null(const char *t)
Definition: strconv.hxx:90
static constexpr const char * name() noexcept
Definition: strconv.hxx:99
static bool is_null(const std::string &)
Definition: strconv.hxx:124
static const char * null()
Definition: strconv.hxx:116
static void from_string(const char Str[], std::string &Obj)
Definition: strconv.hxx:127
static std::string to_string(const char *Obj)
Definition: strconv.hxx:93
std::string to_string(const field &Obj)
Convert a field to a string.
Definition: result.cxx:434
static const char * null()
Definition: strconv.hxx:91
static constexpr bool has_null() noexcept
Definition: strconv.hxx:134
static constexpr bool has_null() noexcept
Definition: strconv.hxx:100
static bool is_null(const std::string &)
Definition: strconv.hxx:135
static constexpr bool has_null() noexcept
Definition: strconv.hxx:123
static constexpr const char * name() noexcept
Definition: strconv.hxx:133
static constexpr bool has_null() noexcept
Definition: strconv.hxx:144
static std::string to_string(const std::string &Obj)
Definition: strconv.hxx:128
static constexpr bool has_null() noexcept
Definition: strconv.hxx:114
#define PQXX_DECLARE_STRING_TRAITS_SPECIALIZATION(T)
Definition: strconv.hxx:56
Traits class for use in string conversions.
Definition: strconv.hxx:39
static std::string to_string(const std::stringstream &Obj)
Definition: strconv.hxx:154
static bool is_null(const char *t)
Definition: strconv.hxx:101