aGrUM  0.16.0
DBInitializerFromCSV.h
Go to the documentation of this file.
1 
29 #ifndef GUM_LEARNING_DB_INITILIALIZER_FROM_CSV_H
30 #define GUM_LEARNING_DB_INITILIALIZER_FROM_CSV_H
31 
32 #include <vector>
33 #include <string>
34 #include <fstream>
35 #include <iostream>
36 #include <sstream>
37 
38 #include <agrum/agrum.h>
41 
42 namespace gum {
43 
44  namespace learning {
45 
131  template < template < typename > class ALLOC = std::allocator >
132  class DBInitializerFromCSV : public IDBInitializer< ALLOC > {
133  public:
135  using allocator_type = ALLOC< std::string >;
136 
137  // ##########################################################################
139  // ##########################################################################
141 
143 
153  DBInitializerFromCSV(const std::string filename,
154  bool fileContainsNames = true,
155  const std::string delimiter = ",",
156  const char commentmarker = '#',
157  const char quoteMarker = '"',
158  const allocator_type& alloc = allocator_type());
159 
161 
164 
166 
169  const allocator_type& alloc);
170 
173 
176  const allocator_type& alloc);
177 
179  virtual DBInitializerFromCSV< ALLOC >* clone() const;
180 
183  clone(const allocator_type& alloc) const;
184 
186  virtual ~DBInitializerFromCSV();
187 
189 
190 
191  // ##########################################################################
193  // ##########################################################################
194 
196 
198 
202 
204 
208 
210 
211 
212  protected:
214  virtual std::vector< std::string, ALLOC< std::string > >
215  _variableNames() final;
216 
218  virtual const std::vector< std::string, ALLOC< std::string > >&
219  _currentStringRow() final;
220 
222  virtual bool _nextRow() final;
223 
224 
225 #ifndef DOXYGEN_SHOULD_SKIP_THIS
226 
227  private:
228  // the filename used for parsing
229  std::string __filename;
230 
231  // indicates the delimiter used within the CSV
232  std::string __delimiter;
233 
234  // indicates which character is a comment symbol in the CSV
235  char __comment_marker;
236 
237  // indicates which character is a quote symbol in the CSV
238  char __quote_marker;
239 
240  // indicates whether the first row of the file contains the names
241  bool __first_row_has_names;
242 
243  // the input stream read by the parser
244  std::ifstream __input_stream;
245 
246  // the CSV parser used for the reading the CSV file
247  CSVParser< ALLOC > __parser;
248 
249  // the variables names, if the first row has names
250  std::vector< std::string, ALLOC< std::string > > __var_names;
251 
252 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
253  };
254 
255  } /* namespace learning */
256 
257 } /* namespace gum */
258 
259 // always include the template implementation
261 
262 
263 #endif /* GUM_LEARNING_DB_INITILIALIZER_FROM_CSV_H */
virtual std::vector< std::string, ALLOC< std::string > > _variableNames() final
returns the names of the variables
virtual ~DBInitializerFromCSV()
destructor
DBInitializerFromCSV(const std::string filename, bool fileContainsNames=true, const std::string delimiter=",", const char commentmarker='#', const char quoteMarker='"', const allocator_type& alloc = allocator_type())
default constructor
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Class for fast parsing of CSV file (never more than one line in application memory) ...
Definition: CSVParser.h:78
DBInitializerFromCSV< ALLOC > & operator=(const DBInitializerFromCSV< ALLOC > &from)
copy operator
STL namespace.
virtual DBInitializerFromCSV< ALLOC > * clone() const
virtual copy constructor
virtual bool _nextRow() final
indicates whether there is a next row to read (and point on it)
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.
virtual const std::vector< std::string, ALLOC< std::string > > & _currentStringRow() final
returns the content of the current row using strings
The class for initializing DatabaseTable and RawDatabaseTable instances from CSV files.
ALLOC< std::string > allocator_type
type for the allocators passed in arguments of methods
The base class for initializing DatabaseTable and RawDatabaseTable instances from CSV files or SQL da...
Class for fast parsing of CSV file (never more than one line in application memory) ...