15#include <unordered_map>
71 size_t size()
const {
return _count; }
72 bool empty()
const {
return _count == 0; }
78 const T *_base =
nullptr;
85 const auto r = _rowOf.find(
row);
86 const auto c = _columnOf.find(
column);
88 if (
r == _rowOf.end() ||
c == _columnOf.end())
90 return _cells[
c->second * _rows.size() +
r->second];
95 const auto r = _rowOf.find(
row);
97 if (
r == _rowOf.end())
99 return Span(_cells.data() +
r->second, _rows.size(), _columnNames.size());
104 const auto c = _columnOf.find(
column);
106 if (
c == _columnOf.end())
108 return columnAt(
c->second);
113 return Span(_cells.data(), 1, _cells.size());
118 return _columnOf.count(
column) != 0;
128 if (_columnOf.count(
column))
131 _columnOf.emplace(
column, _columnNames.size());
132 _columnNames.push_back(
column);
133 _cells.resize(_cells.size() + _rows.size(),
T{});
146 const auto c = _columnOf.find(
column);
148 if (
c == _columnOf.end())
152 const size_t at = rowOf(
row);
154 _cells[
c->second * _rows.size() +
at] =
value;
164 template <
typename Predicate>
168 for (
size_t column = 0;
column < _columnNames.size(); ) {
174 const auto begin = _cells.begin() +
column * _rows.size();
176 _cells.erase(begin, begin + _rows.size());
177 _columnNames.erase(_columnNames.begin() +
column);
185 const std::vector<std::string> &
rows()
const {
return _rows; }
188 const std::vector<std::string> &
columnNames()
const {
return _columnNames; }
192 Span columnAt(
size_t column)
const {
193 return Span(_cells.data() +
column * _rows.size(), 1, _rows.size());
202 size_t rowOf(
const std::string &
row) {
203 const auto found = _rowOf.find(
row);
205 if (
found != _rowOf.end())
206 return found->second;
208 const size_t oldRows = _rows.size();
210 const size_t columns = _columnNames.size();
216 _cells = std::move(
grown);
219 _rows.push_back(
row);
226 for (
size_t at = 0;
at < _columnNames.size();
at++)
227 _columnOf.emplace(_columnNames[
at],
at);
231 std::vector<T> _cells;
233 std::vector<std::string> _rows;
234 std::vector<std::string> _columnNames;
235 std::unordered_map<std::string, size_t> _rowOf;
236 std::unordered_map<std::string, size_t> _columnOf;
std::forward_iterator_tag iterator_category
Definition Stride.hpp:46
const T & operator*() const
Definition Stride.hpp:54
Iterator(const T *at, size_t step)
Definition Stride.hpp:52
bool operator==(const Iterator &o) const
Definition Stride.hpp:56
bool operator!=(const Iterator &o) const
Definition Stride.hpp:57
const T & reference
Definition Stride.hpp:50
T value_type
Definition Stride.hpp:48
std::ptrdiff_t difference_type
Definition Stride.hpp:47
Iterator & operator++()
Definition Stride.hpp:55
const T * pointer
Definition Stride.hpp:49
Une ligne ou une colonne : un depart, un pas, une longueur.
Definition Stride.hpp:42
Iterator end() const
Definition Stride.hpp:75
bool empty() const
Definition Stride.hpp:72
Iterator begin() const
Definition Stride.hpp:74
size_t size() const
Le nombre de cases, vides comprises.
Definition Stride.hpp:71
const T & operator[](size_t at) const
Definition Stride.hpp:68
Span(const T *base, size_t step, size_t count)
Definition Stride.hpp:65
Une table ligne x colonne, nommee des deux cotes, rangee a plat.
Definition Stride.hpp:32
Span column(const std::string &column) const
La colonne : une case par ligne. Vide si la colonne est inconnue.
Definition Stride.hpp:103
T at(const std::string &row, const std::string &column) const
La case, T{} si l'une des deux chaines est inconnue.
Definition Stride.hpp:84
Span row(const std::string &row) const
La ligne : une case par colonne. Vide si la ligne est inconnue.
Definition Stride.hpp:94
bool hasColumn(const std::string &column) const
Cette colonne existe-t-elle deja ?
Definition Stride.hpp:117
const std::vector< std::string > & columnNames() const
Les colonnes, dans l'ordre d'ajout.
Definition Stride.hpp:188
size_t eraseColumnsIf(Predicate should)
Retire les colonnes que should accepte.
Definition Stride.hpp:165
bool addColumn(const std::string &column)
Ajoute une colonne vide.
Definition Stride.hpp:127
const std::vector< std::string > & rows() const
Les lignes, dans l'ordre de decouverte.
Definition Stride.hpp:185
Span all() const
Toute la table, colonne par colonne.
Definition Stride.hpp:112
bool set(const std::string &row, const std::string &column, T value)
Ecrit une case. La ligne est creee si elle est nouvelle.
Definition Stride.hpp:145