aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
IDBInitializer.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2025 by *
5 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
6 * - Christophe GONZALES(_at_AMU) *
7 * *
8 * The aGrUM/pyAgrum library is free software; you can redistribute it *
9 * and/or modify it under the terms of either : *
10 * *
11 * - the GNU Lesser General Public License as published by *
12 * the Free Software Foundation, either version 3 of the License, *
13 * or (at your option) any later version, *
14 * - the MIT license (MIT), *
15 * - or both in dual license, as here. *
16 * *
17 * (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18 * *
19 * This aGrUM/pyAgrum library is distributed in the hope that it will be *
20 * useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26 * OTHER DEALINGS IN THE SOFTWARE. *
27 * *
28 * See LICENCES for more details. *
29 * *
30 * SPDX-FileCopyrightText: Copyright 2005-2025 *
31 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
32 * - Christophe GONZALES(_at_AMU) *
33 * SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34 * *
35 * Contact : info_at_agrum_dot_org *
36 * homepage : http://agrum.gitlab.io *
37 * gitlab : https://gitlab.com/agrumery/agrum *
38 * *
39 ****************************************************************************/
40
41
48#ifndef GUM_LEARNING_IDB_INITILIALIZER_H
49#define GUM_LEARNING_IDB_INITILIALIZER_H
50
51#include <string>
52#include <vector>
53
54#include <agrum/agrum.h>
55
58
59namespace gum {
60
61 namespace learning {
62
136 public:
139 enum class InputType : char { STRING, DBCELL };
140
141 // ##########################################################################
143 // ##########################################################################
145
147
150
153
156
158 virtual IDBInitializer* clone() const = 0;
159
162
164
165
166 // ##########################################################################
168 // ##########################################################################
170
172 const std::vector< std::string >& variableNames();
173
175
177 template < class DATABASE >
178 void fillDatabase(DATABASE& database, const bool retry_insertion = false);
179
182 std::size_t throwingColumn() const;
183
185
186
187 protected:
190
193
195 virtual std::vector< std::string > variableNames_() = 0;
196
198
199 virtual const std::vector< std::string >& currentStringRow_();
200
202
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 > _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 < class DATABASE >
226 void _fillDatabaseFromStrings_(DATABASE& database, const bool retry_insertion);
227
229 template < class DATABASE >
230 void _fillDatabaseFromDBCells_(DATABASE& database, const bool retry_insertion);
231
232#endif /* DOXYGEN_SHOULD_SKIP_THIS */
233 };
234
235 } /* namespace learning */
236
237} /* namespace gum */
238
240#ifndef GUM_NO_INLINE
242#endif /* GUM_NO_INLINE */
243
244// always include the template implementation
246
247#endif /* GUM_LEARNING_IDB_INITILIALIZER_H */
The class representing the original values of the cells of databases.
The class representing a record stored in a tabular database.
Inlined implementation for initializing DatabaseTables and RawDatabaseTables from files or sql databa...
The base class for initializing DatabaseTables and RawDatabaseTables from files or sql databases.
The class for storing a record in a database.
Definition DBRow.h:75
virtual ~IDBInitializer()
destructor
IDBInitializer & operator=(const IDBInitializer &from)
copy operator
virtual const DBRow< DBCell > & currentDBCellRow_()
asks the child class for the content of the current row using dbcells
virtual IDBInitializer * clone() const =0
virtual copy constructor
IDBInitializer & operator=(IDBInitializer &&from)
move operator
IDBInitializer(IDBInitializer &&from)
move constructor
IDBInitializer(const InputType type)
default constructor
void fillDatabase(DATABASE &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 std::vector< std::string > variableNames_()=0
ask the child class for the names of the variables
virtual bool nextRow_()=0
indicates whether there is a next row to read (and point on it)
const std::vector< std::string > & variableNames()
returns the names of the variables in the input dataset
std::size_t throwingColumn() const
This method indicates which column filling raised an exception, if any, during the execution of fillD...
IDBInitializer(const IDBInitializer &from)
copy constructor
virtual const std::vector< std::string > & currentStringRow_()
asks the child class for the content of the current row using strings
include the inlined functions if necessary
Definition CSVParser.h:54
gum is the global namespace for all aGrUM entities
Definition agrum.h:46