Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

tablereader.hxx

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  *   FILE
00004  *      pqxx/tablereader.hxx
00005  *
00006  *   DESCRIPTION
00007  *      definition of the pqxx::tablereader class.
00008  *   pqxx::tablereader enables optimized batch reads from a database table
00009  *   DO NOT INCLUDE THIS FILE DIRECTLY; include pqxx/tablereader instead.
00010  *
00011  * Copyright (c) 2001-2004, Jeroen T. Vermeulen <jtv@xs4all.nl>
00012  *
00013  * See COPYING for copyright license.  If you did not receive a file called
00014  * COPYING with this source code, please notify the distributor of this mistake,
00015  * or contact the author.
00016  *
00017  *-------------------------------------------------------------------------
00018  */
00019 #include "pqxx/result"
00020 #include "pqxx/tablestream"
00021 
00022 /* Methods tested in eg. self-test program test001 are marked with "//[t1]"
00023  */
00024 
00025 namespace pqxx
00026 {
00027 
00029 
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());                       //[t6]
00049 
00051 
00053   template<typename ITER>
00054   tablereader(transaction_base &, 
00055       const PGSTD::string &RName,
00056       ITER begincolumns,
00057       ITER endcolumns,
00058       const PGSTD::string &Null=PGSTD::string());                       //[t80]
00059 
00060   ~tablereader() throw ();                                              //[t6]
00061 
00062   template<typename TUPLE> tablereader &operator>>(TUPLE &);            //[t8]
00063 
00064   operator bool() const throw () { return !m_Done; }                    //[t6]
00065   bool operator!() const throw () { return m_Done; }                    //[t6]
00066 
00068 
00072   bool get_raw_line(PGSTD::string &Line);                               //[t8]
00073 
00074   template<typename TUPLE> 
00075   void tokenize(PGSTD::string, TUPLE &) const;                          //[t8]
00076 
00078 
00085   virtual void complete();                                              //[t8]
00086 
00087 #ifdef PQXX_DEPRECATED_HEADERS
00088 
00089   bool GetRawLine(PGSTD::string &L) { return get_raw_line(L); }
00091   template<typename TUPLE> void Tokenize(PGSTD::string L, TUPLE &T) const
00092         { tokenize(L, T); }
00093 #endif
00094 
00095 private:
00096   void setup(transaction_base &T,
00097       const PGSTD::string &RName,
00098       const PGSTD::string &Columns=PGSTD::string());
00099   void reader_close();
00100   PGSTD::string extract_field(const PGSTD::string &, 
00101       PGSTD::string::size_type &) const;
00102 
00103   bool m_Done;
00104 };
00105 
00106 
00107 // TODO: Find meaningful definition of input iterator
00108 
00109 
00110 template<typename ITER> inline
00111 tablereader::tablereader(transaction_base &T, 
00112     const PGSTD::string &RName,
00113     ITER begincolumns,
00114     ITER endcolumns,
00115     const PGSTD::string &Null) :
00116   tablestream(T, RName, Null, "tablereader"),
00117   m_Done(true)
00118 {
00119   setup(T, RName, columnlist(begincolumns, endcolumns));
00120 }
00121 
00122 
00123 template<typename TUPLE> 
00124 inline void tablereader::tokenize(PGSTD::string Line, TUPLE &T) const
00125 {
00126   PGSTD::back_insert_iterator<TUPLE> ins = PGSTD::back_inserter(T);
00127 
00128   // Filter and tokenize line, inserting tokens at end of T
00129   PGSTD::string::size_type here=0;
00130   while (here < Line.size()) *ins++ = extract_field(Line, here);
00131 }
00132 
00133 
00134 template<typename TUPLE> 
00135 inline tablereader &pqxx::tablereader::operator>>(TUPLE &T)
00136 {
00137   PGSTD::string Line;
00138   if (get_raw_line(Line)) tokenize(Line, T);
00139   return *this;
00140 }
00141 
00142 
00143 } // namespace pqxx
00144 

Generated on Mon Nov 15 11:28:00 2004 for libpqxx by  doxygen 1.3.9.1