libpqxx  4.0.1
tablereader.hxx
1 /*-------------------------------------------------------------------------
2  *
3  * FILE
4  * pqxx/tablereader.hxx
5  *
6  * DESCRIPTION
7  * definition of the pqxx::tablereader class.
8  * pqxx::tablereader enables optimized batch reads from a database table
9  * DO NOT INCLUDE THIS FILE DIRECTLY; include pqxx/tablereader instead.
10  *
11  * Copyright (c) 2001-2011, Jeroen T. Vermeulen <jtv@xs4all.nl>
12  *
13  * See COPYING for copyright license. If you did not receive a file called
14  * COPYING with this source code, please notify the distributor of this mistake,
15  * or contact the author.
16  *
17  *-------------------------------------------------------------------------
18  */
19 #ifndef PQXX_H_TABLEREADER
20 #define PQXX_H_TABLEREADER
21 #include "pqxx/compiler-public.hxx"
22 #include "pqxx/compiler-internal-pre.hxx"
23 #include "pqxx/result"
24 #include "pqxx/tablestream"
25 namespace pqxx
26 {
28 
31 class PQXX_LIBEXPORT tablereader : public tablestream
32 {
33 public:
35  const PGSTD::string &Name,
36  const PGSTD::string &Null=PGSTD::string());
37  template<typename ITER>
39  const PGSTD::string &Name,
40  ITER begincolumns,
41  ITER endcolumns);
42  template<typename ITER> tablereader(transaction_base &,
43  const PGSTD::string &Name,
44  ITER begincolumns,
45  ITER endcolumns,
46  const PGSTD::string &Null);
47  ~tablereader() throw ();
48  template<typename TUPLE> tablereader &operator>>(TUPLE &);
49  operator bool() const throw () { return !m_Done; }
50  bool operator!() const throw () { return m_Done; }
51  bool get_raw_line(PGSTD::string &Line);
52  template<typename TUPLE>
53  void tokenize(PGSTD::string, TUPLE &) const;
54  virtual void complete();
55 private:
56  void setup(transaction_base &T,
57  const PGSTD::string &RName,
58  const PGSTD::string &Columns=PGSTD::string());
59  void PQXX_PRIVATE reader_close();
60  PGSTD::string extract_field(const PGSTD::string &,
61  PGSTD::string::size_type &) const;
62  bool m_Done;
63 };
64 template<typename ITER> inline
66  const PGSTD::string &Name,
67  ITER begincolumns,
68  ITER endcolumns) :
69  namedclass(Name, "tablereader"),
70  tablestream(T, PGSTD::string()),
71  m_Done(true)
72 {
73  setup(T, Name, columnlist(begincolumns, endcolumns));
74 }
75 template<typename ITER> inline
77  const PGSTD::string &Name,
78  ITER begincolumns,
79  ITER endcolumns,
80  const PGSTD::string &Null) :
81  namedclass(Name, "tablereader"),
82  tablestream(T, Null),
83  m_Done(true)
84 {
85  setup(T, Name, columnlist(begincolumns, endcolumns));
86 }
87 template<typename TUPLE>
88 inline void tablereader::tokenize(PGSTD::string Line, TUPLE &T) const
89 {
90  PGSTD::back_insert_iterator<TUPLE> ins = PGSTD::back_inserter(T);
91  PGSTD::string::size_type here=0;
92  while (here < Line.size()) *ins++ = extract_field(Line, here);
93 }
94 template<typename TUPLE>
96 {
97  PGSTD::string Line;
98  if (get_raw_line(Line)) tokenize(Line, T);
99  return *this;
100 }
101 } // namespace pqxx
102 #include "pqxx/compiler-internal-post.hxx"
103 #endif