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-2006, 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/compiler-public.hxx"
00020 #include "pqxx/compiler-internal-pre.hxx"
00021 
00022 #include "pqxx/result"
00023 #include "pqxx/tablestream"
00024 
00025 /* Methods tested in eg. self-test program test001 are marked with "//[t1]"
00026  */
00027 
00028 namespace pqxx
00029 {
00030 
00032 
00046 class PQXX_LIBEXPORT tablereader : public tablestream
00047 {
00048 public:
00049   tablereader(transaction_base &,
00050       const PGSTD::string &Name,
00051       const PGSTD::string &Null=PGSTD::string());                       //[t6]
00052 
00054 
00056   template<typename ITER>
00057   tablereader(transaction_base &,
00058       const PGSTD::string &Name,
00059       ITER begincolumns,
00060       ITER endcolumns);                                                 //[t80]
00061 
00062   template<typename ITER> tablereader(transaction_base &,
00063       const PGSTD::string &Name,
00064       ITER begincolumns,
00065       ITER endcolumns,
00066       const PGSTD::string &Null);                                       //[t80]
00067 
00068   ~tablereader() throw ();                                              //[t6]
00069 
00070   template<typename TUPLE> tablereader &operator>>(TUPLE &);            //[t8]
00071 
00072   operator bool() const throw () { return !m_Done; }                    //[t6]
00073   bool operator!() const throw () { return m_Done; }                    //[t6]
00074 
00076 
00080   bool get_raw_line(PGSTD::string &Line);                               //[t8]
00081 
00082   template<typename TUPLE>
00083   void tokenize(PGSTD::string, TUPLE &) const;                          //[t8]
00084 
00086 
00093   virtual void complete();                                              //[t8]
00094 
00095 #ifdef PQXX_DEPRECATED_HEADERS
00096 
00097   bool GetRawLine(PGSTD::string &L) PQXX_DEPRECATED { return get_raw_line(L); }
00099   template<typename TUPLE> void Tokenize(PGSTD::string L, TUPLE &T) const
00100         PQXX_DEPRECATED { tokenize(L, T); }
00101 #endif
00102 
00103 private:
00104   void setup(transaction_base &T,
00105       const PGSTD::string &RName,
00106       const PGSTD::string &Columns=PGSTD::string());
00107   void PQXX_PRIVATE reader_close();
00108   PGSTD::string extract_field(const PGSTD::string &,
00109       PGSTD::string::size_type &) const;
00110 
00111   bool m_Done;
00112 };
00113 
00114 
00115 // TODO: Find meaningful definition of input iterator
00116 
00117 
00118 template<typename ITER> inline
00119 tablereader::tablereader(transaction_base &T,
00120     const PGSTD::string &Name,
00121     ITER begincolumns,
00122     ITER endcolumns) :
00123   namedclass(Name, "tablereader"),
00124   tablestream(T, PGSTD::string()),
00125   m_Done(true)
00126 {
00127   setup(T, Name, columnlist(begincolumns, endcolumns));
00128 }
00129 
00130 template<typename ITER> inline
00131 tablereader::tablereader(transaction_base &T,
00132     const PGSTD::string &Name,
00133     ITER begincolumns,
00134     ITER endcolumns,
00135     const PGSTD::string &Null) :
00136   namedclass(Name, "tablereader"),
00137   tablestream(T, Null),
00138   m_Done(true)
00139 {
00140   setup(T, Name, columnlist(begincolumns, endcolumns));
00141 }
00142 
00143 
00144 template<typename TUPLE>
00145 inline void tablereader::tokenize(PGSTD::string Line, TUPLE &T) const
00146 {
00147   PGSTD::back_insert_iterator<TUPLE> ins = PGSTD::back_inserter(T);
00148 
00149   // Filter and tokenize line, inserting tokens at end of T
00150   PGSTD::string::size_type here=0;
00151   while (here < Line.size()) *ins++ = extract_field(Line, here);
00152 }
00153 
00154 
00155 template<typename TUPLE>
00156 inline tablereader &pqxx::tablereader::operator>>(TUPLE &T)
00157 {
00158   PGSTD::string Line;
00159   if (get_raw_line(Line)) tokenize(Line, T);
00160   return *this;
00161 }
00162 
00163 
00164 } // namespace pqxx
00165 
00166 #include "pqxx/compiler-internal-post.hxx"

Generated on Sun Jun 18 14:51:00 2006 for libpqxx by  doxygen 1.4.6