libpqxx
tablereader.hxx
1 
13 #ifndef PQXX_H_TABLEREADER
14 #define PQXX_H_TABLEREADER
15 
16 #include "pqxx/compiler-public.hxx"
17 #include "pqxx/compiler-internal-pre.hxx"
18 #include "pqxx/result.hxx"
19 #include "pqxx/tablestream.hxx"
20 
21 
22 namespace pqxx
23 {
25 
29 class PQXX_LIBEXPORT tablereader : public tablestream
30 {
31 public:
32  PQXX_DEPRECATED tablereader(
34  const std::string &Name,
35  const std::string &Null=std::string{});
36  template<typename ITER>
37  PQXX_DEPRECATED tablereader(
39  const std::string &Name,
40  ITER begincolumns,
41  ITER endcolumns);
42  template<typename ITER>
43  PQXX_DEPRECATED tablereader(
45  const std::string &Name,
46  ITER begincolumns,
47  ITER endcolumns,
48  const std::string &Null);
49  ~tablereader() noexcept;
50  template<typename TUPLE> tablereader &operator>>(TUPLE &);
51  operator bool() const noexcept { return not m_done; }
52  bool operator!() const noexcept { return m_done; }
53  bool get_raw_line(std::string &Line);
54  template<typename TUPLE>
55  void tokenize(std::string, TUPLE &) const;
56  virtual void complete() override;
57 private:
58  void set_up(
60  const std::string &RName,
61  const std::string &Columns=std::string{});
62  PQXX_PRIVATE void reader_close();
63  std::string extract_field(
64  const std::string &,
65  std::string::size_type &) const;
66  bool m_done;
67 };
68 
69 
70 template<typename ITER> inline
73  const std::string &Name,
74  ITER begincolumns,
75  ITER endcolumns) :
76  namedclass{Name, "tablereader"},
77  tablestream{T, std::string{}},
78  m_done{true}
79 {
80  set_up(T, Name, columnlist(begincolumns, endcolumns));
81 }
82 
83 
84 template<typename ITER> inline
87  const std::string &Name,
88  ITER begincolumns,
89  ITER endcolumns,
90  const std::string &Null) :
91  namedclass{Name, "tablereader"},
92  tablestream{T, Null},
93  m_done{true}
94 {
95  set_up(T, Name, columnlist(begincolumns, endcolumns));
96 }
97 
98 
99 template<typename TUPLE>
100 inline void tablereader::tokenize(std::string Line, TUPLE &T) const
101 {
102  std::back_insert_iterator<TUPLE> ins = std::back_inserter(T);
103  std::string::size_type here = 0;
104  while (here < Line.size()) *ins++ = extract_field(Line, here);
105 }
106 
107 
108 template<typename TUPLE>
110 {
111  std::string Line;
112  if (get_raw_line(Line)) tokenize(Line, T);
113  return *this;
114 }
115 } // namespace pqxx
116 
117 #include "pqxx/compiler-internal-post.hxx"
118 #endif
Interface definition (and common code) for "transaction" classes.
Definition: transaction_base.hxx:136
namedclass(const std::string &Classname)
Definition: util.hxx:248
Base class for obsolete tablereader/tablewriter classes.
Definition: tablestream.hxx:26
tablereader(transaction_base &, const std::string &Name, const std::string &Null=std::string{})
Definition: tablereader.cxx:21
static std::string columnlist(ITER colbegin, ITER colend)
Definition: tablestream.hxx:52
Definition: tablereader.hxx:29
tablereader & operator>>(TUPLE &)
Definition: tablereader.hxx:109
void tokenize(std::string, TUPLE &) const
Definition: tablereader.hxx:100
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:25
bool operator!() const noexcept
Definition: tablereader.hxx:52
bool get_raw_line(std::string &Line)
Definition: tablereader.cxx:55