aGrUM  0.16.0
DBHandler.h
Go to the documentation of this file.
1 
28 #ifndef GUM_LEARNING_DB_HANDLER_H
29 #define GUM_LEARNING_DB_HANDLER_H
30 
31 #include <cstddef>
32 #include <utility>
33 #include <memory>
34 #include <vector>
35 #include <string>
36 
37 #include <agrum/agrum.h>
39 
40 namespace gum {
41 
42  namespace learning {
43 
119  template < typename T_DATA,
120  template < typename > class ALLOC = std::allocator >
121  class DBHandler {
122  public:
125  using iterator_category = std::random_access_iterator_tag;
128  using const_reference = const value_type&;
129  using pointer = value_type*;
130  using const_pointer = const value_type*;
131  using size_type = std::size_t;
132  using difference_type = std::ptrdiff_t;
133  using allocator_type = ALLOC< void >;
135 
137  template < typename TX_DATA >
138  using DBVector = std::vector< TX_DATA, ALLOC< TX_DATA > >;
139 
140 
141  // ##########################################################################
143  // ##########################################################################
144 
146 
148 
152  virtual std::size_t size() const = 0;
153 
155  virtual std::size_t DBSize() const = 0;
156 
158 
160  virtual const_reference rowSafe() const = 0;
161 
163 
165  virtual reference rowSafe() = 0;
166 
168 
172  virtual const_reference row() const = 0;
173 
175 
179  virtual reference row() = 0;
180 
182 
186  virtual void nextRow() = 0;
187 
189 
192  virtual std::size_t numRow() const = 0;
193 
195 
198  virtual bool hasRows() const = 0;
199 
201  virtual void reset() = 0;
202 
204 
213  virtual void setRange(std::size_t begin, std::size_t end) = 0;
214 
216 
220  virtual std::pair< std::size_t, std::size_t > range() const = 0;
221 
223  virtual const DBVector< std::string >& variableNames() const = 0;
224 
226  virtual std::size_t nbVariables() const = 0;
227 
229 
230 
231 #ifndef DOXYGEN_SHOULD_SKIP_THIS
232 
233  protected:
234  // the cache used to avoid cacheline problems due to parallelism
235  static constexpr int _cache_size{128};
236 
237  // a buffer to avoid cacheline problems due to parallelism
238  char _align[_cache_size];
239 
240 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
241  };
242 
243  } /* namespace learning */
244 
245 } /* namespace gum */
246 
247 #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:132
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:131
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
std::vector< TX_DATA, ALLOC< TX_DATA > > DBVector
the type for the allocated vectors in IDatabases
Definition: DBHandler.h:138
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
virtual void nextRow()=0
go to the next row in the database
The base class for all database handlers.
Definition: DBHandler.h:121
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:125
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:56
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:133
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)