30 #ifndef DOXYGEN_SHOULD_SKIP_THIS 38 template <
template <
typename >
class ALLOC >
39 template <
template <
typename >
class VARALLOC,
43 const typename RawDatabaseTable< ALLOC >::template MissingValType<
44 MISSALLOC >& missing_symbols,
45 const std::vector< std::string, VARALLOC< std::string > >& var_names,
47 IDatabaseTable< DBCell, ALLOC >(missing_symbols, var_names, alloc),
48 __ignored_cols(alloc) {
54 template <
template <
typename >
class ALLOC >
55 template <
template <
typename >
class MISSALLOC >
58 MISSALLOC >& missing_symbols,
62 std::vector<
std::string, ALLOC<
std::string > >(),
64 __ignored_cols(alloc) {
70 template <
template <
typename >
class ALLOC >
74 std::vector<
std::string, ALLOC<
std::string > >(),
75 std::vector<
std::string, ALLOC<
std::string > >(),
77 __ignored_cols(alloc) {
83 template <
template <
typename >
class ALLOC >
85 const RawDatabaseTable< ALLOC >& from,
88 __ignored_cols(from.__ignored_cols, alloc) {
93 template <
template <
typename >
class ALLOC >
95 const RawDatabaseTable< ALLOC >& from) :
100 template <
template <
typename >
class ALLOC >
102 RawDatabaseTable< ALLOC >&& from,
105 __ignored_cols(
std::move(from.__ignored_cols)) {
111 template <
template <
typename >
class ALLOC >
113 RawDatabaseTable< ALLOC >&& from) :
118 template <
template <
typename >
class ALLOC >
121 ALLOC< RawDatabaseTable< ALLOC > > allocator(alloc);
122 RawDatabaseTable< ALLOC >* new_db = allocator.allocate(1);
124 allocator.construct(new_db, *
this, alloc);
126 allocator.deallocate(new_db, 1);
135 template <
template <
typename >
class ALLOC >
142 template <
template <
typename >
class ALLOC >
149 template <
template <
typename >
class ALLOC >
151 operator=(
const RawDatabaseTable< ALLOC >& from) {
154 __ignored_cols = from.__ignored_cols;
161 template <
template <
typename >
class ALLOC >
163 operator=(RawDatabaseTable< ALLOC >&& from) {
166 __ignored_cols = std::move(from.__ignored_cols);
173 template <
template <
typename >
class ALLOC >
175 const std::vector< std::string, ALLOC< std::string > >& names,
176 const bool from_external_object) {
177 const std::size_t
size = names.size();
178 const std::size_t ignored_cols_size = __ignored_cols.size();
180 if (!from_external_object || !ignored_cols_size) {
181 if (this->
_rows.empty() || (size == this->
_rows[0].size())) {
186 "the number of variable's names (i.e., " 187 << size <<
") does not correspond to the number of columns of the " 188 <<
"raw database table (i.e.," << this->
_rows[0].
size() <<
")");
193 std::size_t ignored_size = std::size_t(0);
196 for (
auto iter = __ignored_cols.rbegin(), rend = __ignored_cols.rend();
198 ++iter, ++ignored_size) {
199 if (*iter < size) {
break; }
201 ignored_size = ignored_cols_size - ignored_size;
203 if (this->
_rows.empty()
204 || (size == this->
_rows[0].size() + ignored_size)) {
206 for (std::size_t i = std::size_t(0), j = std::size_t(0); i <
size; ++i) {
207 if (i != __ignored_cols[j]) {
208 new_names.push_back(names[i]);
210 if (++j == ignored_cols_size) {
211 for (++i; i <
size; ++i) {
212 new_names.push_back(names[i]);
221 "the number of variable's names excluding the ignored " 222 <<
"columns (i.e., " << (size - ignored_size)
223 <<
") does not correspond to the number of columns of the " 224 <<
"raw database table (i.e.," << this->
_rows[0].
size()
232 template <
template <
typename >
class ALLOC >
234 const bool from_external_object) {
239 const std::size_t size = __ignored_cols.size();
241 if (from_external_object) {
242 for (i = std::size_t(0); i <
size; ++i) {
243 if (k <= __ignored_cols[i]) {
244 if (k == __ignored_cols[i])
return;
249 for (i = std::size_t(0); i <
size; ++i, ++kk) {
250 if (kk <= __ignored_cols[i]) {
251 if (kk == __ignored_cols[i])
return;
262 const std::size_t col = kk - i;
268 const std::size_t nb_rows = this->
_rows.size();
269 if (nb_rows != std::size_t(0)) {
270 const std::size_t nb_cols = this->
_rows[0].size();
271 for (std::size_t i = std::size_t(0); i < nb_rows; ++i) {
272 auto& row = this->
_rows[i].row();
274 bool has_missing_val =
false;
275 for (std::size_t j = std::size_t(0); j < nb_cols; ++j) {
276 if ((j != col) && row[j].isMissing()) {
277 has_missing_val =
true;
281 if (!has_missing_val)
284 row.erase(row.begin() + col);
291 __ignored_cols.push_back(std::size_t(0));
292 for (std::size_t j = size; j > i; --j)
293 __ignored_cols[j] = __ignored_cols[j - 1];
294 __ignored_cols[i] = kk;
299 template <
template <
typename >
class ALLOC >
300 INLINE
const typename RawDatabaseTable< ALLOC >::template
DBVector<
303 return __ignored_cols;
308 template <
template <
typename >
class ALLOC >
309 const typename RawDatabaseTable< ALLOC >::template DBVector< std::size_t >
312 if (data.empty()) {
return DBVector< std::size_t >(); }
314 const std::size_t size = data[0].size();
315 const std::size_t ignored_cols_size = __ignored_cols.size();
316 DBVector< std::size_t > cols(size);
318 if (!ignored_cols_size) {
319 for (std::size_t i = std::size_t(0); i <
size; ++i) {
325 std::size_t i = std::size_t(0);
326 std::size_t k = std::size_t(0);
327 std::size_t j = std::size_t(0);
329 if (i != __ignored_cols[j]) {
331 if (++k == size)
break;
333 if (++j == ignored_cols_size) {
334 for (++i; k <
size; ++i, ++k) {
349 template <
template <
typename >
class ALLOC >
351 RawDatabaseTable< ALLOC >::__convert(
const std::string& elt)
const {
357 template <
template <
typename >
class ALLOC >
359 const std::vector< std::string, ALLOC< std::string > >& new_row) {
362 const std::size_t row_size = new_row.size();
363 const std::size_t ignored_cols_size = __ignored_cols.size();
364 std::size_t ignored_size = std::size_t(0);
365 if (ignored_cols_size) {
367 for (
auto iter = __ignored_cols.rbegin(), rend = __ignored_cols.rend();
369 ++iter, ++ignored_size) {
370 if (*iter < row_size) {
break; }
372 ignored_size = ignored_cols_size - ignored_size;
378 << (row_size - ignored_size)
379 <<
" elements whereas the raw database table has " 385 dbrow.reserve(row_size - ignored_size);
386 bool has_missing_val =
false;
389 if (ignored_size == 0) {
390 for (
const auto& elt : new_row) {
391 const DBCell new_cell(this->__convert(elt));
392 if (new_cell.isMissing()) has_missing_val =
true;
393 dbrow.pushBack(new_cell);
396 for (std::size_t i = std::size_t(0), j = std::size_t(0); i < row_size;
398 if (i != __ignored_cols[j]) {
399 const DBCell new_cell(this->__convert(new_row[i]));
400 if (new_cell.isMissing()) has_missing_val =
true;
401 dbrow.pushBack(new_cell);
403 if (++j == ignored_size) {
404 for (++i; i < row_size; ++i) {
405 const DBCell new_cell(this->__convert(new_row[i]));
406 if (new_cell.isMissing()) has_missing_val =
true;
407 dbrow.pushBack(new_cell);
415 std::move(dbrow), has_missing_val ? IsMissing::True : IsMissing::False);
420 template <
template <
typename >
class ALLOC >
422 __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 ...
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.