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,
template <
typename >
class ALLOC = std::allocator >
56 using allocator_type = ALLOC< T_DATA >;
68 DBRow(
const ALLOC< T_DATA >& alloc);
71 DBRow(
const std::size_t size,
72 const double weight = 1.0,
73 const ALLOC< T_DATA >& alloc = ALLOC< T_DATA >());
76 DBRow(
const std::size_t size,
77 const T_DATA default_value,
79 const ALLOC< T_DATA >& alloc = ALLOC< T_DATA >());
82 DBRow(std::initializer_list< T_DATA > list,
83 const double weight = 1.0,
84 const ALLOC< T_DATA >& alloc = ALLOC< T_DATA >());
87 template <
template <
typename >
class OTHER_ALLOC >
88 DBRow(
const std::vector< T_DATA, OTHER_ALLOC< T_DATA > >& cells,
89 const double weight = 1.0,
90 const ALLOC< T_DATA >& alloc = ALLOC< T_DATA >());
93 DBRow(std::vector< T_DATA, ALLOC< T_DATA > >&& cells,
94 const double weight = 1.0,
95 const ALLOC< T_DATA >& alloc = ALLOC< T_DATA >());
98 DBRow(
const DBRow< T_DATA, ALLOC >& from);
101 DBRow(
const DBRow< T_DATA, ALLOC >& from,
const ALLOC< T_DATA >& alloc);
104 DBRow(DBRow< T_DATA, ALLOC >&& from);
107 DBRow(DBRow< T_DATA, ALLOC >&& from,
const ALLOC< T_DATA >& alloc);
137 T_DATA&
operator[](
const std::size_t i);
143 const T_DATA&
operator[](
const std::size_t i)
const;
155 const std::vector< T_DATA, ALLOC< T_DATA > >&
row()
const noexcept;
158 std::vector< T_DATA, ALLOC< T_DATA > >&
row()
noexcept;
161 const double&
weight()
const noexcept;
164 double&
weight()
noexcept;
167 template <
template <
typename >
class OTHER_ALLOC >
168 void setRow(
const std::vector< T_DATA, OTHER_ALLOC< T_DATA > >& new_row);
171 void setRow(std::vector< T_DATA, ALLOC< T_DATA > >&& new_row);
177 std::size_t
size()
const noexcept;
180 void resize(
const std::size_t new_size);
183 void reserve(
const std::size_t new_size);
199 std::vector< T_DATA, ALLOC< T_DATA > >
row_;
205 template <
typename TX_DATA,
template <
typename >
class OTHER_ALLOC >
214 #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