aGrUM  0.16.0
IDBInitializer.h
Go to the documentation of this file.
1 
29 #ifndef GUM_LEARNING_IDB_INITILIALIZER_H
30 #define GUM_LEARNING_IDB_INITILIALIZER_H
31 
32 #include <vector>
33 #include <string>
34 
35 #include <agrum/agrum.h>
38 
39 
40 namespace gum {
41 
42  namespace learning {
43 
116  template < template < typename > class ALLOC >
118  public:
121  enum class InputType : char { STRING, DBCELL };
122 
124  using allocator_type = ALLOC< std::string >;
125 
126  // ##########################################################################
128  // ##########################################################################
130 
132 
135  IDBInitializer(const InputType type, const allocator_type& alloc);
136 
139 
142  const allocator_type& alloc);
143 
146 
149 
151  virtual IDBInitializer< ALLOC >* clone() const = 0;
152 
154  virtual IDBInitializer< ALLOC >*
155  clone(const allocator_type& alloc) const = 0;
156 
158  virtual ~IDBInitializer();
159 
161 
162 
163  // ##########################################################################
165  // ##########################################################################
167 
169  const std::vector< std::string, ALLOC< std::string > >& variableNames();
170 
172 
174  template < template < template < typename > class > class DATABASE >
175  void fillDatabase(DATABASE< ALLOC >& database,
176  const bool retry_insertion = false);
177 
180  std::size_t throwingColumn() const;
181 
184 
186 
187 
188  protected:
191 
194 
196  virtual std::vector< std::string, ALLOC< std::string > >
197  _variableNames() = 0;
198 
200 
201  virtual const std::vector< std::string, ALLOC< std::string > >&
203 
205 
206  virtual const DBRow< DBCell, ALLOC >& _currentDBCellRow();
207 
209  virtual bool _nextRow() = 0;
210 
211 
212 #ifndef DOXYGEN_SHOULD_SKIP_THIS
213 
214  private:
215  // the names of the variables
216  std::vector< std::string, ALLOC< std::string > > __var_names;
217 
218  // the types of the input data read to fill the database
219  InputType __input_type;
220 
221  // indicates whether an exception was raised when adding the last row
222  // into the database. If so, when filling again the database, we may
223  // try to insert again the same row
224  bool __last_insertion_failed{false};
225 
226 
228  template < template < template < typename > class > class DATABASE >
229  void __fillDatabaseFromStrings(DATABASE< ALLOC >& database,
230  const bool retry_insertion);
231 
233  template < template < template < typename > class > class DATABASE >
234  void __fillDatabaseFromDBCells(DATABASE< ALLOC >& database,
235  const bool retry_insertion);
236 
237 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
238  };
239 
240  } /* namespace learning */
241 
242 } /* namespace gum */
243 
244 // always include the template implementation
246 
247 #endif /* GUM_LEARNING_IDB_INITILIALIZER_H */
const std::vector< std::string, ALLOC< std::string > > & variableNames()
returns the names of the variables in the input dataset
virtual std::vector< std::string, ALLOC< std::string > > _variableNames()=0
ask the child class for the names of the variables
virtual const DBRow< DBCell, ALLOC > & _currentDBCellRow()
asks the child class for the content of the current row using dbcells
allocator_type getAllocator() const
returns the allocator used
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
IDBInitializer< ALLOC > & operator=(const IDBInitializer< ALLOC > &from)
copy operator
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
void fillDatabase(DATABASE< ALLOC > &database, const bool retry_insertion=false)
fills the rows of the database table
InputType
the enumeration indicating the type of the data the IDBInitializer expects as input data ...
virtual bool _nextRow()=0
indicates whether there is a next row to read (and point on it)
The class for storing a record in a database.
Definition: DBRow.h:56
ALLOC< std::string > allocator_type
type for the allocators passed in arguments of methods
virtual const std::vector< std::string, ALLOC< std::string > > & _currentStringRow()
asks the child class for the content of the current row using strings
IDBInitializer(const InputType type, const allocator_type &alloc)
default constructor
std::size_t throwingColumn() const
This method indicates which column filling raised an exception, if any, during the execution of fillD...
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
virtual ~IDBInitializer()
destructor
The base class for initializing DatabaseTable and RawDatabaseTable instances from CSV files or SQL da...
virtual IDBInitializer< ALLOC > * clone() const =0
virtual copy constructor