tablereader.hxx

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-2015, 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 #ifndef PQXX_H_TABLEREADER
00020 #define PQXX_H_TABLEREADER
00021 #include "pqxx/compiler-public.hxx"
00022 #include "pqxx/compiler-internal-pre.hxx"
00023 #include "pqxx/result"
00024 #include "pqxx/tablestream"
00025 namespace pqxx
00026 {
00028 
00031 class PQXX_LIBEXPORT tablereader : public tablestream
00032 {
00033 public:
00034   tablereader(transaction_base &,
00035       const std::string &Name,
00036       const std::string &Null=std::string());
00037   template<typename ITER>
00038   tablereader(transaction_base &,
00039       const std::string &Name,
00040       ITER begincolumns,
00041       ITER endcolumns);
00042   template<typename ITER> tablereader(transaction_base &,
00043       const std::string &Name,
00044       ITER begincolumns,
00045       ITER endcolumns,
00046       const std::string &Null);
00047   ~tablereader() PQXX_NOEXCEPT;
00048   template<typename TUPLE> tablereader &operator>>(TUPLE &);
00049   operator bool() const PQXX_NOEXCEPT { return !m_Done; }
00050   bool operator!() const PQXX_NOEXCEPT { return m_Done; }
00051   bool get_raw_line(std::string &Line);
00052   template<typename TUPLE>
00053   void tokenize(std::string, TUPLE &) const;
00054   virtual void complete() PQXX_OVERRIDE;
00055 private:
00056   void setup(transaction_base &T,
00057       const std::string &RName,
00058       const std::string &Columns=std::string());
00059   PQXX_PRIVATE void reader_close();
00060   std::string extract_field(
00061         const std::string &,
00062         std::string::size_type &) const;
00063   bool m_Done;
00064 };
00065 template<typename ITER> inline
00066 tablereader::tablereader(transaction_base &T,
00067     const std::string &Name,
00068     ITER begincolumns,
00069     ITER endcolumns) :
00070   namedclass(Name, "tablereader"),
00071   tablestream(T, std::string()),
00072   m_Done(true)
00073 {
00074   setup(T, Name, columnlist(begincolumns, endcolumns));
00075 }
00076 template<typename ITER> inline
00077 tablereader::tablereader(transaction_base &T,
00078     const std::string &Name,
00079     ITER begincolumns,
00080     ITER endcolumns,
00081     const std::string &Null) :
00082   namedclass(Name, "tablereader"),
00083   tablestream(T, Null),
00084   m_Done(true)
00085 {
00086   setup(T, Name, columnlist(begincolumns, endcolumns));
00087 }
00088 template<typename TUPLE>
00089 inline void tablereader::tokenize(std::string Line, TUPLE &T) const
00090 {
00091   std::back_insert_iterator<TUPLE> ins = std::back_inserter(T);
00092   std::string::size_type here=0;
00093   while (here < Line.size()) *ins++ = extract_field(Line, here);
00094 }
00095 template<typename TUPLE>
00096 inline tablereader &pqxx::tablereader::operator>>(TUPLE &T)
00097 {
00098   std::string Line;
00099   if (get_raw_line(Line)) tokenize(Line, T);
00100   return *this;
00101 }
00102 } // namespace pqxx
00103 #include "pqxx/compiler-internal-post.hxx"
00104 #endif

Generated on 16 Mar 2017 for libpqxx by  doxygen 1.6.1