18 #ifndef PQXX_H_STRINGCONV
19 #define PQXX_H_STRINGCONV
21 #include "pqxx/compiler-public.hxx"
54 #define PQXX_DECLARE_STRING_TRAITS_SPECIALIZATION(T) \
55 template<> struct PQXX_LIBEXPORT string_traits<T> \
57 typedef T subject_type; \
58 static const char *name() { return #T; } \
59 static bool has_null() { return false; } \
60 static bool is_null(T) { return false; } \
62 { internal::throw_null_conversion(name()); return subject_type(); } \
63 static void from_string(const char Str[], T &Obj); \
64 static PGSTD::string to_string(T Obj); \
75 #ifdef PQXX_HAVE_LONG_LONG
82 #ifdef PQXX_HAVE_LONG_DOUBLE
86 #undef PQXX_DECLARE_STRING_TRAITS_SPECIALIZATION
91 static const char *
name() {
return "const char *"; }
93 static bool is_null(
const char *t) {
return !t; }
94 static const char *
null() {
return NULL; }
95 static void from_string(
const char Str[],
const char *&Obj) { Obj = Str; }
96 static PGSTD::string
to_string(
const char *Obj) {
return Obj; }
102 static const char *
name() {
return "char *"; }
104 static bool is_null(
const char *t) {
return !t; }
105 static const char *
null() {
return NULL; }
110 static PGSTD::string
to_string(
char *Obj) {
return Obj; }
116 static const char *
name() {
return "char[]"; }
118 static bool is_null(
const char t[]) {
return !t; }
119 static const char *
null() {
return NULL; }
120 static void from_string(
const char Str[],
const char *&Obj) { Obj = Str; }
121 static PGSTD::string
to_string(
const char Obj[]) {
return Obj; }
126 static const char *
name() {
return "string"; }
128 static bool is_null(
const PGSTD::string &) {
return false; }
129 static PGSTD::string null()
131 static void from_string(
const char Str[], PGSTD::string &Obj) { Obj=Str; }
132 static PGSTD::string
to_string(
const PGSTD::string &Obj) {
return Obj; }
137 static const char *
name() {
return "const string"; }
139 static bool is_null(
const PGSTD::string &) {
return false; }
140 static const PGSTD::string null()
142 static const PGSTD::string
to_string(
const PGSTD::string &Obj) {
return Obj; }
147 static const char *
name() {
return "stringstream"; }
149 static bool is_null(
const PGSTD::stringstream &) {
return false; }
150 static PGSTD::stringstream null()
156 static void from_string(
const char Str[], PGSTD::stringstream &Obj)
157 { Obj.clear(); Obj << Str; }
158 static PGSTD::string
to_string(
const PGSTD::stringstream &Obj)
159 {
return Obj.str(); }
182 throw PGSTD::runtime_error(
"Attempt to read NULL string");
194 template<
typename T>
inline void from_string(
const char Str[], T &Obj,
size_t)
200 inline void from_string<PGSTD::string>(
const char Str[],
205 throw PGSTD::runtime_error(
"Attempt to read NULL string");
206 Obj.assign(Str, len);
217 template<>
inline void
235 template<
typename T>
inline PGSTD::string
to_string(
const T &Obj)