68 lines
1.6 KiB
C++
68 lines
1.6 KiB
C++
#ifndef QUERY_RECORD_HPP
|
|
#define QUERY_RECORD_HPP
|
|
|
|
#include "matador/utils/access.hpp"
|
|
|
|
#include "matador/sql/column.hpp"
|
|
|
|
#include <vector>
|
|
#include <unordered_map>
|
|
|
|
namespace matador::sql {
|
|
|
|
class record
|
|
{
|
|
private:
|
|
using column_by_index = std::vector<column>;
|
|
using column_index_pair = std::pair<std::reference_wrapper<column>, size_t>;
|
|
using column_by_name_map = std::unordered_map<std::string, column_index_pair>;
|
|
|
|
public:
|
|
using iterator = column_by_index::iterator;
|
|
using const_iterator = column_by_index::const_iterator;
|
|
|
|
record() = default;
|
|
record(std::initializer_list<column> columns);
|
|
~record() = default;
|
|
|
|
template<class Operator>
|
|
void process(Operator &op)
|
|
{
|
|
for(auto &col : columns_) {
|
|
// Todo: Find a solution to handle a column with process
|
|
int todo{};
|
|
matador::utils::access::attribute(op, col.name().c_str(), todo, col.attributes());
|
|
}
|
|
}
|
|
template < typename Type >
|
|
void append(const std::string &name, long size = -1)
|
|
{
|
|
append(make_column<Type>(name, size));
|
|
}
|
|
|
|
void append(column col);
|
|
|
|
[[nodiscard]] const column& at(const std::string &name) const;
|
|
const column& at(size_t index);
|
|
|
|
iterator find(const std::string &column_name);
|
|
const_iterator find(const std::string &column_name) const;
|
|
|
|
iterator begin();
|
|
[[nodiscard]] const_iterator begin() const;
|
|
[[nodiscard]] const_iterator cbegin() const;
|
|
|
|
iterator end();
|
|
[[nodiscard]] const_iterator end() const;
|
|
[[nodiscard]] const_iterator cend() const;
|
|
|
|
[[nodiscard]] size_t size() const;
|
|
|
|
private:
|
|
column_by_index columns_;
|
|
column_by_name_map columns_by_name_;
|
|
};
|
|
|
|
}
|
|
#endif //QUERY_RECORD_HPP
|