00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 #include "pqxx/libcompiler.h"
00020 
00021 #include "pqxx/result"
00022 #include "pqxx/tablestream"
00023 
00024 
00025 
00026 
00027 namespace pqxx
00028 {
00029 
00031 
00045 class PQXX_LIBEXPORT tablereader : public tablestream
00046 {
00047 public:
00048   tablereader(transaction_base &,
00049       const PGSTD::string &RName,
00050       const PGSTD::string &Null=PGSTD::string());                       
00051 
00053 
00055   template<typename ITER>
00056   tablereader(transaction_base &,
00057       const PGSTD::string &RName,
00058       ITER begincolumns,
00059       ITER endcolumns,
00060       const PGSTD::string &Null=PGSTD::string());                       
00061 
00062   ~tablereader() throw ();                                              
00063 
00064   template<typename TUPLE> tablereader &operator>>(TUPLE &);            
00065 
00066   operator bool() const throw () { return !m_Done; }                    
00067   bool operator!() const throw () { return m_Done; }                    
00068 
00070 
00074   bool get_raw_line(PGSTD::string &Line);                               
00075 
00076   template<typename TUPLE>
00077   void tokenize(PGSTD::string, TUPLE &) const;                          
00078 
00080 
00087   virtual void complete();                                              
00088 
00089 #ifdef PQXX_DEPRECATED_HEADERS
00090 
00091   bool GetRawLine(PGSTD::string &L) { return get_raw_line(L); }
00093   template<typename TUPLE> void Tokenize(PGSTD::string L, TUPLE &T) const
00094         { tokenize(L, T); }
00095 #endif
00096 
00097 private:
00098   void setup(transaction_base &T,
00099       const PGSTD::string &RName,
00100       const PGSTD::string &Columns=PGSTD::string());
00101   void PQXX_PRIVATE reader_close();
00102   PGSTD::string extract_field(const PGSTD::string &,
00103       PGSTD::string::size_type &) const;
00104 
00105   bool m_Done;
00106 };
00107 
00108 
00109 
00110 
00111 
00112 template<typename ITER> inline
00113 tablereader::tablereader(transaction_base &T,
00114     const PGSTD::string &RName,
00115     ITER begincolumns,
00116     ITER endcolumns,
00117     const PGSTD::string &Null) :
00118   tablestream(T, RName, Null, "tablereader"),
00119   m_Done(true)
00120 {
00121   setup(T, RName, columnlist(begincolumns, endcolumns));
00122 }
00123 
00124 
00125 template<typename TUPLE>
00126 inline void tablereader::tokenize(PGSTD::string Line, TUPLE &T) const
00127 {
00128   PGSTD::back_insert_iterator<TUPLE> ins = PGSTD::back_inserter(T);
00129 
00130   
00131   PGSTD::string::size_type here=0;
00132   while (here < Line.size()) *ins++ = extract_field(Line, here);
00133 }
00134 
00135 
00136 template<typename TUPLE>
00137 inline tablereader &pqxx::tablereader::operator>>(TUPLE &T)
00138 {
00139   PGSTD::string Line;
00140   if (get_raw_line(Line)) tokenize(Line, T);
00141   return *this;
00142 }
00143 
00144 
00145 } 
00146