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 
28 class PQXX_LIBEXPORT tablereader : public tablestream
29 {
30 public:
33  const std::string &Name,
34  const std::string &Null=std::string());
35  template<typename ITER>
38  const std::string &Name,
39  ITER begincolumns,
40  ITER endcolumns);
41  template<typename ITER> tablereader(
43  const std::string &Name,
44  ITER begincolumns,
45  ITER endcolumns,
46  const std::string &Null);
47  ~tablereader() noexcept;
48  template<typename TUPLE> tablereader &operator>>(TUPLE &);
49  operator bool() const noexcept { return !m_done; }
50  bool operator!() const 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() override;
55 private:
56  void setup(
58  const std::string &RName,
59  const std::string &Columns=std::string());
60  PQXX_PRIVATE void reader_close();
61  std::string extract_field(
62  const std::string &,
63  std::string::size_type &) const;
64  bool m_done;
65 };
66 
67 
68 template<typename ITER> inline
71  const std::string &Name,
72  ITER begincolumns,
73  ITER endcolumns) :
74  namedclass(Name, "tablereader"),
75  tablestream(T, std::string()),
76  m_done(true)
77 {
78  setup(T, Name, columnlist(begincolumns, endcolumns));
79 }
80 
81 
82 template<typename ITER> inline
85  const std::string &Name,
86  ITER begincolumns,
87  ITER endcolumns,
88  const std::string &Null) :
89  namedclass(Name, "tablereader"),
90  tablestream(T, Null),
91  m_done(true)
92 {
93  setup(T, Name, columnlist(begincolumns, endcolumns));
94 }
95 
96 
97 template<typename TUPLE>
98 inline void tablereader::tokenize(std::string Line, TUPLE &T) const
99 {
100  std::back_insert_iterator<TUPLE> ins = std::back_inserter(T);
101  std::string::size_type here=0;
102  while (here < Line.size()) *ins++ = extract_field(Line, here);
103 }
104 
105 
106 template<typename TUPLE>
108 {
109  std::string Line;
110  if (get_raw_line(Line)) tokenize(Line, T);
111  return *this;
112 }
113 } // namespace pqxx
114 
115 #include "pqxx/compiler-internal-post.hxx"
116 #endif
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:22
namedclass(const std::string &Classname)
Definition: util.hxx:170
tablereader & operator>>(TUPLE &)
Definition: tablereader.hxx:107
bool operator!() const noexcept
Definition: tablereader.hxx:50
Definition: tablestream.hxx:24
Interface definition (and common code) for "transaction" classes.
Definition: transaction_base.hxx:130
Definition: tablereader.hxx:28
STL namespace.
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:49
bool get_raw_line(std::string &Line)
Definition: tablereader.cxx:55
void tokenize(std::string, TUPLE &) const
Definition: tablereader.hxx:98