11 #ifndef PQXX_H_STRINGCONV 12 #define PQXX_H_STRINGCONV 14 #include "pqxx/compiler-public.hxx" 58 const std::string &type);
69 #define PQXX_DECLARE_STRING_TRAITS_SPECIALIZATION(T) \ 70 template<> struct PQXX_LIBEXPORT string_traits<T> \ 72 static constexpr const char *name() noexcept { return #T; } \ 73 static constexpr bool has_null() noexcept { return false; } \ 74 static bool is_null(T) { return false; } \ 75 [[noreturn]] static T null() \ 76 { internal::throw_null_conversion(name()); } \ 77 static void from_string(const char Str[], T &Obj); \ 78 static std::string to_string(T Obj); \ 96 #undef PQXX_DECLARE_STRING_TRAITS_SPECIALIZATION 109 template<
typename ENUM>
115 static constexpr
bool has_null() noexcept {
return false; }
116 [[noreturn]]
static ENUM
null()
143 #define PQXX_DECLARE_ENUM_CONVERSION(ENUM) \ 145 struct PQXX_LIBEXPORT string_traits<ENUM> : pqxx::enum_traits<ENUM> \ 147 static constexpr const char *name() noexcept { return #ENUM; } \ 148 [[noreturn]] static ENUM null() \ 149 { internal::throw_null_conversion(name()); } \ 156 static constexpr
const char *
name() noexcept {
return "const char *"; }
157 static constexpr
bool has_null() noexcept {
return true; }
158 static bool is_null(
const char *t) {
return !t; }
159 static const char *
null() {
return nullptr; }
160 static void from_string(
const char Str[],
const char *&Obj) { Obj = Str; }
161 static std::string
to_string(
const char *Obj) {
return Obj; }
167 static constexpr
const char *
name() noexcept {
return "char *"; }
168 static constexpr
bool has_null() noexcept {
return true; }
169 static bool is_null(
const char *t) {
return !t; }
170 static const char *
null() {
return nullptr; }
181 static constexpr
const char *
name() noexcept {
return "char[]"; }
182 static constexpr
bool has_null() noexcept {
return true; }
183 static bool is_null(
const char t[]) {
return !t; }
184 static const char *
null() {
return nullptr; }
185 static std::string
to_string(
const char Obj[]) {
return Obj; }
190 static constexpr
const char *
name() noexcept {
return "string"; }
191 static constexpr
bool has_null() noexcept {
return false; }
192 static bool is_null(
const std::string &) {
return false; }
195 static void from_string(
const char Str[], std::string &Obj) { Obj=Str; }
196 static std::string
to_string(
const std::string &Obj) {
return Obj; }
201 static constexpr
const char *
name() noexcept {
return "const string"; }
202 static constexpr
bool has_null() noexcept {
return false; }
203 static bool is_null(
const std::string &) {
return false; }
204 static const std::string
null()
206 static const std::string
to_string(
const std::string &Obj) {
return Obj; }
211 static constexpr
const char *
name() noexcept {
return "stringstream"; }
212 static constexpr
bool has_null() noexcept {
return false; }
213 static bool is_null(
const std::stringstream &) {
return false; }
214 static std::stringstream
null()
221 { Obj.clear(); Obj << Str; }
222 static std::string
to_string(
const std::stringstream &Obj)
223 {
return Obj.str(); }
245 if (!Str)
throw std::runtime_error(
"Attempt to read null string");
257 template<
typename T>
inline void from_string(
const char Str[], T &Obj,
size_t)
263 inline void from_string<std::string>(
268 if (!Str)
throw std::runtime_error(
"Attempt to read null string");
269 Obj.assign(Str, len);
280 template<>
inline void 290 {
return static_cast<char>(i+
'0'); }
299 template<
typename T>
inline std::string
to_string(
const T &Obj)
static bool is_null(const char *t)
Definition: strconv.hxx:158
static const char * null()
Definition: strconv.hxx:184
static const char * null()
Definition: strconv.hxx:170
static std::string to_string(const std::stringstream &Obj)
Definition: strconv.hxx:222
static const std::string to_string(const std::string &Obj)
Definition: strconv.hxx:206
#define PQXX_DECLARE_STRING_TRAITS_SPECIALIZATION(T)
Definition: strconv.hxx:69
static constexpr bool has_null() noexcept
Definition: strconv.hxx:202
static void from_string(const char Str[], std::stringstream &Obj)
Definition: strconv.hxx:220
static std::string to_string(const char Obj[])
Definition: strconv.hxx:185
static void from_string(const char Str[], ENUM &Obj)
Definition: strconv.hxx:119
std::string to_string(const field &Obj)
Convert a field to a string.
Definition: result.cxx:434
void from_string(const field &F, T &Obj)
Convert a field's string contents to another type.
Definition: field.hxx:354
static constexpr bool has_null() noexcept
Definition: strconv.hxx:182
char number_to_digit(int i) noexcept
Definition: strconv.hxx:289
static constexpr const char * name() noexcept
Definition: strconv.hxx:181
static ENUM null()
Definition: strconv.hxx:116
int digit_to_number(char c) noexcept
Compute numeric value of given textual digit (assuming that it is a digit)
Definition: strconv.hxx:288
static bool is_null(const std::string &)
Definition: strconv.hxx:192
static constexpr bool has_null() noexcept
Definition: strconv.hxx:191
static const char * null()
Definition: strconv.hxx:159
static constexpr const char * name() noexcept
Definition: strconv.hxx:201
static bool is_null(const std::stringstream &)
Definition: strconv.hxx:213
void throw_null_conversion(const std::string &type)
Throw exception for attempt to convert null to given type.
Definition: strconv.cxx:291
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:22
static std::string to_string(const std::string &Obj)
Definition: strconv.hxx:196
static constexpr bool has_null() noexcept
Definition: strconv.hxx:212
static void from_string(const char Str[], std::string &Obj)
Definition: strconv.hxx:195
static constexpr const char * name() noexcept
Definition: strconv.hxx:167
Helper class for defining enum conversions.
Definition: strconv.hxx:110
static constexpr bool has_null() noexcept
Definition: strconv.hxx:115
static bool is_null(const std::string &)
Definition: strconv.hxx:203
static bool is_null(const char *t)
Definition: strconv.hxx:169
static constexpr const char * name() noexcept
Definition: strconv.hxx:156
static constexpr bool has_null() noexcept
Definition: strconv.hxx:168
static constexpr const char * name() noexcept
Definition: strconv.hxx:211
static bool is_null(const char t[])
Definition: strconv.hxx:183
Traits class for use in string conversions.
Definition: strconv.hxx:52
static void from_string(const char Str[], const char *&Obj)
Definition: strconv.hxx:160
void from_string(const std::string &Str, std::string &Obj)
Definition: strconv.hxx:281
static std::string to_string(char *Obj)
Definition: strconv.hxx:175
static std::string null()
Definition: strconv.hxx:193
static std::string to_string(ENUM Obj)
Definition: strconv.hxx:126
static const std::string null()
Definition: strconv.hxx:204
static constexpr bool has_null() noexcept
Definition: strconv.hxx:157
static std::stringstream null()
Definition: strconv.hxx:214
static std::string to_string(const char *Obj)
Definition: strconv.hxx:161
static constexpr const char * name() noexcept
Definition: strconv.hxx:190
typename std::underlying_type< ENUM >::type underlying_type
Definition: strconv.hxx:112
std::string to_string(const T &Obj)
Convert built-in type to a readable string that PostgreSQL will understand.
Definition: strconv.hxx:299