aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
gum::learning::DBHandler< T_DATA, ALLOC > Class Template Referenceabstract

The base class for all database handlers. More...

#include <agrum/tools/database/DBHandler.h>

+ Inheritance diagram for gum::learning::DBHandler< T_DATA, ALLOC >:

Public Member Functions

Accessors / Modifiers
virtual std::size_t size () const =0
 returns the number of rows managed by the handler More...
 
virtual std::size_t DBSize () const =0
 the number of rows in the whole database More...
 
virtual const_reference rowSafe () const =0
 returns the current row of the database (safe version) More...
 
virtual reference rowSafe ()=0
 returns the current row of the database (safe version) More...
 
virtual const_reference row () const =0
 returns the current row pointed to by the handler (unsafe version) More...
 
virtual reference row ()=0
 returns the current row pointed to by the handler (unsafe version) More...
 
virtual void nextRow ()=0
 go to the next row in the database More...
 
virtual std::size_t numRow () const =0
 number of row the handler points to (from the beginning of the area) More...
 
virtual bool hasRows () const =0
 indicates wether there are still rows to parse in the database More...
 
virtual void reset ()=0
 puts the handler to the beginning of the database area it handles More...
 
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 More...
 
virtual std::pair< std::size_t, std::size_t > range () const =0
 returns the current range of rows of the handler More...
 
virtual const DBVector< std::string > & variableNames () const =0
 returns the names of the variables corresponding to the rows More...
 
virtual std::size_t nbVariables () const =0
 returns the number of variables (columns) of the database More...
 

Public Types

template<typename TX_DATA >
using DBVector = std::vector< TX_DATA, ALLOC< TX_DATA > >
 the type for the allocated vectors in IDatabases More...
 
using iterator_category = std::random_access_iterator_tag
 Types for STL compliance. More...
 
using value_type = DBRow< T_DATA, ALLOC >
 Types for STL compliance. More...
 
using reference = value_type &
 Types for STL compliance. More...
 
using const_reference = const value_type &
 Types for STL compliance. More...
 
using pointer = value_type *
 Types for STL compliance. More...
 
using const_pointer = const value_type *
 Types for STL compliance. More...
 
using size_type = std::size_t
 Types for STL compliance. More...
 
using difference_type = std::ptrdiff_t
 Types for STL compliance. More...
 
using allocator_type = ALLOC< void >
 Types for STL compliance. More...
 

Detailed Description

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
class gum::learning::DBHandler< T_DATA, ALLOC >

The base class for all database handlers.

Here is an example of how to use this class, illustrated on handlers for a RawDatabaseTable:

// create the database
database.setVariableNames( std::vector<std::string> { "v1", "v2", "v3" } );
// add one row to the database
database.insertRow( row );
// create a safe and an unsafe handler. Those inherit from DBHandler
typename gum::learning::RawDatabaseTable<>::Handler uhandler( database );
// by default, the handlers range over the whole database, which
// currently contains only one row
// here, we add 5 new rows into the database
for ( int i = 0; i < 5; ++i ) database.insertRow( row );
// due to the addition of the rows, the safe handler is aware that there
// are now 6 rows. The unsafe handler still thinks there is only one row
std::cout << handler.range().second; // displays 6 (the last area's element)
std::cout << handler.size (); // displays 6 (handler's range)
std::cout << handler.DBSize (); // displays 6 (database's size)
std::cout << uhandler.size (); // displays 1 (handler's range)
std::cout << uhandler.DBSize (); // displays 6 (database's size)
// change the range of rows handled by the DBHandler
std::cout << handler.setRange ( 1, 4 ); // now parses rows [1,4)
std::cout << handler.size (); // displays 3: rows 1, 2, and 3
std::cout << handler.DBSize (); // displays 6: database's size
std::cout << handler.numRow (); // displays 0: the handler currently
// points on the first row of its managed area [1,4)
uhandler.setRange ( 1, 4 ); // uhandler now parsed rows [1,4)
std::cout << uhandler.size (); // displays 3: rows 1, 2, and 3
std::cout << uhandler.DBSize (); // displays 6: database's size
std::cout << uhandler.numRow (); // displays 0: the handler currently
// points on the first row of its managed area [1,4)
// move the handler to the next row
handler.nextRow();
std::cout << handler.numRow (); // displays 1: the handler points now
// on the second row of its managed area. This corresponds to the third
// DBRow of the database since the range of handler is [1,4)
// get the DBRow pointed to by the handler: this is the 3rd DBRow
// of the database
auto& xrow2 = handler.row (); // get the DBRow, unsafe version
auto& yrow2 = handler.rowSafe (); // get the DBRow, safe version
const std::vector<gum::learning::DBCell>& xrow = xrow2.row ();
const double xweight = xrow2.weight ();
// check whether there exist other rows managed by the handler after
// the current row
bool has_rows = handler.hasRows (); // true: there is still the 4th row
handler.nextRow();
bool has_rows2 = handler.hasRows (); // false: the 4th row is the last one
// makes the handler point again on the 2nd row of the database
handler.reset ();
std::cout << handler.numRow (); // displays 0: the handler currently
// points on the first row of its managed area [1,4)
// see the variables' names, i.e., the names of the database's columns
const auto& vars = handler.variableNames();

Definition at line 119 of file DBHandler.h.

Member Typedef Documentation

◆ allocator_type

template<typename T_DATA , template< typename > class ALLOC = std::allocator>
using gum::learning::DBHandler< T_DATA, ALLOC >::allocator_type = ALLOC< void >

Types for STL compliance.

Definition at line 131 of file DBHandler.h.

◆ const_pointer

template<typename T_DATA , template< typename > class ALLOC = std::allocator>
using gum::learning::DBHandler< T_DATA, ALLOC >::const_pointer = const value_type*

Types for STL compliance.

Definition at line 128 of file DBHandler.h.

◆ const_reference

template<typename T_DATA , template< typename > class ALLOC = std::allocator>
using gum::learning::DBHandler< T_DATA, ALLOC >::const_reference = const value_type&

Types for STL compliance.

Definition at line 126 of file DBHandler.h.

◆ DBVector

template<typename T_DATA , template< typename > class ALLOC = std::allocator>
template<typename TX_DATA >
using gum::learning::DBHandler< T_DATA, ALLOC >::DBVector = std::vector< TX_DATA, ALLOC< TX_DATA > >

the type for the allocated vectors in IDatabases

Definition at line 136 of file DBHandler.h.

◆ difference_type

template<typename T_DATA , template< typename > class ALLOC = std::allocator>
using gum::learning::DBHandler< T_DATA, ALLOC >::difference_type = std::ptrdiff_t

Types for STL compliance.

Definition at line 130 of file DBHandler.h.

◆ iterator_category

template<typename T_DATA , template< typename > class ALLOC = std::allocator>
using gum::learning::DBHandler< T_DATA, ALLOC >::iterator_category = std::random_access_iterator_tag

Types for STL compliance.

Definition at line 123 of file DBHandler.h.

◆ pointer

template<typename T_DATA , template< typename > class ALLOC = std::allocator>
using gum::learning::DBHandler< T_DATA, ALLOC >::pointer = value_type*

Types for STL compliance.

Definition at line 127 of file DBHandler.h.

◆ reference

template<typename T_DATA , template< typename > class ALLOC = std::allocator>
using gum::learning::DBHandler< T_DATA, ALLOC >::reference = value_type&

Types for STL compliance.

Definition at line 125 of file DBHandler.h.

◆ size_type

template<typename T_DATA , template< typename > class ALLOC = std::allocator>
using gum::learning::DBHandler< T_DATA, ALLOC >::size_type = std::size_t

Types for STL compliance.

Definition at line 129 of file DBHandler.h.

◆ value_type

template<typename T_DATA , template< typename > class ALLOC = std::allocator>
using gum::learning::DBHandler< T_DATA, ALLOC >::value_type = DBRow< T_DATA, ALLOC >

Types for STL compliance.

Definition at line 124 of file DBHandler.h.

Member Function Documentation

◆ DBSize()

template<typename T_DATA , template< typename > class ALLOC = std::allocator>
virtual std::size_t gum::learning::DBHandler< T_DATA, ALLOC >::DBSize ( ) const
pure virtual

the number of rows in the whole database

Implemented in gum::learning::IDatabaseTable< T_DATA, ALLOC >::Handler.

◆ hasRows()

template<typename T_DATA , template< typename > class ALLOC = std::allocator>
virtual bool gum::learning::DBHandler< T_DATA, ALLOC >::hasRows ( ) const
pure virtual

indicates wether there are still rows to parse in the database

Remember that the handler manages only a specified area of the database, so the method just indicates whether there still remains rows in the area.

Implemented in gum::learning::IDatabaseTable< T_DATA, ALLOC >::Handler.

◆ nbVariables()

template<typename T_DATA , template< typename > class ALLOC = std::allocator>
virtual std::size_t gum::learning::DBHandler< T_DATA, ALLOC >::nbVariables ( ) const
pure virtual

returns the number of variables (columns) of the database

Implemented in gum::learning::IDatabaseTable< T_DATA, ALLOC >::Handler.

◆ nextRow()

template<typename T_DATA , template< typename > class ALLOC = std::allocator>
virtual void gum::learning::DBHandler< T_DATA, ALLOC >::nextRow ( )
pure virtual

go to the next row in the database

Warning
If there is no more row, i.e., you are already on the last DBRow managed or you point already to the end of the area, then the handler will point on the end of the area. In particular, this will not raise any exception.

Implemented in gum::learning::IDatabaseTable< T_DATA, ALLOC >::Handler.

◆ numRow()

template<typename T_DATA , template< typename > class ALLOC = std::allocator>
virtual std::size_t gum::learning::DBHandler< T_DATA, ALLOC >::numRow ( ) const
pure virtual

number of row the handler points to (from the beginning of the area)

This method assigns 0 to the first row in the area handled by the handler. So the number returned is the number of rows between the currently pointed one to the beginning of the area handled.

Implemented in gum::learning::IDatabaseTable< T_DATA, ALLOC >::Handler.

◆ range()

template<typename T_DATA , template< typename > class ALLOC = std::allocator>
virtual std::pair< std::size_t, std::size_t > gum::learning::DBHandler< T_DATA, ALLOC >::range ( ) const
pure virtual

returns the current range of rows of the handler

The range returned is of type [begin,end), i.e., the first row of the range managed by the DBHandler has index begin in the whole database, and the last row of the range has index end-1 in the whole database. The endth row is therefore the first one outside the range.

Implemented in gum::learning::IDatabaseTable< T_DATA, ALLOC >::Handler.

◆ reset()

template<typename T_DATA , template< typename > class ALLOC = std::allocator>
virtual void gum::learning::DBHandler< T_DATA, ALLOC >::reset ( )
pure virtual

puts the handler to the beginning of the database area it handles

Implemented in gum::learning::IDatabaseTable< T_DATA, ALLOC >::Handler.

◆ row() [1/2]

template<typename T_DATA , template< typename > class ALLOC = std::allocator>
virtual const_reference gum::learning::DBHandler< T_DATA, ALLOC >::row ( ) const
pure virtual

returns the current row pointed to by the handler (unsafe version)

Warning
The method does not check whether the handler already points to the end of its area. It is thus faster than method rowSafe () but, when you call it, you must be sure that the row actually exists, i.e., that the handler has not reached its end.

Implemented in gum::learning::IDatabaseTable< T_DATA, ALLOC >::Handler.

◆ row() [2/2]

template<typename T_DATA , template< typename > class ALLOC = std::allocator>
virtual reference gum::learning::DBHandler< T_DATA, ALLOC >::row ( )
pure virtual

returns the current row pointed to by the handler (unsafe version)

Warning
The method does not check whether the handler already points to the end of its area. It is thus faster than method rowSafe () but, when you call it, you must be sure that the row actually exists, i.e., that the handler has not reached its end.

Implemented in gum::learning::IDatabaseTable< T_DATA, ALLOC >::Handler.

◆ rowSafe() [1/2]

template<typename T_DATA , template< typename > class ALLOC = std::allocator>
virtual const_reference gum::learning::DBHandler< T_DATA, ALLOC >::rowSafe ( ) const
pure virtual

returns the current row of the database (safe version)

Exceptions
OutOfBoundsis raised if the handler points outside of its area

Implemented in gum::learning::IDatabaseTable< T_DATA, ALLOC >::Handler.

◆ rowSafe() [2/2]

template<typename T_DATA , template< typename > class ALLOC = std::allocator>
virtual reference gum::learning::DBHandler< T_DATA, ALLOC >::rowSafe ( )
pure virtual

returns the current row of the database (safe version)

Exceptions
OutOfBoundsis raised if the handler points outside of its area

Implemented in gum::learning::IDatabaseTable< T_DATA, ALLOC >::Handler.

◆ setRange()

template<typename T_DATA , template< typename > class ALLOC = std::allocator>
virtual void gum::learning::DBHandler< T_DATA, ALLOC >::setRange ( std::size_t  begin,
std::size_t  end 
)
pure virtual

sets the range of rows in the database that the handler will parse

The range provided in arguments specifies that area [begin,end) is the one managed by the DBHandler, i.e., the first row of the area has index begin in the whole database, and the last row of the area has index end-1 in the whole database. The endth row is the first one outside the area.

Parameters
beginthe number of the row in the whole database that will be the first one in the area managed by the DBHandler.
endthe number of the row in the whole database from which the DBHandler considers it is outside of its area.

Implemented in gum::learning::IDatabaseTable< T_DATA, ALLOC >::Handler.

◆ size()

template<typename T_DATA , template< typename > class ALLOC = std::allocator>
virtual std::size_t gum::learning::DBHandler< T_DATA, ALLOC >::size ( ) const
pure virtual

returns the number of rows managed by the handler

A handler needs not necessarily handle all the rows of the database. For instance, RecordCounters cut the database into several pieces and assign each piece to a handler. Then each handler is used in parallel to perform countings only on a subset of the database

Implemented in gum::learning::IDatabaseTable< T_DATA, ALLOC >::Handler.

◆ variableNames()

template<typename T_DATA , template< typename > class ALLOC = std::allocator>
virtual const DBVector< std::string >& gum::learning::DBHandler< T_DATA, ALLOC >::variableNames ( ) const
pure virtual

returns the names of the variables corresponding to the rows

Implemented in gum::learning::IDatabaseTable< T_DATA, ALLOC >::Handler.


The documentation for this class was generated from the following file: