aGrUM  0.14.2
DBHandler.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  ***************************************************************************/
25 #ifndef GUM_LEARNING_DB_HANDLER_H
26 #define GUM_LEARNING_DB_HANDLER_H
27 
28 #include <cstddef>
29 #include <utility>
30 #include <memory>
31 #include <vector>
32 #include <string>
33 
34 #include <agrum/agrum.h>
36 
37 namespace gum {
38 
39  namespace learning {
40 
116  template < typename T_DATA,
117  template < typename > class ALLOC = std::allocator >
118  class DBHandler {
119  public:
122  using iterator_category = std::random_access_iterator_tag;
125  using const_reference = const value_type&;
126  using pointer = value_type*;
127  using const_pointer = const value_type*;
128  using size_type = std::size_t;
129  using difference_type = std::ptrdiff_t;
130  using allocator_type = ALLOC< void >;
132 
134  template < typename TX_DATA >
135  using DBVector = std::vector< TX_DATA, ALLOC< TX_DATA > >;
136 
137 
138  // ##########################################################################
140  // ##########################################################################
141 
143 
145 
149  virtual std::size_t size() const = 0;
150 
152  virtual std::size_t DBSize() const = 0;
153 
155 
157  virtual const_reference rowSafe() const = 0;
158 
160 
162  virtual reference rowSafe() = 0;
163 
165 
169  virtual const_reference row() const = 0;
170 
172 
176  virtual reference row() = 0;
177 
179 
183  virtual void nextRow() = 0;
184 
186 
189  virtual std::size_t numRow() const = 0;
190 
192 
195  virtual bool hasRows() const = 0;
196 
198  virtual void reset() = 0;
199 
201 
210  virtual void setRange(std::size_t begin, std::size_t end) = 0;
211 
213 
217  virtual std::pair< std::size_t, std::size_t > range() const = 0;
218 
220  virtual const DBVector< std::string >& variableNames() const = 0;
221 
223  virtual std::size_t nbVariables() const = 0;
224 
226 
227 
228 #ifndef DOXYGEN_SHOULD_SKIP_THIS
229 
230  protected:
231  // the cache used to avoid cacheline problems due to parallelism
232  static constexpr int _cache_size{128};
233 
234  // a buffer to avoid cacheline problems due to parallelism
235  char _align[_cache_size];
236 
237 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
238  };
239 
240  } /* namespace learning */
241 
242 } /* namespace gum */
243 
244 #endif /* GUM_LEARNING_DB_HANDLER_H */
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
std::ptrdiff_t difference_type
Types for STL compliance.
Definition: DBHandler.h:129
virtual std::size_t nbVariables() const =0
returns the number of variables (columns) of the database
std::size_t size_type
Types for STL compliance.
Definition: DBHandler.h:128
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
std::vector< TX_DATA, ALLOC< TX_DATA > > DBVector
the type for the allocated vectors in IDatabases
Definition: DBHandler.h:135
The class representing a record stored in a tabular database.
virtual void nextRow()=0
go to the next row in the database
The base class for all database handlers.
Definition: DBHandler.h:118
virtual std::size_t size() const =0
returns the number of rows managed by the handler
std::random_access_iterator_tag iterator_category
Types for STL compliance.
Definition: DBHandler.h:122
virtual bool hasRows() const =0
indicates wether there are still rows to parse in the database
virtual const DBVector< std::string > & variableNames() const =0
returns the names of the variables corresponding to the rows
virtual const_reference rowSafe() const =0
returns the current row of the database (safe version)
The class for storing a record in a database.
Definition: DBRow.h:53
virtual void reset()=0
puts the handler to the beginning of the database area it handles
virtual std::size_t numRow() const =0
number of row the handler points to (from the beginning of the area)
virtual std::size_t DBSize() const =0
the number of rows in the whole database
ALLOC< void > allocator_type
Types for STL compliance.
Definition: DBHandler.h:130
virtual std::pair< std::size_t, std::size_t > range() const =0
returns the current range of rows of the handler
virtual const_reference row() const =0
returns the current row pointed to by the handler (unsafe version)