aGrUM  0.14.2
DBRowGenerator4CompleteRows_tpl.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
27 
28 #ifndef DOXYGEN_SHOULD_SKIP_THIS
29 
30 namespace gum {
31 
32  namespace learning {
33 
35  template < template < typename > class ALLOC >
39  }
40 
41 
43  template < template < typename > class ALLOC >
45  const std::vector< DBTranslatedValueType, ALLOC< DBTranslatedValueType > >
46  column_types,
48  alloc) :
49  DBRowGenerator< ALLOC >(
50  column_types, DBRowGeneratorGoal::ONLY_REMOVE_MISSING_VALUES, alloc) {
51  GUM_CONSTRUCTOR(DBRowGenerator4CompleteRows);
52  }
53 
54 
56  template < template < typename > class ALLOC >
58  const DBRowGenerator4CompleteRows< ALLOC >& from,
60  alloc) :
61  DBRowGenerator< ALLOC >(from, alloc),
62  __input_row(from.__input_row) {
63  GUM_CONS_CPY(DBRowGenerator4CompleteRows);
64  }
65 
66 
68  template < template < typename > class ALLOC >
70  const DBRowGenerator4CompleteRows< ALLOC >& from) :
71  DBRowGenerator4CompleteRows< ALLOC >(from, from.getAllocator()) {}
72 
73 
75  template < template < typename > class ALLOC >
77  DBRowGenerator4CompleteRows< ALLOC >&& from,
79  alloc) :
80  DBRowGenerator< ALLOC >(std::move(from), alloc),
81  __input_row(from.__input_row) {
82  GUM_CONS_MOV(DBRowGenerator4CompleteRows);
83  }
84 
85 
87  template < template < typename > class ALLOC >
89  DBRowGenerator4CompleteRows< ALLOC >&& from) :
90  DBRowGenerator4CompleteRows< ALLOC >(std::move(from),
91  from.getAllocator()) {}
92 
93 
95  template < template < typename > class ALLOC >
96  DBRowGenerator4CompleteRows< ALLOC >*
99  alloc) const {
100  ALLOC< DBRowGenerator4CompleteRows< ALLOC > > allocator(alloc);
101  DBRowGenerator4CompleteRows< ALLOC >* generator = allocator.allocate(1);
102  try {
103  allocator.construct(generator, *this, alloc);
104  } catch (...) {
105  allocator.deallocate(generator, 1);
106  throw;
107  }
108  return generator;
109  }
110 
111 
113  template < template < typename > class ALLOC >
114  DBRowGenerator4CompleteRows< ALLOC >*
116  return clone(this->getAllocator());
117  }
118 
119 
121  template < template < typename > class ALLOC >
123  GUM_DESTRUCTOR(DBRowGenerator4CompleteRows);
124  }
125 
126 
128  template < template < typename > class ALLOC >
129  DBRowGenerator4CompleteRows< ALLOC >& DBRowGenerator4CompleteRows< ALLOC >::
130  operator=(const DBRowGenerator4CompleteRows< ALLOC >& from) {
132  __input_row = from.__input_row;
133  return *this;
134  }
135 
136 
138  template < template < typename > class ALLOC >
139  DBRowGenerator4CompleteRows< ALLOC >& DBRowGenerator4CompleteRows< ALLOC >::
140  operator=(DBRowGenerator4CompleteRows< ALLOC >&& from) {
141  DBRowGenerator< ALLOC >::operator=(std::move(from));
142  __input_row = from.__input_row;
143  return *this;
144  }
145 
146 
148  template < template < typename > class ALLOC >
149  INLINE const DBRow< DBTranslatedValue, ALLOC >&
151  this->decreaseRemainingRows();
152  return *__input_row;
153  }
154 
155 
157  template < template < typename > class ALLOC >
159  const DBRow< DBTranslatedValue, ALLOC >& row) {
160  // check that all the values are observed
161  const auto& xrow = row.row();
162  for (const auto col : this->_columns_of_interest) {
163  switch (this->_column_types[col]) {
165  if (xrow[col].discr_val == std::numeric_limits< std::size_t >::max()) {
166  __input_row = nullptr;
167  return std::size_t(0);
168  }
169  break;
170 
172  if (xrow[col].cont_val == std::numeric_limits< float >::max()) {
173  __input_row = nullptr;
174  return std::size_t(0);
175  }
176  break;
177 
178  default:
179  GUM_ERROR(NotImplementedYet,
180  "DBTranslatedValueType " << int(this->_column_types[col])
181  << " is not supported yet");
182  break;
183  }
184  }
185  __input_row = &row;
186  return std::size_t(1);
187  }
188 
189 
190  } /* namespace learning */
191 
192 } /* namespace gum */
193 
194 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
std::vector< std::size_t, ALLOC< std::size_t > > _columns_of_interest
the set of columns of interest
DBRowGeneratorGoal
the type of things that a DBRowGenerator is designed for
DBRowGenerator< ALLOC > & operator=(const DBRowGenerator< ALLOC > &)
copy constructor
void decreaseRemainingRows()
decrease the number of remaining output rows
STL namespace.
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
virtual std::size_t _computeRows(const DBRow< DBTranslatedValue, ALLOC > &row) final
computes the rows it will provide as output
DBRowGenerator4CompleteRows< ALLOC > & operator=(const DBRowGenerator4CompleteRows< ALLOC > &from)
copy operator
ALLOC< DBTranslatedValue > allocator_type
type for the allocators passed in arguments of methods
DBTranslatedValueType
The nature of the elements handled by translators (discrete, continuous).
allocator_type getAllocator() const
returns the allocator used
allocator_type getAllocator() const
returns the allocator used
DBRowGenerator(const std::vector< DBTranslatedValueType, ALLOC< DBTranslatedValueType > > column_types, const DBRowGeneratorGoal goal, const allocator_type &alloc=allocator_type())
default constructor
DBRowGenerator4CompleteRows(const std::vector< DBTranslatedValueType, ALLOC< DBTranslatedValueType > > column_types, const allocator_type &alloc=allocator_type())
default constructor
std::vector< DBTranslatedValueType, ALLOC< DBTranslatedValueType > > _column_types
the types of the columns in the DatabaseTable
virtual const DBRow< DBTranslatedValue, ALLOC > & generate() final
generates one ouput DBRow for each DBRow passed to method setInputRow
virtual DBRowGenerator4CompleteRows< ALLOC > * clone() const override final
virtual copy constructor
A DBRowGenerator class that returns the rows that are complete (fully observed) w.r.t.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52