refactored record classe
This commit is contained in:
@@ -9,20 +9,14 @@
|
||||
namespace matador::sql {
|
||||
|
||||
class record final {
|
||||
private:
|
||||
using field_ref = std::reference_wrapper<field>;
|
||||
using field_by_index = std::vector<field_ref>;
|
||||
using field_index_pair = std::pair<field, field_by_index::difference_type>;
|
||||
using field_by_name_map = std::unordered_map<std::string, field_index_pair>;
|
||||
|
||||
public:
|
||||
using iterator = field_by_index::iterator;
|
||||
using const_iterator = field_by_index::const_iterator;
|
||||
using iterator = std::vector<field>::iterator;
|
||||
using const_iterator = std::vector<field>::const_iterator;
|
||||
|
||||
record() = default;
|
||||
record(std::initializer_list<field> columns);
|
||||
explicit record(const std::vector<field> &columns);
|
||||
record(const record &x);
|
||||
record(const record &x) = default;
|
||||
record& operator=(const record &x);
|
||||
record(record&&) noexcept = default;
|
||||
record& operator=(record&&) noexcept = default;
|
||||
@@ -34,13 +28,13 @@ public:
|
||||
template<class Operator>
|
||||
void process(Operator &op) {
|
||||
for(auto &f : fields_) {
|
||||
f.get().process(op);
|
||||
f.process(op);
|
||||
}
|
||||
}
|
||||
|
||||
void append(const field &col);
|
||||
void append(field col);
|
||||
|
||||
[[nodiscard]] const std::vector<field_ref>& columns() const;
|
||||
[[nodiscard]] const std::vector<field>& columns() const;
|
||||
|
||||
[[nodiscard]] const field& at(const std::string &name) const;
|
||||
[[nodiscard]] const field& at(size_t index) const;
|
||||
@@ -71,12 +65,8 @@ public:
|
||||
void clear();
|
||||
|
||||
private:
|
||||
void init();
|
||||
void add_to_map(field &col, size_t index);
|
||||
|
||||
private:
|
||||
field_by_index fields_;
|
||||
field_by_name_map fields_by_name_;
|
||||
std::vector<field> fields_;
|
||||
std::unordered_map<std::string, std::size_t> index_by_name_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user