22 #include "pqxx/compiler-public.hxx"
23 #include "pqxx/compiler-internal-pre.hxx"
25 #if defined(PQXX_HAVE_OPTIONAL)
29 #if defined(PQXX_HAVE_EXP_OPTIONAL)
30 #include <experimental/optional>
33 #include "pqxx/strconv"
84 bool operator==(
const field &)
const;
90 {
return !operator==(rhs);}
97 const char *name()
const;
122 const char *c_str()
const;
125 template<
typename T>
bool to(T &Obj)
const
127 const char *
const bytes = c_str();
128 if (!bytes[0] && is_null())
return false;
137 #ifdef PQXX_NO_PARTIAL_CLASS_TEMPLATE_SPECIALISATION
138 template<>
bool to<std::string>(std::string &Obj)
const;
145 template<>
bool to<const char *>(
const char *&Obj)
const;
149 template<
typename T>
bool to(T &Obj,
const T &Default)
const
151 const bool NotNull = to(Obj);
152 if (!NotNull) Obj = Default;
160 template<
typename T> T
as(
const T &Default)
const
168 template<
typename T> T
as() const
171 const bool NotNull = to(Obj);
176 #if defined(PQXX_HAVE_OPTIONAL)
177 template<
typename T> std::optional<T>
get()
const
179 {
return get_opt<T, std::optional<T> >(); }
182 #if defined(PQXX_HAVE_EXP_OPTIONAL)
183 template<
typename T> std::experimental::optional<T>
get()
const
185 {
return get_opt<T, std::experimental::optional<T> >(); }
189 bool is_null() const PQXX_NOEXCEPT;
195 size_type size() const PQXX_NOEXCEPT;
200 const
result *home() const PQXX_NOEXCEPT {
return m_home; }
201 size_t idx() const PQXX_NOEXCEPT {
return m_row; }
213 template<
typename T,
typename OPTIONAL_T> OPTIONAL_T get_opt()
const
215 if (is_null())
return OPTIONAL_T();
216 else return OPTIONAL_T(as<T>());
226 inline bool field::to<std::string>(std::string &Obj)
const
228 const char *
const bytes = c_str();
229 if (!bytes[0] && is_null())
return false;
230 Obj = std::string(bytes, size());
241 inline bool field::to<const char *>(
const char *&Obj)
const
243 if (is_null())
return false;
249 template<
typename CHAR=
char,
typename TRAITS=std::
char_traits<CHAR> >
251 public std::basic_streambuf<CHAR, TRAITS>
269 virtual int sync() PQXX_OVERRIDE {
return traits_type::eof(); }
273 {
return traits_type::eof(); }
275 {
return traits_type::eof();}
277 {
return traits_type::eof(); }
279 {
return traits_type::eof(); }
282 const field &m_Field;
287 reinterpret_cast<char_type *
>(
const_cast<char *
>(m_Field.
c_str()));
288 this->setg(G, G, G + m_Field.
size());
303 template<
typename CHAR=
char,
typename TRAITS=std::
char_traits<CHAR> >
305 public std::basic_istream<CHAR, TRAITS>
307 typedef std::basic_istream<CHAR, TRAITS> super;
317 { super::init(&m_Buf); }
328 #include "pqxx/compiler-internal-post.hxx"
unsigned int row_size_type
Definition: field.hxx:42
TRAITS traits_type
Definition: field.hxx:311
std::ios::seekdir seekdir
Definition: field.hxx:260
Definition: field.hxx:250
traits_type::pos_type pos_type
Definition: field.hxx:313
size_t idx() const PQXX_NOEXCEPT
Definition: field.hxx:201
const char * c_str() const
Read as plain C string.
Definition: field.cxx:72
Reference to one row in a result.
Definition: row.hxx:52
bool to(T &Obj, const T &Default) const
Read value into Obj; or use Default & return false if null.
Definition: field.hxx:149
Reference to a field in a result set.
Definition: field.hxx:51
traits_type::int_type int_type
Definition: field.hxx:312
virtual int_type overflow(int_type) PQXX_OVERRIDE
Definition: field.hxx:276
traits_type::pos_type pos_type
Definition: field.hxx:257
basic_fieldstream(const field &F)
Definition: field.hxx:316
virtual pos_type seekoff(off_type, seekdir, openmode) PQXX_OVERRIDE
Definition: field.hxx:272
bool to(T &Obj) const
Read value into Obj; or leave Obj untouched and return false if null.
Definition: field.hxx:125
row_size_type m_col
Definition: field.hxx:204
Input stream that gets its data from a result field.
Definition: field.hxx:304
virtual int sync() PQXX_OVERRIDE
Definition: field.hxx:269
signed int row_difference_type
Definition: field.hxx:45
traits_type::int_type int_type
Definition: field.hxx:256
basic_fieldstream< char > fieldstream
Definition: field.hxx:323
Traits class for use in string conversions.
Definition: strconv.hxx:46
virtual int_type underflow() PQXX_OVERRIDE
Definition: field.hxx:278
field_streambuf(const field &F)
Definition: field.hxx:262
T as() const
Return value as object of given type, or throw exception if null.
Definition: field.hxx:168
virtual pos_type seekpos(pos_type, openmode) PQXX_OVERRIDE
Definition: field.hxx:274
size_type size() const PQXX_NOEXCEPT
Return number of bytes taken up by the field's value.
Definition: field.cxx:84
std::ios::openmode openmode
Definition: field.hxx:259
traits_type::off_type off_type
Definition: field.hxx:258
size_t size_type
Definition: field.hxx:54
CHAR char_type
Definition: field.hxx:254
traits_type::off_type off_type
Definition: field.hxx:314
CHAR char_type
Definition: field.hxx:310
TRAITS traits_type
Definition: field.hxx:255
row_size_type col() const PQXX_NOEXCEPT
Definition: field.hxx:202
Result set containing data returned by a query or command.
Definition: result.hxx:78
row_size_type num() const
Definition: field.hxx:106
void from_string(const field &F, T &Obj)
Convert a field's string contents to another type.
Definition: result.hxx:459
T as(const T &Default) const
Return value as object of given type, or Default if null.
Definition: field.hxx:160
bool operator!=(const field &rhs) const
Byte-by-byte comparison (all nulls are considered equal)
Definition: field.hxx:89
bool operator>>(T &Obj) const
Read value into Obj; or leave Obj untouched and return false if null.
Definition: field.hxx:134