27 #ifndef DOXYGEN_SHOULD_SKIP_THIS 35 template <
template <
typename >
class ALLOC >
36 template <
template <
typename >
class VARALLOC,
40 const typename RawDatabaseTable< ALLOC >::template MissingValType<
41 MISSALLOC >& missing_symbols,
42 const std::vector< std::string, VARALLOC< std::string > >& var_names,
44 IDatabaseTable< DBCell, ALLOC >(missing_symbols, var_names, alloc),
45 __ignored_cols(alloc) {
51 template <
template <
typename >
class ALLOC >
52 template <
template <
typename >
class MISSALLOC >
55 MISSALLOC >& missing_symbols,
59 std::vector<
std::string, ALLOC<
std::string > >(),
61 __ignored_cols(alloc) {
67 template <
template <
typename >
class ALLOC >
71 std::vector<
std::string, ALLOC<
std::string > >(),
72 std::vector<
std::string, ALLOC<
std::string > >(),
74 __ignored_cols(alloc) {
80 template <
template <
typename >
class ALLOC >
82 const RawDatabaseTable< ALLOC >& from,
85 __ignored_cols(from.__ignored_cols, alloc) {
90 template <
template <
typename >
class ALLOC >
92 const RawDatabaseTable< ALLOC >& from) :
97 template <
template <
typename >
class ALLOC >
99 RawDatabaseTable< ALLOC >&& from,
102 __ignored_cols(
std::move(from.__ignored_cols)) {
108 template <
template <
typename >
class ALLOC >
110 RawDatabaseTable< ALLOC >&& from) :
115 template <
template <
typename >
class ALLOC >
118 ALLOC< RawDatabaseTable< ALLOC > > allocator(alloc);
119 RawDatabaseTable< ALLOC >* new_db = allocator.allocate(1);
121 allocator.construct(new_db, *
this, alloc);
123 allocator.deallocate(new_db, 1);
132 template <
template <
typename >
class ALLOC >
139 template <
template <
typename >
class ALLOC >
146 template <
template <
typename >
class ALLOC >
148 operator=(
const RawDatabaseTable< ALLOC >& from) {
151 __ignored_cols = from.__ignored_cols;
158 template <
template <
typename >
class ALLOC >
160 operator=(RawDatabaseTable< ALLOC >&& from) {
163 __ignored_cols = std::move(from.__ignored_cols);
170 template <
template <
typename >
class ALLOC >
172 const std::vector< std::string, ALLOC< std::string > >& names,
173 const bool from_external_object) {
174 const std::size_t
size = names.size();
175 const std::size_t ignored_cols_size = __ignored_cols.size();
177 if (!from_external_object || !ignored_cols_size) {
178 if (this->
_rows.empty() || (size == this->
_rows[0].size())) {
183 "the number of variable's names (i.e., " 184 << size <<
") does not correspond to the number of columns of the " 185 <<
"raw database table (i.e.," << this->
_rows[0].
size() <<
")");
190 std::size_t ignored_size = std::size_t(0);
193 for (
auto iter = __ignored_cols.rbegin(), rend = __ignored_cols.rend();
195 ++iter, ++ignored_size) {
196 if (*iter < size) {
break; }
198 ignored_size = ignored_cols_size - ignored_size;
200 if (this->
_rows.empty()
201 || (size == this->
_rows[0].size() + ignored_size)) {
203 for (std::size_t i = std::size_t(0), j = std::size_t(0); i <
size; ++i) {
204 if (i != __ignored_cols[j]) {
205 new_names.push_back(names[i]);
207 if (++j == ignored_cols_size) {
208 for (++i; i <
size; ++i) {
209 new_names.push_back(names[i]);
218 "the number of variable's names excluding the ignored " 219 <<
"columns (i.e., " << (size - ignored_size)
220 <<
") does not correspond to the number of columns of the " 221 <<
"raw database table (i.e.," << this->
_rows[0].
size()
229 template <
template <
typename >
class ALLOC >
231 const bool from_external_object) {
236 const std::size_t size = __ignored_cols.size();
238 if (from_external_object) {
239 for (i = std::size_t(0); i <
size; ++i) {
240 if (k <= __ignored_cols[i]) {
241 if (k == __ignored_cols[i])
return;
246 for (i = std::size_t(0); i <
size; ++i, ++kk) {
247 if (kk <= __ignored_cols[i]) {
248 if (kk == __ignored_cols[i])
return;
259 const std::size_t col = kk - i;
265 const std::size_t nb_rows = this->
_rows.size();
266 if (nb_rows != std::size_t(0)) {
267 const std::size_t nb_cols = this->
_rows[0].size();
268 for (std::size_t i = std::size_t(0); i < nb_rows; ++i) {
269 auto& row = this->
_rows[i].row();
271 bool has_missing_val =
false;
272 for (std::size_t j = std::size_t(0); j < nb_cols; ++j) {
273 if ((j != col) && row[j].isMissing()) {
274 has_missing_val =
true;
278 if (!has_missing_val)
281 row.erase(row.begin() + col);
288 __ignored_cols.push_back(std::size_t(0));
289 for (std::size_t j = size; j > i; --j)
290 __ignored_cols[j] = __ignored_cols[j - 1];
291 __ignored_cols[i] = kk;
296 template <
template <
typename >
class ALLOC >
297 INLINE
const typename RawDatabaseTable< ALLOC >::template
DBVector<
300 return __ignored_cols;
305 template <
template <
typename >
class ALLOC >
306 const typename RawDatabaseTable< ALLOC >::template DBVector< std::size_t >
309 if (data.empty()) {
return DBVector< std::size_t >(); }
311 const std::size_t size = data[0].size();
312 const std::size_t ignored_cols_size = __ignored_cols.size();
313 DBVector< std::size_t > cols(size);
315 if (!ignored_cols_size) {
316 for (std::size_t i = std::size_t(0); i <
size; ++i) {
322 std::size_t i = std::size_t(0);
323 std::size_t k = std::size_t(0);
324 std::size_t j = std::size_t(0);
326 if (i != __ignored_cols[j]) {
328 if (++k == size)
break;
330 if (++j == ignored_cols_size) {
331 for (++i; k <
size; ++i, ++k) {
346 template <
template <
typename >
class ALLOC >
348 RawDatabaseTable< ALLOC >::__convert(
const std::string& elt)
const {
354 template <
template <
typename >
class ALLOC >
356 const std::vector< std::string, ALLOC< std::string > >& new_row) {
359 const std::size_t row_size = new_row.size();
360 const std::size_t ignored_cols_size = __ignored_cols.size();
361 std::size_t ignored_size = std::size_t(0);
362 if (ignored_cols_size) {
364 for (
auto iter = __ignored_cols.rbegin(), rend = __ignored_cols.rend();
366 ++iter, ++ignored_size) {
367 if (*iter < row_size) {
break; }
369 ignored_size = ignored_cols_size - ignored_size;
375 << (row_size - ignored_size)
376 <<
" elements whereas the raw database table has " 382 dbrow.reserve(row_size - ignored_size);
383 bool has_missing_val =
false;
386 if (ignored_size == 0) {
387 for (
const auto& elt : new_row) {
388 const DBCell new_cell(this->__convert(elt));
389 if (new_cell.isMissing()) has_missing_val =
true;
390 dbrow.pushBack(new_cell);
393 for (std::size_t i = std::size_t(0), j = std::size_t(0); i < row_size;
395 if (i != __ignored_cols[j]) {
396 const DBCell new_cell(this->__convert(new_row[i]));
397 if (new_cell.isMissing()) has_missing_val =
true;
398 dbrow.pushBack(new_cell);
400 if (++j == ignored_size) {
401 for (++i; i < row_size; ++i) {
402 const DBCell new_cell(this->__convert(new_row[i]));
403 if (new_cell.isMissing()) has_missing_val =
true;
404 dbrow.pushBack(new_cell);
412 std::move(dbrow), has_missing_val ? IsMissing::True : IsMissing::False);
417 template <
template <
typename >
class ALLOC >
419 __ignored_cols.clear();
void insertRow(const std::vector< std::string, OTHER_ALLOC< std::string > > &new_row)
insert a new row at the end of the database
DBVector< IsMissing > _has_row_missing_val
ALLOC< DBCell > getAllocator() const
returns the allocator of the database
virtual void ignoreColumn(const std::size_t k, const bool from_external_object=true) final
makes the database table ignore from now on the kth column
std::size_t size() const noexcept
returns the number of records (rows) in the database
IDatabaseTable< T_DATA, ALLOC > & operator=(const IDatabaseTable< T_DATA, ALLOC > &from)
copy operator
virtual const DBVector< std::size_t > ignoredColumns() const final
returns the set of columns of the original dataset that are ignored
void eraseAllRows()
erase all the rows
virtual const DBVector< std::size_t > inputColumns() const final
returns the set of columns of the original dataset that are present in the RawDatabaseTable ...
gum is the global namespace for all aGrUM entities
static DBCell bestDBCell(const std::string &str, const std::vector< std::string, ALLOC< std::string > > &missingVals)
returns the DBCell with the best type for an element encoded as a string
bool _isRowSizeOK(const std::size_t size) const
checks whether a size corresponds to the number of columns of the database
const Matrix< T_DATA > & content() const noexcept
returns the content (the records) of the database
IDatabaseTable(const MissingValType< MISSALLOC > &missing_symbols, const std::vector< std::string, VARALLOC< std::string > > &var_names, const ALLOC< DBCell > &alloc)
default constructor
ALLOC< DBCell > allocator_type
Types for STL compliance.
DBVector< std::string > _variable_names
the names of the variables for each column
std::vector< TX_DATA, ALLOC< TX_DATA > > DBVector
the type for the vectors used in the RawDatabaseTable
virtual void insertRow(const std::vector< std::string, ALLOC< std::string > > &new_row) final
insert a new row at the end of the database
RawDatabaseTable(const MissingValType< MISSALLOC > &missing_symbols, const std::vector< std::string, VARALLOC< std::string > > &var_names, const allocator_type &alloc=allocator_type())
default constructor
virtual ~RawDatabaseTable()
destructor
DBVector< std::string > _missing_symbols
std::vector< std::string, XALLOC< std::string > > MissingValType
virtual RawDatabaseTable< ALLOC > * clone() const final
virtual copy constructor
virtual void clear() final
erase the content of the database, including the names of the variables
RawDatabaseTable< ALLOC > & operator=(const RawDatabaseTable< ALLOC > &from)
copy operator
#define GUM_ERROR(type, msg)
virtual void clear()
erase the content of the database, including the names of the variables
virtual void setVariableNames(const std::vector< std::string, ALLOC< std::string > > &names, const bool from_external_object=true) final
sets the names of the variables
The table containing the raw/original data of a database.