libpqxx  5.0
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-2015, 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 std::string &Name,
36  const std::string &Null=std::string());
37  template<typename ITER>
39  const std::string &Name,
40  ITER begincolumns,
41  ITER endcolumns);
42  template<typename ITER> tablereader(transaction_base &,
43  const std::string &Name,
44  ITER begincolumns,
45  ITER endcolumns,
46  const std::string &Null);
47  ~tablereader() PQXX_NOEXCEPT;
48  template<typename TUPLE> tablereader &operator>>(TUPLE &);
49  operator bool() const PQXX_NOEXCEPT { return !m_Done; }
50  bool operator!() const PQXX_NOEXCEPT { return m_Done; }
51  bool get_raw_line(std::string &Line);
52  template<typename TUPLE>
53  void tokenize(std::string, TUPLE &) const;
54  virtual void complete() PQXX_OVERRIDE;
55 private:
56  void setup(transaction_base &T,
57  const std::string &RName,
58  const std::string &Columns=std::string());
59  PQXX_PRIVATE void reader_close();
60  std::string extract_field(
61  const std::string &,
62  std::string::size_type &) const;
63  bool m_Done;
64 };
65 template<typename ITER> inline
67  const std::string &Name,
68  ITER begincolumns,
69  ITER endcolumns) :
70  namedclass(Name, "tablereader"),
71  tablestream(T, std::string()),
72  m_Done(true)
73 {
74  setup(T, Name, columnlist(begincolumns, endcolumns));
75 }
76 template<typename ITER> inline
78  const std::string &Name,
79  ITER begincolumns,
80  ITER endcolumns,
81  const std::string &Null) :
82  namedclass(Name, "tablereader"),
83  tablestream(T, Null),
84  m_Done(true)
85 {
86  setup(T, Name, columnlist(begincolumns, endcolumns));
87 }
88 template<typename TUPLE>
89 inline void tablereader::tokenize(std::string Line, TUPLE &T) const
90 {
91  std::back_insert_iterator<TUPLE> ins = std::back_inserter(T);
92  std::string::size_type here=0;
93  while (here < Line.size()) *ins++ = extract_field(Line, here);
94 }
95 template<typename TUPLE>
97 {
98  std::string Line;
99  if (get_raw_line(Line)) tokenize(Line, T);
100  return *this;
101 }
102 } // namespace pqxx
103 #include "pqxx/compiler-internal-post.hxx"
104 #endif
tablereader & operator>>(TUPLE &)
Definition: tablereader.hxx:96
Definition: tablereader.hxx:31
tablereader(transaction_base &, const std::string &Name, const std::string &Null=std::string())
Definition: tablereader.cxx:28
bool operator!() const PQXX_NOEXCEPT
Definition: tablereader.hxx:50
static std::string columnlist(ITER colbegin, ITER colend)
Definition: tablestream.hxx:50
void tokenize(std::string, TUPLE &) const
Definition: tablereader.hxx:89
Definition: tablestream.hxx:28
Definition: transaction_base.hxx:133