aGrUM  0.16.0
DBRow.h
Go to the documentation of this file.
1 
28 #ifndef GUM_LEARNING_DB_ROW_H
29 #define GUM_LEARNING_DB_ROW_H
30 
31 #include <cstddef>
32 #include <cstring>
33 #include <initializer_list>
34 #include <memory>
35 #include <vector>
36 
37 #include <agrum/agrum.h>
38 
39 namespace gum {
40 
41  namespace learning {
42 
54  template < typename T_DATA,
55  template < typename > class ALLOC = std::allocator >
56  class DBRow {
57  public:
58  using allocator_type = ALLOC< T_DATA >;
59 
60  // ##########################################################################
62  // ##########################################################################
63 
65 
67  DBRow();
68 
70  DBRow(const ALLOC< T_DATA >& alloc);
71 
73  DBRow(const std::size_t size,
74  const double weight = 1.0,
75  const ALLOC< T_DATA >& alloc = ALLOC< T_DATA >());
76 
78  DBRow(const std::size_t size,
79  const T_DATA default_value,
80  const double weight,
81  const ALLOC< T_DATA >& alloc = ALLOC< T_DATA >());
82 
84  DBRow(std::initializer_list< T_DATA > list,
85  const double weight = 1.0,
86  const ALLOC< T_DATA >& alloc = ALLOC< T_DATA >());
87 
89  template < template < typename > class OTHER_ALLOC >
90  DBRow(const std::vector< T_DATA, OTHER_ALLOC< T_DATA > >& cells,
91  const double weight = 1.0,
92  const ALLOC< T_DATA >& alloc = ALLOC< T_DATA >());
93 
95  DBRow(std::vector< T_DATA, ALLOC< T_DATA > >&& cells,
96  const double weight = 1.0,
97  const ALLOC< T_DATA >& alloc = ALLOC< T_DATA >());
98 
100  DBRow(const DBRow< T_DATA, ALLOC >& from);
101 
103  DBRow(const DBRow< T_DATA, ALLOC >& from, const ALLOC< T_DATA >& alloc);
104 
107 
109  DBRow(DBRow< T_DATA, ALLOC >&& from, const ALLOC< T_DATA >& alloc);
110 
112  DBRow< T_DATA, ALLOC >* clone() const;
113 
115  DBRow< T_DATA, ALLOC >* clone(const ALLOC< T_DATA >& alloc) const;
116 
118  ~DBRow();
119 
121 
122 
123  // ##########################################################################
125  // ##########################################################################
126 
128 
131 
134 
136 
139  T_DATA& operator[](const std::size_t i);
140 
142 
145  const T_DATA& operator[](const std::size_t i) const;
146 
148 
149 
150  // ##########################################################################
152  // ##########################################################################
153 
155 
157  const std::vector< T_DATA, ALLOC< T_DATA > >& row() const noexcept;
158 
160  std::vector< T_DATA, ALLOC< T_DATA > >& row() noexcept;
161 
163  const double& weight() const noexcept;
164 
166  double& weight() noexcept;
167 
169  template < template < typename > class OTHER_ALLOC >
170  void setRow(const std::vector< T_DATA, OTHER_ALLOC< T_DATA > >& new_row);
171 
173  void setRow(std::vector< T_DATA, ALLOC< T_DATA > >&& new_row);
174 
176  void setWeight(const double new_weight);
177 
179  std::size_t size() const noexcept;
180 
182  void resize(const std::size_t new_size);
183 
185  void reserve(const std::size_t new_size);
186 
188  void pushBack(const T_DATA& elt);
189 
191  void pushBack(T_DATA&& elt);
192 
194  ALLOC< T_DATA > getAllocator() const;
195 
197 
198 
199  protected:
201  std::vector< T_DATA, ALLOC< T_DATA > > _row;
202 
204  double _weight{1.0f};
205 
206  // used for constructors and operators
207  template < typename TX_DATA, template < typename > class OTHER_ALLOC >
208  friend class DBRow;
209  };
210 
211  } /* namespace learning */
212 
213 } /* namespace gum */
214 
217 
218 #endif /* GUM_LEARNING_DB_ROW_H */
DBRow< T_DATA, ALLOC > * clone() const
virtual copy constructor
~DBRow()
destructor
double _weight
the weight of the row
Definition: DBRow.h:204
STL namespace.
DBRow()
default constructor
DBRow< T_DATA, ALLOC > & operator=(const DBRow< T_DATA, ALLOC > &from)
copy operator
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
ALLOC< T_DATA > allocator_type
Definition: DBRow.h:58
std::vector< T_DATA, ALLOC< T_DATA > > _row
the row itself
Definition: DBRow.h:201
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
The class for storing a record in a database.
Definition: DBRow.h:56
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
void resize(const std::size_t new_size)
resize a given row, i.e., its number of elements
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
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
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.