aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
DBHandler.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
47#ifndef GUM_LEARNING_DB_HANDLER_H
48#define GUM_LEARNING_DB_HANDLER_H
49
50#include <cstddef>
51#include <memory>
52#include <string>
53#include <utility>
54#include <vector>
55
56#include <agrum/agrum.h>
57
59
60namespace gum {
61
62 namespace learning {
63
139 template < typename T_DATA >
140 class DBHandler {
141 public:
144 using iterator_category = std::random_access_iterator_tag;
149 using const_pointer = const value_type*;
150 using size_type = std::size_t;
151 using difference_type = std::ptrdiff_t;
153
155 template < typename TX_DATA >
156 using DBVector = std::vector< TX_DATA >;
157
158
159 // ##########################################################################
161 // ##########################################################################
162
164
166
170 virtual std::size_t size() const = 0;
171
173 virtual std::size_t DBSize() const = 0;
174
176
178 virtual const_reference rowSafe() const = 0;
179
181
183 virtual reference rowSafe() = 0;
184
186
190 virtual const_reference row() const = 0;
191
193
197 virtual reference row() = 0;
198
200
204 virtual void nextRow() = 0;
205
207
210 virtual std::size_t numRow() const = 0;
211
213
216 virtual bool hasRows() const = 0;
217
219 virtual void reset() = 0;
220
222
231 virtual void setRange(std::size_t begin, std::size_t end) = 0;
232
234
238 virtual std::pair< std::size_t, std::size_t > range() const = 0;
239
241 virtual const DBVector< std::string >& variableNames() const = 0;
242
244 virtual std::size_t nbVariables() const = 0;
245
247
248
249#ifndef DOXYGEN_SHOULD_SKIP_THIS
250
251 protected:
252 // the cache used to avoid cacheline problems due to parallelism
253 static constexpr int cache_size_{128};
254
255 // a buffer to avoid cacheline problems due to parallelism
256 char align_[cache_size_];
257
258#endif /* DOXYGEN_SHOULD_SKIP_THIS */
259 };
260
261 } /* namespace learning */
262
263} /* namespace gum */
264
265#endif /* GUM_LEARNING_DB_HANDLER_H */
The class representing a record stored in a tabular database.
The base class for all database handlers.
Definition DBHandler.h:140
const value_type * const_pointer
Types for STL compliance.
Definition DBHandler.h:149
value_type & reference
Types for STL compliance.
Definition DBHandler.h:146
virtual std::pair< std::size_t, std::size_t > range() const =0
returns the current range of rows of the handler
virtual const_reference rowSafe() const =0
returns the current row of the database (safe version)
DBRow< T_DATA > value_type
Types for STL compliance.
Definition DBHandler.h:145
virtual reference row()=0
returns the current row pointed to by the handler (unsafe version)
virtual reference rowSafe()=0
returns the current row of the database (safe version)
value_type * pointer
Types for STL compliance.
Definition DBHandler.h:148
virtual std::size_t DBSize() const =0
the number of rows in the whole database
virtual std::size_t numRow() const =0
number of row the handler points to (from the beginning of the area)
std::ptrdiff_t difference_type
Types for STL compliance.
Definition DBHandler.h:151
virtual const DBVector< std::string > & variableNames() const =0
returns the names of the variables corresponding to the rows
const value_type & const_reference
Types for STL compliance.
Definition DBHandler.h:147
virtual bool hasRows() const =0
indicates wether there are still rows to parse in the database
virtual void nextRow()=0
go to the next row in the database
std::random_access_iterator_tag iterator_category
Types for STL compliance.
Definition DBHandler.h:144
virtual void setRange(std::size_t begin, std::size_t end)=0
sets the range of rows in the database that the handler will parse
virtual std::size_t size() const =0
returns the number of rows managed by the handler
virtual std::size_t nbVariables() const =0
returns the number of variables (columns) of the database
virtual void reset()=0
puts the handler to the beginning of the database area it handles
std::size_t size_type
Types for STL compliance.
Definition DBHandler.h:150
virtual const_reference row() const =0
returns the current row pointed to by the handler (unsafe version)
std::vector< TX_DATA > DBVector
the type for the allocated vectors in IDatabases
Definition DBHandler.h:156
The class for storing a record in a database.
Definition DBRow.h:75
include the inlined functions if necessary
Definition CSVParser.h:54
gum is the global namespace for all aGrUM entities
Definition agrum.h:46