25 #ifndef DOXYGEN_SHOULD_SKIP_THIS 32 template <
template <
typename >
class ALLOC >
35 return __columns.get_allocator();
40 template <
template <
typename >
class ALLOC >
42 ALLOC< DBTranslator< ALLOC > > allocator(this->getAllocator());
43 for (
auto translator : __translators) {
44 allocator.destroy(translator);
45 allocator.deallocate(translator, 1);
48 __translators.clear();
50 __highest_column = std::size_t(0);
55 template <
template <
typename >
class ALLOC >
56 void DBTranslatorSet< ALLOC >::__copy(
57 const DBTranslatorSet< ALLOC >& from,
59 if (__translators.size() != 0) clear();
64 const std::size_t size = from.__translators.size();
65 __translators.reserve(size);
66 __columns.reserve(size);
67 __translators.resize(size);
68 __columns.resize(size);
72 for (i = std::size_t(0); i < size; ++i) {
73 __translators[i] = from.__translators[i]->clone(alloc);
74 __columns[i] = from.__columns[i];
77 __translators.resize(i);
82 __highest_column = from.__highest_column;
87 template <
template <
typename >
class ALLOC >
91 __columns(allocator_type(alloc)) {
97 template <
template <
typename >
class ALLOC >
99 const DBTranslatorSet< ALLOC >& from,
101 __translators(alloc),
110 template <
template <
typename >
class ALLOC >
112 const DBTranslatorSet< ALLOC >& from) :
117 template <
template <
typename >
class ALLOC >
119 DBTranslatorSet< ALLOC >&& from,
121 __translators(
std::move(from.__translators), alloc),
122 __columns(
std::move(from.__columns), alloc),
123 __highest_column(from.__highest_column) {
129 template <
template <
typename >
class ALLOC >
136 template <
template <
typename >
class ALLOC >
139 ALLOC< DBTranslatorSet< ALLOC > > allocator(alloc);
140 DBTranslatorSet< ALLOC >*
set = allocator.allocate(1);
142 allocator.construct(
set, *
this, alloc);
144 allocator.deallocate(
set, 1);
152 template <
template <
typename >
class ALLOC >
159 template <
template <
typename >
class ALLOC >
167 template <
template <
typename >
class ALLOC >
169 operator=(
const DBTranslatorSet< ALLOC >& from) {
180 template <
template <
typename >
class ALLOC >
182 operator=(DBTranslatorSet< ALLOC >&& from) {
185 __translators = std::move(from.__translators);
186 __columns = std::move(from.__columns);
187 __highest_column = from.__highest_column;
195 template <
template <
typename >
class ALLOC >
198 return *(__translators[k]);
203 template <
template <
typename >
class ALLOC >
206 return *(__translators[k]);
211 template <
template <
typename >
class ALLOC >
212 template <
template <
template <
typename >
class >
class Translator >
214 const Translator< ALLOC >& translator,
215 const std::size_t column,
216 const bool unique_column) {
220 const std::size_t size = __translators.size();
222 for (std::size_t i = std::size_t(0); i <
size; ++i) {
223 if (__columns[i] == column)
225 "There already exists a DBTranslator that parses Column" 231 __translators.reserve(size + 1);
232 __columns.reserve(size + 1);
235 ALLOC< DBTranslator< ALLOC > > allocator(this->
getAllocator());
236 DBTranslator< ALLOC >* new_translator =
translator.clone(allocator);
238 __translators.resize(size + 1);
239 __columns.resize(size + 1);
240 __translators[
size] = new_translator;
241 __columns[
size] = column;
244 if (column > __highest_column) __highest_column = column;
251 template <
template <
typename >
class ALLOC >
252 template <
template <
typename >
class XALLOC >
255 const std::size_t column,
256 const std::vector< std::string, XALLOC< std::string > >& missing_symbols,
257 const bool unique_column) {
259 switch (var.varType()) {
261 const LabelizedVariable& xvar =
262 static_cast< const LabelizedVariable&
>(var);
263 DBTranslator4LabelizedVariable< ALLOC >
translator(xvar,
269 const IDiscretizedVariable& xvar =
270 static_cast< const IDiscretizedVariable&
>(var);
271 DBTranslator4DiscretizedVariable< ALLOC >
translator(xvar,
277 const RangeVariable& xvar =
static_cast< const RangeVariable&
>(var);
278 DBTranslator4RangeVariable< ALLOC >
translator(xvar, missing_symbols);
283 const IContinuousVariable& xvar =
284 static_cast< const IContinuousVariable&
>(var);
285 DBTranslator4ContinuousVariable< ALLOC >
translator(xvar,
292 "The insertion of the translator for Variable " 294 <<
" is impossible because a translator " 295 "for such variable is not implemented yet");
301 template <
template <
typename >
class ALLOC >
303 const Variable& var,
const std::size_t column,
const bool unique_column) {
304 const std::vector< std::string, ALLOC< std::string > > missing;
310 template <
template <
typename >
class ALLOC >
312 const bool k_is_input_col) {
313 ALLOC< DBTranslator< ALLOC > > allocator(this->
getAllocator());
314 const std::size_t nb_trans = __translators.size();
316 if (!k_is_input_col) {
317 if (nb_trans < k)
return;
320 allocator.destroy(__translators[k]);
321 allocator.deallocate(__translators[k], 1);
323 const std::size_t colk = __columns[k];
324 __translators.erase(__translators.begin() + k);
325 __columns.erase(__columns.begin() + k);
329 if (__highest_column == colk) {
330 __highest_column = std::size_t(0);
331 for (
const auto col : __columns)
332 if (__highest_column < col) __highest_column = col;
336 auto iter_trans = __translators.rbegin();
337 bool translator_found =
false;
338 for (
auto iter_col = __columns.rbegin(); iter_col != __columns.rend();
339 ++iter_col, ++iter_trans) {
340 if (*iter_col == k) {
342 allocator.destroy(*iter_trans);
343 allocator.deallocate(*iter_trans, 1);
345 __translators.erase((iter_trans + 1).base());
346 __columns.erase((iter_col + 1).base());
347 translator_found =
true;
353 if (translator_found && (k == __highest_column)) {
354 __highest_column = std::size_t(0);
355 for (
const auto col : __columns)
356 if (__highest_column < col) __highest_column = col;
363 template <
template <
typename >
class ALLOC >
364 template <
template <
typename >
class OTHER_ALLOC >
366 const std::vector< std::string, OTHER_ALLOC< std::string > >& row,
367 const std::size_t k)
const {
368 return __translators[k]->translate(row[__columns[k]]);
373 template <
template <
typename >
class ALLOC >
374 template <
template <
typename >
class OTHER_ALLOC >
376 const std::vector< std::string, OTHER_ALLOC< std::string > >& row,
377 const std::size_t k)
const {
378 if (__translators.size() <= k)
379 GUM_ERROR(UndefinedElement,
"Translator #" << k <<
" could not be found");
380 return __translators[k]->translate(row[__columns[k]]);
385 template <
template <
typename >
class ALLOC >
387 const DBTranslatedValue translated_val,
const std::size_t k)
const {
388 return __translators[k]->translateBack(translated_val);
393 template <
template <
typename >
class ALLOC >
395 const DBTranslatedValue translated_val,
const std::size_t k)
const {
396 if (__translators.size() <= k)
397 GUM_ERROR(UndefinedElement,
"Translator #" << k <<
"could not be found");
398 return __translators[k]->translateBack(translated_val);
404 template <
template <
typename >
class ALLOC >
406 const DBTranslatedValue translated_val,
const std::size_t k)
const {
407 return __translators[k]->isMissingValue(translated_val);
413 template <
template <
typename >
class ALLOC >
415 const DBTranslatedValue translated_val,
const std::size_t k)
const {
416 if (__translators.size() <= k)
417 GUM_ERROR(UndefinedElement,
"Translator #" << k <<
"could not be found");
418 return __translators[k]->isMissingValue(translated_val);
423 template <
template <
typename >
class ALLOC >
424 INLINE DBTranslator< ALLOC >&
426 return *(__translators[k]);
431 template <
template <
typename >
class ALLOC >
432 INLINE
const DBTranslator< ALLOC >&
434 return *(__translators[k]);
439 template <
template <
typename >
class ALLOC >
440 INLINE DBTranslator< ALLOC >&
442 if (__translators.size() <= k)
443 GUM_ERROR(UndefinedElement,
"Translator #" << k <<
"could not be found");
444 return *(__translators[k]);
449 template <
template <
typename >
class ALLOC >
450 INLINE
const DBTranslator< ALLOC >&
452 if (__translators.size() <= k)
453 GUM_ERROR(UndefinedElement,
"Translator #" << k <<
"could not be found");
454 return *(__translators[k]);
459 template <
template <
typename >
class ALLOC >
462 return __translators[k]->domainSize();
467 template <
template <
typename >
class ALLOC >
470 if (__translators.size() <= k)
471 GUM_ERROR(UndefinedElement,
"Variable #" << k <<
"could not be found");
472 return __translators[k]->domainSize();
477 template <
template <
typename >
class ALLOC >
478 INLINE
const Variable&
480 return *(__translators[k]->variable());
485 template <
template <
typename >
class ALLOC >
486 INLINE
const Variable&
488 if (__translators.size() <= k)
489 GUM_ERROR(UndefinedElement,
"Variable #" << k <<
"could not be found");
490 return *(__translators[k]->variable());
496 template <
template <
typename >
class ALLOC >
499 return __translators[k]->needsReordering();
505 template <
template <
typename >
class ALLOC >
508 if (__translators.size() <= k)
509 GUM_ERROR(UndefinedElement,
"Variable #" << k <<
"could not be found");
510 return __translators[k]->needsReordering();
516 template <
template <
typename >
class ALLOC >
517 INLINE HashTable< std::size_t,
519 ALLOC< std::pair< std::size_t, std::size_t > > >
521 return __translators[k]->reorder();
527 template <
template <
typename >
class ALLOC >
528 INLINE HashTable< std::size_t,
530 ALLOC< std::pair< std::size_t, std::size_t > > >
532 if (__translators.size() <= k)
533 GUM_ERROR(UndefinedElement,
"Variable #" << k <<
"could not be found");
534 return __translators[k]->reorder();
540 template <
template <
typename >
class ALLOC >
549 template <
template <
typename >
class ALLOC >
552 if (__translators.size() <= k)
553 GUM_ERROR(UndefinedElement,
"Column #" << k <<
"could not be found");
559 template <
template <
typename >
class ALLOC >
561 return __highest_column;
566 template <
template <
typename >
class ALLOC >
568 return __columns.size();
573 template <
template <
typename >
class ALLOC >
575 return __columns.size();
579 template <
template <
typename >
class ALLOC >
581 std::vector< DBTranslator< ALLOC >*, ALLOC< DBTranslator< ALLOC >* > >&
583 return __translators;
HashTable< std::size_t, std::size_t, ALLOC< std::pair< std::size_t, std::size_t > > > reorder(const std::size_t k)
performs a reordering of the dictionary and returns a mapping from the old translated values to the n...
const Variable & variable(const std::size_t k) const
returns the variable stored into the kth translator
const std::vector< DBTranslator< ALLOC > *, ALLOC< DBTranslator< ALLOC > *> > & translators() const
returns the set of translators
void eraseTranslator(const std::size_t k, const bool k_is_input_col=false)
erases either the kth translator or those parsing the kth column of the input database ...
DBTranslatorSet< ALLOC > & operator=(const DBTranslatorSet< ALLOC > &from)
copy operator
std::string translateBack(const DBTranslatedValue translated_val, const std::size_t k) const
returns the original string that was translated into translated_val
const Variable & variableSafe(const std::size_t k) const
returns the variable stored into the kth translator
std::size_t domainSizeSafe(const std::size_t k) const
returns the domain size of the variable stored into the kth translator
std::size_t highestInputColumn() const
returns the largest input database column index read by the translators
DBTranslator< ALLOC > & translatorSafe(const std::size_t k)
returns the kth translator
typename DBTranslator< ALLOC >::allocator_type allocator_type
type for the allocators passed in arguments of methods
std::size_t inputColumnSafe(const std::size_t k) const
returns the column of the input database that will be read by the kth translator
std::size_t nbTranslators() const
returns the number of translators stored into the set
gum is the global namespace for all aGrUM entities
DBTranslatorSet(const allocator_type &alloc=allocator_type())
default constructor
DBTranslator< ALLOC > & operator[](const std::size_t k)
returns the kth translator
std::size_t domainSize(const std::size_t k) const
returns the domain size of the variable stored into the kth translator
DBTranslator< ALLOC > & translator(const std::size_t k)
returns the kth translator
bool isMissingValueSafe(const DBTranslatedValue translated_val, const std::size_t k) const
similar to method isMissingValue, except that it checks that the kth translator exists ...
allocator_type getAllocator() const
returns the allocator used by the translator set
std::size_t insertTranslator(const Translator< ALLOC > &translator, const std::size_t column, const bool unique_column=true)
inserts a new translator at the end of the translator set
bool needsReordering(const std::size_t k) const
indicates whether a reordering is needed to make the kth translator sorted
virtual ~DBTranslatorSet()
destructor
std::size_t inputColumn(const std::size_t k) const
returns the column of the input database that will be read by the kth translator
std::string translateBackSafe(const DBTranslatedValue translated_val, const std::size_t k) const
similar to method translateBack, except that it checks that the kth translator exists ...
std::size_t size() const
returns the number of translators stored into the set
DBTranslatedValue translateSafe(const std::vector< std::string, OTHER_ALLOC< std::string > > &row, const std::size_t k) const
similar to method translate, except that it checks that the kth translator exists ...
bool needsReorderingSafe(const std::size_t k) const
same as method needsReordering but checks that the kth translator exists
DBTranslatedValue translate(const std::vector< std::string, OTHER_ALLOC< std::string > > &row, const std::size_t k) const
ask the kth translator to translate a string in a row of the database
void clear()
remove all the translators
HashTable< std::size_t, std::size_t, ALLOC< std::pair< std::size_t, std::size_t > > > reorderSafe(const std::size_t k)
same as method reorder but checks that the kth translator exists
virtual DBTranslatorSet< ALLOC > * clone() const
virtual copy constructor
bool isMissingValue(const DBTranslatedValue translated_val, const std::size_t k) const
indicates whether the kth translator considers a translated_val as a missing value ...
#define GUM_ERROR(type, msg)