00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <string>
00020
00021 #include "pqxx/result"
00022 #include "pqxx/tablestream"
00023
00024
00025
00026
00027 namespace pqxx
00028 {
00029
00031
00043 class PQXX_LIBEXPORT tablereader : public tablestream
00044 {
00045 public:
00046 tablereader(transaction_base &,
00047 const PGSTD::string &RName,
00048 const PGSTD::string &Null=PGSTD::string());
00049 ~tablereader();
00050
00051 template<typename TUPLE> tablereader &operator>>(TUPLE &);
00052
00053 operator bool() const throw () { return !m_Done; }
00054 bool operator!() const throw () { return m_Done; }
00055
00057
00060 bool get_raw_line(PGSTD::string &Line);
00061
00062 template<typename TUPLE>
00063 void tokenize(PGSTD::string, TUPLE &) const;
00064
00066
00073 virtual void complete();
00074
00075 #ifdef PQXX_DEPRECATED_HEADERS
00076
00077 bool GetRawLine(PGSTD::string &L) { return get_raw_line(L); }
00079 template<typename TUPLE> void Tokenize(PGSTD::string L, TUPLE &T) const
00080 { tokenize(L, T); }
00081 #endif
00082
00083 private:
00084 void reader_close();
00085 PGSTD::string extract_field(const PGSTD::string &,
00086 PGSTD::string::size_type &) const;
00087
00088 bool m_Done;
00089 };
00090
00091
00092 }
00093
00094
00095
00096
00097 template<typename TUPLE>
00098 inline void pqxx::tablereader::tokenize(PGSTD::string Line, TUPLE &T) const
00099 {
00100 PGSTD::back_insert_iterator<TUPLE> ins = PGSTD::back_inserter(T);
00101
00102
00103 PGSTD::string::size_type here=0;
00104 while (here < Line.size()) *ins++ = extract_field(Line, here);
00105 }
00106
00107
00108 template<typename TUPLE>
00109 inline pqxx::tablereader &pqxx::tablereader::operator>>(TUPLE &T)
00110 {
00111 PGSTD::string Line;
00112 if (get_raw_line(Line)) tokenize(Line, T);
00113 return *this;
00114 }
00115
00116