27 #ifndef GUM_LEARNING_DB_ROW_H 28 #define GUM_LEARNING_DB_ROW_H 32 #include <initializer_list> 36 #include <agrum/agrum.h> 53 template <
typename T_DATA,
54 template <
typename >
class ALLOC = std::allocator >
57 using allocator_type = ALLOC< T_DATA >;
69 DBRow(
const ALLOC< T_DATA >& alloc);
72 DBRow(
const std::size_t size,
73 const double weight = 1.0,
74 const ALLOC< T_DATA >& alloc = ALLOC< T_DATA >());
77 DBRow(
const std::size_t size,
78 const T_DATA default_value,
80 const ALLOC< T_DATA >& alloc = ALLOC< T_DATA >());
83 DBRow(std::initializer_list< T_DATA > list,
84 const double weight = 1.0,
85 const ALLOC< T_DATA >& alloc = ALLOC< T_DATA >());
88 template <
template <
typename >
class OTHER_ALLOC >
89 DBRow(
const std::vector< T_DATA, OTHER_ALLOC< T_DATA > >& cells,
90 const double weight = 1.0,
91 const ALLOC< T_DATA >& alloc = ALLOC< T_DATA >());
94 DBRow(std::vector< T_DATA, ALLOC< T_DATA > >&& cells,
95 const double weight = 1.0,
96 const ALLOC< T_DATA >& alloc = ALLOC< T_DATA >());
99 DBRow(
const DBRow< T_DATA, ALLOC >& from);
102 DBRow(
const DBRow< T_DATA, ALLOC >& from,
const ALLOC< T_DATA >& alloc);
105 DBRow(DBRow< T_DATA, ALLOC >&& from);
108 DBRow(DBRow< T_DATA, ALLOC >&& from,
const ALLOC< T_DATA >& alloc);
138 T_DATA&
operator[](
const std::size_t i);
144 const T_DATA&
operator[](
const std::size_t i)
const;
156 const std::vector< T_DATA, ALLOC< T_DATA > >&
row()
const noexcept;
159 std::vector< T_DATA, ALLOC< T_DATA > >&
row()
noexcept;
162 const double&
weight()
const noexcept;
165 double&
weight()
noexcept;
168 template <
template <
typename >
class OTHER_ALLOC >
169 void setRow(
const std::vector< T_DATA, OTHER_ALLOC< T_DATA > >& new_row);
172 void setRow(std::vector< T_DATA, ALLOC< T_DATA > >&& new_row);
178 std::size_t
size()
const noexcept;
181 void resize(
const std::size_t new_size);
184 void reserve(
const std::size_t new_size);
200 std::vector< T_DATA, ALLOC< T_DATA > >
row_;
206 template <
typename TX_DATA,
template <
typename >
class OTHER_ALLOC >
215 #include <agrum/tools/database/DBRow_tpl.h> std::vector< T_DATA, ALLOC< T_DATA > > row_
the row itself
double & weight() noexcept
returns the weight assigned to the DBRow
DBRow< T_DATA, ALLOC > * clone() const
virtual copy constructor
INLINE void emplace(Args &&... args)
DBRow(const DBRow< T_DATA, ALLOC > &from)
copy constructor
void setRow(std::vector< T_DATA, ALLOC< T_DATA > > &&new_row)
sets a new row (without changing the weight)
DBRow(DBRow< T_DATA, ALLOC > &&from)
move constructor
DBRow(std::vector< T_DATA, ALLOC< T_DATA > > &&cells, const double weight=1.0, const ALLOC< T_DATA > &alloc=ALLOC< T_DATA >())
initializer with a move from a vector of cells
DBRow()
default constructor
DBRow< T_DATA, ALLOC > & operator=(const DBRow< T_DATA, ALLOC > &from)
copy operator
void pushBack(T_DATA &&elt)
adds a new element at the end of the row
DBRow(const ALLOC< T_DATA > &alloc)
default constructor with specific allocator
DBRow< T_DATA, ALLOC > * clone(const ALLOC< T_DATA > &alloc) const
virtual copy constructor with a given allocator
void setRow(const std::vector< T_DATA, OTHER_ALLOC< T_DATA > > &new_row)
sets a new row (without changing the weight)
void setWeight(const double new_weight)
sets a new weight
double weight_
the weight of the row
DBRow(const std::size_t size, const double weight=1.0, const ALLOC< T_DATA > &alloc=ALLOC< T_DATA >())
constructs a row of a given size with missing values
DBRow(const DBRow< T_DATA, ALLOC > &from, const ALLOC< T_DATA > &alloc)
copy constructor with a given allocator
const T_DATA & operator[](const std::size_t i) const
returns the ith content of the row
const std::vector< T_DATA, ALLOC< T_DATA > > & row() const noexcept
returns the current row (without the weight)
const double & weight() const noexcept
returns the weight assigned to the DBRow
DBRow(DBRow< T_DATA, ALLOC > &&from, const ALLOC< T_DATA > &alloc)
move constructor with a given allocator
void resize(const std::size_t new_size)
resize a given row, i.e., its number of elements
DBRow< T_DATA, ALLOC > & operator=(DBRow< T_DATA, ALLOC > &&from)
move operator
std::vector< T_DATA, ALLOC< T_DATA > > & row() noexcept
returns the current row (without the weight)
DBRow(const std::size_t size, const T_DATA default_value, const double weight, const ALLOC< T_DATA > &alloc=ALLOC< T_DATA >())
constructor with a given size for the row
Database(const std::string &filename, const BayesNet< GUM_SCALAR > &bn, const std::vector< std::string > &missing_symbols)
std::size_t size() const noexcept
returns the number of elements in the row
T_DATA & operator[](const std::size_t i)
returns the ith content of the row
void reserve(const std::size_t new_size)
reserve a size for the elements of a given row
DBRow(std::initializer_list< T_DATA > list, const double weight=1.0, const ALLOC< T_DATA > &alloc=ALLOC< T_DATA >())
initializer list constructor
DBRow(const std::vector< T_DATA, OTHER_ALLOC< T_DATA > > &cells, const double weight=1.0, const ALLOC< T_DATA > &alloc=ALLOC< T_DATA >())
initializer from a vector of cells
ALLOC< T_DATA > getAllocator() const
returns the allocator used by the DBRow
void pushBack(const T_DATA &elt)
adds a new element at the end of the row