00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
#include <string>
00020 
00021 
#include "pqxx/result"
00022 
#include "pqxx/tablestream"
00023 
00024 
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());                       
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());                       
00059 
00060   ~tablereader() 
throw ();                                              
00061 
00062   
template<
typename TUPLE> tablereader &operator>>(TUPLE &);            
00063 
00064   operator bool() const throw () { 
return !m_Done; }                    
00065   bool operator!() const throw () { 
return m_Done; }                    
00066 
00068 
00071   
bool get_raw_line(PGSTD::string &Line);                               
00072 
00073   
template<
typename TUPLE> 
00074   
void tokenize(PGSTD::string, TUPLE &) const;                          
00075 
00077 
00084   virtual 
void complete();                                              
00085 
00086 #ifdef PQXX_DEPRECATED_HEADERS
00088   
bool GetRawLine(PGSTD::string &L) { 
return get_raw_line(L); }
00090   
template<
typename TUPLE> 
void Tokenize(PGSTD::string L, TUPLE &T)
 const
00091 
        { tokenize(L, T); }
00092 
#endif
00093 
00094 
private:
00095   
void setup(transaction_base &T,
00096       
const PGSTD::string &RName,
00097       
const PGSTD::string &Columns=PGSTD::string());
00098   
void reader_close();
00099   PGSTD::string extract_field(
const PGSTD::string &, 
00100       PGSTD::string::size_type &) const;
00101 
00102   
bool m_Done;
00103 };
00104 
00105 
00106 
00107 
00108 
00109 template<typename ITER> inline
00110 tablereader::tablereader(
transaction_base &T, 
00111     const PGSTD::string &RName,
00112     ITER begincolumns,
00113     ITER endcolumns,
00114     const PGSTD::string &Null) :
00115   
tablestream(T, RName, Null, "tablereader"),
00116   m_Done(true)
00117 {
00118   setup(T, RName, columnlist(begincolumns, endcolumns));
00119 }
00120 
00121 
00122 
template<
typename TUPLE> 
00123 inline void tablereader::tokenize(PGSTD::string Line, TUPLE &T)
 const
00124 
{
00125   PGSTD::back_insert_iterator<TUPLE> ins = PGSTD::back_inserter(T);
00126 
00127   
00128   PGSTD::string::size_type here=0;
00129   
while (here < Line.size()) *ins++ = extract_field(Line, here);
00130 }
00131 
00132 
00133 
template<
typename TUPLE> 
00134 inline tablereader &
pqxx::tablereader::operator>>(TUPLE &T)
00135 {
00136   PGSTD::string Line;
00137   
if (
get_raw_line(Line)) 
tokenize(Line, T);
00138   
return *
this;
00139 }
00140 
00141 
00142 } 
00143