Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | 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 <string>
00020 
00021 #include "pqxx/result"
00022 #include "pqxx/tablestream"
00023 
00024 /* Methods tested in eg. self-test program test001 are marked with "//[t1]"
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());                       //[t6]
00049   ~tablereader() throw ();                                              //[t6]
00050 
00051   template<typename TUPLE> tablereader &operator>>(TUPLE &);            //[t8]
00052 
00053   operator bool() const throw () { return !m_Done; }                    //[t6]
00054   bool operator!() const throw () { return m_Done; }                    //[t6]
00055 
00057 
00060   bool get_raw_line(PGSTD::string &Line);                               //[t8]
00061 
00062   template<typename TUPLE> 
00063   void tokenize(PGSTD::string, TUPLE &) const;                          //[t8]
00064 
00066 
00073   virtual void complete();                                              //[t8]
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 // TODO: Find meaningful definition of input iterator
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   // Filter and tokenize line, inserting tokens at end of T
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 

Generated on Thu Feb 19 22:04:36 2004 for libpqxx by doxygen 1.3.5