-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathData_Details.hxx
More file actions
72 lines (50 loc) · 1.86 KB
/
Copy pathData_Details.hxx
File metadata and controls
72 lines (50 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#pragma once
#include "Common.hxx"
#include "Field_Framework.hxx"
#include "Row.hxx"
namespace tablator {
class Data_Details {
public:
Data_Details(size_t row_size, size_t num_rows = 0) : row_size_(row_size) {
init(num_rows);
}
Data_Details(const Field_Framework &field_framework, size_t num_rows = 0)
: Data_Details(field_framework.get_row_size(), num_rows) {}
void append_row(const Row &row) {
assert(row.get_data().size() == get_row_size());
data_.reserve(data_.size() + row.get_data().size());
data_.insert(data_.end(), row.get_data().begin(), row.get_data().end());
}
void append_rows(const Data_Details &other) {
assert(other.get_row_size() == get_row_size());
data_.reserve(data_.size() + other.get_data().size());
data_.insert(data_.end(), other.get_data().begin(), other.get_data().end());
}
void adjust_num_rows(const size_t new_num_rows) {
data_.resize(new_num_rows * get_row_size());
}
void reserve_rows(const size_t &new_num_rows) {
data_.reserve(get_row_size() * new_num_rows);
}
// accessors
size_t get_data_size() const { return data_.size(); }
size_t get_num_rows() const {
if (get_row_size() == 0) {
return 0;
}
return get_data_size() / get_row_size();
};
inline size_t get_row_size() const { return row_size_; }
inline const std::vector<uint8_t> &get_data() const { return data_; }
// Non-const to support append_rows().
inline std::vector<uint8_t> &get_data() { return data_; }
inline void set_data(const std::vector<uint8_t> &d) { data_ = d; }
private:
void init(const size_t &new_num_rows) {
reserve_rows(new_num_rows);
}
// Can't be const because of append_rows().
std::vector<uint8_t> data_;
size_t row_size_;
};
} // namespace tablator