tablereader.hxx
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef PQXX_H_TABLEREADER
00020 #define PQXX_H_TABLEREADER
00021
00022 #include "pqxx/compiler-public.hxx"
00023 #include "pqxx/compiler-internal-pre.hxx"
00024
00025 #include "pqxx/result"
00026 #include "pqxx/tablestream"
00027
00028
00029
00030
00031 namespace pqxx
00032 {
00033
00035
00049 class PQXX_LIBEXPORT tablereader : public tablestream
00050 {
00051 public:
00052 tablereader(transaction_base &,
00053 const PGSTD::string &Name,
00054 const PGSTD::string &Null=PGSTD::string());
00055
00057
00059 template<typename ITER>
00060 tablereader(transaction_base &,
00061 const PGSTD::string &Name,
00062 ITER begincolumns,
00063 ITER endcolumns);
00064
00065 template<typename ITER> tablereader(transaction_base &,
00066 const PGSTD::string &Name,
00067 ITER begincolumns,
00068 ITER endcolumns,
00069 const PGSTD::string &Null);
00070
00071 ~tablereader() throw ();
00072
00073 template<typename TUPLE> tablereader &operator>>(TUPLE &);
00074
00075 operator bool() const throw () { return !m_Done; }
00076 bool operator!() const throw () { return m_Done; }
00077
00079
00083 bool get_raw_line(PGSTD::string &Line);
00084
00085 template<typename TUPLE>
00086 void tokenize(PGSTD::string, TUPLE &) const;
00087
00089
00096 virtual void complete();
00097
00098 private:
00099 void setup(transaction_base &T,
00100 const PGSTD::string &RName,
00101 const PGSTD::string &Columns=PGSTD::string());
00102 void PQXX_PRIVATE reader_close();
00103 PGSTD::string extract_field(const PGSTD::string &,
00104 PGSTD::string::size_type &) const;
00105
00106 bool m_Done;
00107 };
00108
00109
00110
00111
00112
00113 template<typename ITER> inline
00114 tablereader::tablereader(transaction_base &T,
00115 const PGSTD::string &Name,
00116 ITER begincolumns,
00117 ITER endcolumns) :
00118 namedclass(Name, "tablereader"),
00119 tablestream(T, PGSTD::string()),
00120 m_Done(true)
00121 {
00122 setup(T, Name, columnlist(begincolumns, endcolumns));
00123 }
00124
00125 template<typename ITER> inline
00126 tablereader::tablereader(transaction_base &T,
00127 const PGSTD::string &Name,
00128 ITER begincolumns,
00129 ITER endcolumns,
00130 const PGSTD::string &Null) :
00131 namedclass(Name, "tablereader"),
00132 tablestream(T, Null),
00133 m_Done(true)
00134 {
00135 setup(T, Name, columnlist(begincolumns, endcolumns));
00136 }
00137
00138
00139 template<typename TUPLE>
00140 inline void tablereader::tokenize(PGSTD::string Line, TUPLE &T) const
00141 {
00142 PGSTD::back_insert_iterator<TUPLE> ins = PGSTD::back_inserter(T);
00143
00144
00145 PGSTD::string::size_type here=0;
00146 while (here < Line.size()) *ins++ = extract_field(Line, here);
00147 }
00148
00149
00150 template<typename TUPLE>
00151 inline tablereader &pqxx::tablereader::operator>>(TUPLE &T)
00152 {
00153 PGSTD::string Line;
00154 if (get_raw_line(Line)) tokenize(Line, T);
00155 return *this;
00156 }
00157
00158
00159 }
00160
00161 #include "pqxx/compiler-internal-post.hxx"
00162
00163 #endif
00164