11 #ifndef PQXX_H_STRINGCONV 12 #define PQXX_H_STRINGCONV 14 #include "pqxx/compiler-public.hxx" 57 const std::string &type);
68 #define PQXX_DECLARE_STRING_TRAITS_SPECIALIZATION(T) \ 69 template<> struct PQXX_LIBEXPORT string_traits<T> \ 71 static constexpr const char *name() noexcept { return #T; } \ 72 static constexpr bool has_null() noexcept { return false; } \ 73 static bool is_null(T) { return false; } \ 74 [[noreturn]] static T null() \ 75 { internal::throw_null_conversion(name()); } \ 76 static void from_string(const char Str[], T &Obj); \ 77 static std::string to_string(T Obj); \ 95 #undef PQXX_DECLARE_STRING_TRAITS_SPECIALIZATION 108 template<
typename ENUM>
114 static constexpr
bool has_null() noexcept {
return false; }
115 [[noreturn]]
static ENUM
null()
142 #define PQXX_DECLARE_ENUM_CONVERSION(ENUM) \ 144 struct string_traits<ENUM> : pqxx::enum_traits<ENUM> \ 146 static constexpr const char *name() noexcept { return #ENUM; } \ 147 [[noreturn]] static ENUM null() \ 148 { internal::throw_null_conversion(name()); } \ 155 static constexpr
const char *
name() noexcept {
return "const char *"; }
156 static constexpr
bool has_null() noexcept {
return true; }
157 static bool is_null(
const char *t) {
return t ==
nullptr; }
158 static const char *
null() {
return nullptr; }
159 static void from_string(
const char Str[],
const char *&Obj) { Obj = Str; }
160 static std::string
to_string(
const char *Obj) {
return Obj; }
166 static constexpr
const char *
name() noexcept {
return "char *"; }
167 static constexpr
bool has_null() noexcept {
return true; }
168 static bool is_null(
const char *t) {
return t ==
nullptr; }
169 static const char *
null() {
return nullptr; }
180 static constexpr
const char *
name() noexcept {
return "char[]"; }
181 static constexpr
bool has_null() noexcept {
return true; }
182 static bool is_null(
const char t[]) {
return t ==
nullptr; }
183 static const char *
null() {
return nullptr; }
184 static std::string
to_string(
const char Obj[]) {
return Obj; }
189 static constexpr
const char *
name() noexcept {
return "string"; }
190 static constexpr
bool has_null() noexcept {
return false; }
191 static bool is_null(
const std::string &) {
return false; }
192 [[noreturn]]
static std::string
null()
194 static void from_string(
const char Str[], std::string &Obj) { Obj=Str; }
195 static std::string
to_string(
const std::string &Obj) {
return Obj; }
200 static constexpr
const char *
name() noexcept {
return "const string"; }
201 static constexpr
bool has_null() noexcept {
return false; }
202 static bool is_null(
const std::string &) {
return false; }
203 [[noreturn]]
static const std::string
null()
205 static const std::string
to_string(
const std::string &Obj) {
return Obj; }
210 static constexpr
const char *
name() noexcept {
return "stringstream"; }
211 static constexpr
bool has_null() noexcept {
return false; }
212 static bool is_null(
const std::stringstream &) {
return false; }
213 [[noreturn]]
static std::stringstream
null()
216 { Obj.clear(); Obj << Str; }
217 static std::string
to_string(
const std::stringstream &Obj)
218 {
return Obj.str(); }
240 if (Str ==
nullptr)
throw std::runtime_error{
"Attempt to read null string."};
252 template<
typename T>
inline void from_string(
const char Str[], T &Obj,
size_t)
258 inline void from_string<std::string>(
263 if (Str ==
nullptr)
throw std::runtime_error{
"Attempt to read null string."};
264 Obj.assign(Str, len);
275 template<>
inline void 285 {
return static_cast<char>(i+
'0'); }
294 template<
typename T>
inline std::string
to_string(
const T &Obj)
void from_string(const field &F, T &Obj)
Convert a field's string contents to another type.
Definition: field.hxx:365
static const std::string to_string(const std::string &Obj)
Definition: strconv.hxx:205
void throw_null_conversion(const std::string &type)
Throw exception for attempt to convert null to given type.
Definition: strconv.cxx:58
static bool is_null(const char *t)
Definition: strconv.hxx:157
static void from_string(const char Str[], std::string &Obj)
Definition: strconv.hxx:194
static std::string to_string(const std::string &Obj)
Definition: strconv.hxx:195
constexpr int digit_to_number(char c) noexcept
Compute numeric value of given textual digit (assuming that it is a digit)
Definition: strconv.hxx:283
static const char * null()
Definition: strconv.hxx:183
static const std::string null()
Definition: strconv.hxx:203
static bool is_null(const std::string &)
Definition: strconv.hxx:202
static std::string to_string(char *Obj)
Definition: strconv.hxx:174
static constexpr const char * name() noexcept
Definition: strconv.hxx:166
static std::string to_string(const std::stringstream &Obj)
Definition: strconv.hxx:217
void from_string(const std::string &Str, std::string &Obj)
Definition: strconv.hxx:276
static bool is_null(const std::stringstream &)
Definition: strconv.hxx:212
static bool is_null(const char t[])
Definition: strconv.hxx:182
static constexpr const char * name() noexcept
Definition: strconv.hxx:210
static std::string to_string(const char *Obj)
Definition: strconv.hxx:160
std::string to_string(const field &Obj)
Convert a field to a string.
Definition: result.cxx:448
static std::string null()
Definition: strconv.hxx:192
static constexpr bool has_null() noexcept
Definition: strconv.hxx:156
static constexpr bool has_null() noexcept
Definition: strconv.hxx:167
Helper class for defining enum conversions.
Definition: strconv.hxx:109
constexpr char number_to_digit(int i) noexcept
Definition: strconv.hxx:284
static void from_string(const char Str[], const char *&Obj)
Definition: strconv.hxx:159
static ENUM null()
Definition: strconv.hxx:115
static constexpr bool has_null() noexcept
Definition: strconv.hxx:181
static std::string to_string(const char Obj[])
Definition: strconv.hxx:184
Traits class for use in string conversions.
Definition: strconv.hxx:51
static constexpr bool has_null() noexcept
Definition: strconv.hxx:190
typename std::underlying_type< ENUM >::type underlying_type
Definition: strconv.hxx:111
std::string to_string(const T &Obj)
Convert built-in type to a readable string that PostgreSQL will understand.
Definition: strconv.hxx:294
static constexpr bool has_null() noexcept
Definition: strconv.hxx:114
static constexpr bool has_null() noexcept
Definition: strconv.hxx:211
static const char * null()
Definition: strconv.hxx:169
static constexpr const char * name() noexcept
Definition: strconv.hxx:180
static constexpr bool has_null() noexcept
Definition: strconv.hxx:201
static bool is_null(const char *t)
Definition: strconv.hxx:168
static constexpr const char * name() noexcept
Definition: strconv.hxx:155
static constexpr const char * name() noexcept
Definition: strconv.hxx:189
static void from_string(const char Str[], ENUM &Obj)
Definition: strconv.hxx:118
static constexpr const char * name() noexcept
Definition: strconv.hxx:200
#define PQXX_DECLARE_STRING_TRAITS_SPECIALIZATION(T)
Definition: strconv.hxx:68
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:25
static std::stringstream null()
Definition: strconv.hxx:213
static const char * null()
Definition: strconv.hxx:158
static bool is_null(const std::string &)
Definition: strconv.hxx:191
static std::string to_string(ENUM Obj)
Definition: strconv.hxx:125
static void from_string(const char Str[], std::stringstream &Obj)
Definition: strconv.hxx:215