aGrUM  0.14.2
IDBInitializer.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  ***************************************************************************/
26 #ifndef GUM_LEARNING_IDB_INITILIALIZER_H
27 #define GUM_LEARNING_IDB_INITILIALIZER_H
28 
29 #include <vector>
30 #include <string>
31 
32 #include <agrum/agrum.h>
35 
36 
37 namespace gum {
38 
39  namespace learning {
40 
113  template < template < typename > class ALLOC >
115  public:
118  enum class InputType : char { STRING, DBCELL };
119 
121  using allocator_type = ALLOC< std::string >;
122 
123  // ##########################################################################
125  // ##########################################################################
127 
129 
132  IDBInitializer(const InputType type, const allocator_type& alloc);
133 
136 
139  const allocator_type& alloc);
140 
143 
146 
148  virtual IDBInitializer< ALLOC >* clone() const = 0;
149 
151  virtual IDBInitializer< ALLOC >*
152  clone(const allocator_type& alloc) const = 0;
153 
155  virtual ~IDBInitializer();
156 
158 
159 
160  // ##########################################################################
162  // ##########################################################################
164 
166  const std::vector< std::string, ALLOC< std::string > >& variableNames();
167 
169 
171  template < template < template < typename > class > class DATABASE >
172  void fillDatabase(DATABASE< ALLOC >& database,
173  const bool retry_insertion = false);
174 
177  std::size_t throwingColumn() const;
178 
181 
183 
184 
185  protected:
188 
191 
193  virtual std::vector< std::string, ALLOC< std::string > >
194  _variableNames() = 0;
195 
197 
198  virtual const std::vector< std::string, ALLOC< std::string > >&
200 
202 
203  virtual const DBRow< DBCell, ALLOC >& _currentDBCellRow();
204 
206  virtual bool _nextRow() = 0;
207 
208 
209 #ifndef DOXYGEN_SHOULD_SKIP_THIS
210 
211  private:
212  // the names of the variables
213  std::vector< std::string, ALLOC< std::string > > __var_names;
214 
215  // the types of the input data read to fill the database
216  InputType __input_type;
217 
218  // indicates whether an exception was raised when adding the last row
219  // into the database. If so, when filling again the database, we may
220  // try to insert again the same row
221  bool __last_insertion_failed{false};
222 
223 
225  template < template < template < typename > class > class DATABASE >
226  void __fillDatabaseFromStrings(DATABASE< ALLOC >& database,
227  const bool retry_insertion);
228 
230  template < template < template < typename > class > class DATABASE >
231  void __fillDatabaseFromDBCells(DATABASE< ALLOC >& database,
232  const bool retry_insertion);
233 
234 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
235  };
236 
237  } /* namespace learning */
238 
239 } /* namespace gum */
240 
241 // always include the template implementation
243 
244 #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
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
The class representing a record stored in a tabular database.
IDBInitializer< ALLOC > & operator=(const IDBInitializer< ALLOC > &from)
copy operator
The class representing the original values of the cells of databases.
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:53
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...
The base class for initializing DatabaseTables and RawDatabaseTables from files or sql databases...
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