Vince's CSV Parser
Loading...
Searching...
No Matches
clean_data_frame.hpp
1#pragma once
2
3#include "row_storage.hpp"
4#include "row_view.hpp"
5
6namespace csv {
7 namespace internals {
8 namespace data_frame {
12 class CleanDataFrame : public RowBackend {
13 public:
14 CleanDataFrame() = default;
15 CleanDataFrame(const CleanDataFrame&) = delete;
16 CleanDataFrame& operator=(const CleanDataFrame&) = delete;
17 CleanDataFrame(CleanDataFrame&&) noexcept = default;
18 CleanDataFrame& operator=(CleanDataFrame&&) noexcept = default;
19
20 inline const ConstColNamesPtr& names() const noexcept { return names_; }
21 inline void set_names(ConstColNamesPtr names) { names_ = std::move(names); }
22 inline std::vector<CSVRow>& rows() noexcept { return rows_; }
23 inline const std::vector<CSVRow>& rows() const noexcept { return rows_; }
24 inline size_t n_cols() const noexcept { return names_->size(); }
25 inline const RowOverlay* find_edits(size_t) const noexcept { return nullptr; }
26
27 inline CellBinding bind(size_t, size_t column) const {
28 validate_column(column, n_cols());
29 return CellBinding{nullptr, column};
30 }
31
32 inline csv::string_view view(size_t row, size_t column) const {
33 validate_column(column, n_cols());
34 return RowViewAccessor::view(rows_[row], column);
35 }
36
37 inline CSVRow make_inserted_row(const std::vector<std::string>& row, CSVError& error) const {
38 if (!validate_row(row, n_cols(), error)) return {};
39 return RowStorageBuilder::make_row(row, names_);
40 }
41
42 inline void reserve_insert() { reserve_next(rows_); }
43 inline void insert_row(size_t index, CSVRow&& row) {
44 rows_.insert(rows_.begin() + index, std::move(row));
45 }
46 inline void erase_row(size_t index) { rows_.erase(rows_.begin() + index); }
47
48 inline CleanDataFrame selected_rows(const std::vector<std::uint8_t>& mask, CSVError& error) const {
50 selected.names_ = names_;
51 selected.rows_ = select_parsed_rows(rows_, mask, error);
52 return selected;
53 }
54
55 inline void replace_rows(std::vector<CSVRow>&& rows, ConstColNamesPtr names) noexcept {
56 rows_ = std::move(rows);
57 names_ = std::move(names);
58 }
59
60 private:
61 ConstColNamesPtr names_ = std::make_shared<ColNames>();
62 std::vector<CSVRow> rows_;
63 };
64 }
65 }
66}
Data structure for representing CSV rows.
Definition csv_row.hpp:533
Borrow a row and error state for synchronous, single-pass field access.
Direct parsed-row backend and stable physical backing for editing.
The all encompassing namespace.
std::string_view string_view
The string_view class used by this library.
Definition common.hpp:182
A diagnostic whose text remains valid for the lifetime of the error.
Definition csv_error.hpp:94