2017-12-09 10:45:13 +01:00
|
|
|
|
#ifndef PGSQL_COL_H
|
|
|
|
|
|
#define PGSQL_COL_H
|
|
|
|
|
|
|
|
|
|
|
|
#include "Pgsql_Row.h"
|
2018-11-17 19:36:12 +01:00
|
|
|
|
#include <boost/container/small_vector.hpp>
|
2017-12-09 10:45:13 +01:00
|
|
|
|
|
|
|
|
|
|
namespace Pgsql {
|
|
|
|
|
|
|
|
|
|
|
|
class Col {
|
|
|
|
|
|
public:
|
2017-12-12 20:13:53 +01:00
|
|
|
|
explicit Col(const Pgsql::Row &r)
|
2017-12-09 10:45:13 +01:00
|
|
|
|
: row(r)
|
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
void reset() { col = -1; }
|
2017-12-17 11:27:42 +01:00
|
|
|
|
|
2017-12-09 10:45:13 +01:00
|
|
|
|
Pgsql::Value nextValue()
|
|
|
|
|
|
{
|
|
|
|
|
|
return row.get(++col);
|
|
|
|
|
|
}
|
2017-12-17 11:27:42 +01:00
|
|
|
|
|
2023-02-06 20:03:57 +01:00
|
|
|
|
void skip(int n = 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
col += n;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-17 11:27:42 +01:00
|
|
|
|
template <typename E, typename I>
|
|
|
|
|
|
Col& getAsArray(I insert_iter, NullHandling nullhandling = NullHandling::Throw)
|
|
|
|
|
|
{
|
|
|
|
|
|
nextValue().getAsArray<E, I>(insert_iter, nullhandling);
|
|
|
|
|
|
return *this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename E, typename I>
|
2018-09-19 08:25:23 +02:00
|
|
|
|
Col& getAsArray(I insert_iter, const E &value_for_nulls)
|
2017-12-17 11:27:42 +01:00
|
|
|
|
{
|
|
|
|
|
|
nextValue().getAsArray<E, I>(insert_iter, value_for_nulls);
|
|
|
|
|
|
return *this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename E, typename I>
|
2018-09-19 08:25:23 +02:00
|
|
|
|
Col& getAsArrayOfOptional(I insert_iter)
|
2017-12-17 11:27:42 +01:00
|
|
|
|
{
|
|
|
|
|
|
nextValue().getAsArrayOfOptional<E, I>(insert_iter);
|
|
|
|
|
|
return *this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename E, typename I>
|
|
|
|
|
|
Col& getAsVector(I insert_iter)
|
|
|
|
|
|
{
|
|
|
|
|
|
nextValue().getAsVector<E, I>(insert_iter);
|
|
|
|
|
|
return *this;
|
|
|
|
|
|
}
|
2017-12-09 10:45:13 +01:00
|
|
|
|
private:
|
2017-12-12 20:13:53 +01:00
|
|
|
|
const Pgsql::Row &row;
|
2017-12-09 10:45:13 +01:00
|
|
|
|
int col = -1;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2018-09-19 08:25:23 +02:00
|
|
|
|
template <typename T>
|
|
|
|
|
|
Col& operator>>(Col &c, std::vector<T> &s)
|
|
|
|
|
|
{
|
|
|
|
|
|
return c.getAsArray<T>(std::back_inserter(s));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-11-17 19:36:12 +01:00
|
|
|
|
template <typename T, std::size_t N>
|
|
|
|
|
|
Col& operator>>(Col &c, boost::container::small_vector<T, N> &s)
|
|
|
|
|
|
{
|
|
|
|
|
|
return c.getAsArray<T>(std::back_inserter(s));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-09 10:45:13 +01:00
|
|
|
|
template <typename T>
|
|
|
|
|
|
Col& operator>>(Col &c, T &s)
|
|
|
|
|
|
{
|
|
|
|
|
|
s << c.nextValue();
|
|
|
|
|
|
return c;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-17 11:27:42 +01:00
|
|
|
|
|
2017-12-09 10:45:13 +01:00
|
|
|
|
} // end namespace Pgsql
|
|
|
|
|
|
|
|
|
|
|
|
#endif // PGSQL_COL_H
|