72 lines
1.7 KiB
C++
72 lines
1.7 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(const record&) = default;
|
|
record& operator=(const record&) = default;
|
|
record(record&&) noexcept = default;
|
|
record& operator=(record&&) noexcept = default;
|
|
~record() = default;
|
|
|
|
template<class Operator>
|
|
void process(Operator &op)
|
|
{
|
|
for(auto &col : columns_) {
|
|
col.process(op);
|
|
}
|
|
}
|
|
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) const;
|
|
|
|
iterator find(const std::string &column_name);
|
|
[[nodiscard]] 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;
|
|
[[nodiscard]] bool empty() const;
|
|
void clear();
|
|
|
|
private:
|
|
column_by_index columns_;
|
|
column_by_name_map columns_by_name_;
|
|
};
|
|
|
|
}
|
|
#endif //QUERY_RECORD_HPP
|