aGrUM  0.16.0
DBRow_tpl.h
Go to the documentation of this file.
1 
28 #ifndef DOXYGEN_SHOULD_SKIP_THIS
29 
30 # include <algorithm>
32 
33 namespace gum {
34 
35  namespace learning {
36 
38  template < typename T_DATA, template < typename > class ALLOC >
39  INLINE ALLOC< T_DATA > DBRow< T_DATA, ALLOC >::getAllocator() const {
40  return _row.get_allocator();
41  }
42 
43 
45  template < typename T_DATA, template < typename > class ALLOC >
46  INLINE DBRow< T_DATA, ALLOC >::DBRow(const ALLOC< T_DATA >& alloc) :
47  _row(alloc) {
48  GUM_CONSTRUCTOR(DBRow);
49  }
50 
51 
53  template < typename T_DATA, template < typename > class ALLOC >
54  INLINE DBRow< T_DATA, ALLOC >::DBRow() : DBRow(ALLOC< T_DATA >()) {}
55 
56 
58  template < typename T_DATA, template < typename > class ALLOC >
59  INLINE DBRow< T_DATA, ALLOC >::DBRow(const std::size_t size,
60  const T_DATA default_cell,
61  const double weight,
62  const ALLOC< T_DATA >& alloc) :
63  _row(size, default_cell, alloc),
64  _weight(weight) {
65  GUM_CONSTRUCTOR(DBRow);
66  }
67 
68 
70  template < typename T_DATA, template < typename > class ALLOC >
71  INLINE DBRow< T_DATA, ALLOC >::DBRow(const std::size_t size,
72  const double weight,
73  const ALLOC< T_DATA >& alloc) :
74  DBRow(size, T_DATA(), weight, alloc) {}
75 
77  template < typename T_DATA, template < typename > class ALLOC >
78  INLINE DBRow< T_DATA, ALLOC >::DBRow(std::initializer_list< T_DATA > list,
79  const double weight,
80  const ALLOC< T_DATA >& alloc) :
81  _row(list, alloc),
82  _weight(weight) {
83  GUM_CONSTRUCTOR(DBRow);
84  }
85 
86 
88  template < typename T_DATA, template < typename > class ALLOC >
89  template < template < typename > class OTHER_ALLOC >
91  const std::vector< T_DATA, OTHER_ALLOC< T_DATA > >& new_row) {
92  const std::size_t size = new_row.size();
93  if (size) {
94  _row.resize(size);
95  std::copy(new_row.begin(), new_row.end(), _row.begin());
96  } else {
97  _row.clear();
98  }
99  }
100 
101 
103  template < typename T_DATA, template < typename > class ALLOC >
104  INLINE void DBRow< T_DATA, ALLOC >::setRow(
105  std::vector< T_DATA, ALLOC< T_DATA > >&& new_row) {
106  _row = std::move(new_row);
107  }
108 
109 
111  template < typename T_DATA, template < typename > class ALLOC >
112  template < template < typename > class OTHER_ALLOC >
114  const std::vector< T_DATA, OTHER_ALLOC< T_DATA > >& cells,
115  const double weight,
116  const ALLOC< T_DATA >& alloc) :
117  _row(alloc),
118  _weight(weight) {
119  setRow(cells);
120  GUM_CONSTRUCTOR(DBRow);
121  }
122 
123 
125  template < typename T_DATA, template < typename > class ALLOC >
127  std::vector< T_DATA, ALLOC< T_DATA > >&& cells,
128  const double weight,
129  const ALLOC< T_DATA >& alloc) :
130  _row(std::move(cells), alloc),
131  _weight(weight) {
132  GUM_CONSTRUCTOR(DBRow);
133  }
134 
135 
137  template < typename T_DATA, template < typename > class ALLOC >
138  INLINE DBRow< T_DATA, ALLOC >::DBRow(const DBRow< T_DATA, ALLOC >& from,
139  const ALLOC< T_DATA >& alloc) :
140  _row(from._row, alloc),
141  _weight(from._weight) {
142  GUM_CONS_CPY(DBRow);
143  }
144 
145 
147  template < typename T_DATA, template < typename > class ALLOC >
148  INLINE DBRow< T_DATA, ALLOC >::DBRow(const DBRow< T_DATA, ALLOC >& from) :
149  DBRow< T_DATA, ALLOC >(from, from.getAllocator()) {}
150 
151 
153  template < typename T_DATA, template < typename > class ALLOC >
154  INLINE DBRow< T_DATA, ALLOC >::DBRow(DBRow< T_DATA, ALLOC >&& from,
155  const ALLOC< T_DATA >& alloc) :
156  _row(std::move(from._row), alloc),
157  _weight(from._weight) {
158  GUM_CONS_MOV(DBRow);
159  }
160 
161 
163  template < typename T_DATA, template < typename > class ALLOC >
164  INLINE DBRow< T_DATA, ALLOC >::DBRow(DBRow< T_DATA, ALLOC >&& from) :
165  DBRow< T_DATA, ALLOC >(from, from.getAllocator()) {}
166 
167 
169  template < typename T_DATA, template < typename > class ALLOC >
170  DBRow< T_DATA, ALLOC >*
171  DBRow< T_DATA, ALLOC >::clone(const ALLOC< T_DATA >& alloc) const {
172  ALLOC< DBRow< T_DATA, ALLOC > > allocator(alloc);
173  DBRow< T_DATA, ALLOC >* row = allocator.allocate(1);
174  try {
175  allocator.construct(row, *this, alloc);
176  } catch (...) {
177  allocator.deallocate(row, 1);
178  throw;
179  }
180  return row;
181  }
182 
183 
185  template < typename T_DATA, template < typename > class ALLOC >
186  DBRow< T_DATA, ALLOC >* DBRow< T_DATA, ALLOC >::clone() const {
187  return clone(this->getAllocator());
188  }
189 
190 
192  template < typename T_DATA, template < typename > class ALLOC >
194  GUM_DESTRUCTOR(DBRow);
195  }
196 
197 
199  template < typename T_DATA, template < typename > class ALLOC >
200  INLINE DBRow< T_DATA, ALLOC >& DBRow< T_DATA, ALLOC >::
201  operator=(const DBRow< T_DATA, ALLOC >& from) {
202  if (this != &from) {
203  _row = from._row;
204  _weight = from._weight;
205  }
206  return *this;
207  }
208 
209 
211  template < typename T_DATA, template < typename > class ALLOC >
212  INLINE DBRow< T_DATA, ALLOC >& DBRow< T_DATA, ALLOC >::
213  operator=(DBRow< T_DATA, ALLOC >&& from) {
214  if (this != &from) {
215  _row = std::move(from._row);
216  _weight = from._weight;
217  }
218  return *this;
219  }
220 
222  template < typename T_DATA, template < typename > class ALLOC >
223  INLINE T_DATA& DBRow< T_DATA, ALLOC >::operator[](const std::size_t i) {
224  return _row[i];
225  }
226 
228  template < typename T_DATA, template < typename > class ALLOC >
229  INLINE const T_DATA& DBRow< T_DATA, ALLOC >::
230  operator[](const std::size_t i) const {
231  return _row[i];
232  }
233 
235  template < typename T_DATA, template < typename > class ALLOC >
236  INLINE const std::vector< T_DATA, ALLOC< T_DATA > >&
237  DBRow< T_DATA, ALLOC >::row() const noexcept {
238  return _row;
239  }
240 
242  template < typename T_DATA, template < typename > class ALLOC >
243  INLINE std::vector< T_DATA, ALLOC< T_DATA > >&
244  DBRow< T_DATA, ALLOC >::row() noexcept {
245  return _row;
246  }
247 
249  template < typename T_DATA, template < typename > class ALLOC >
250  INLINE const double& DBRow< T_DATA, ALLOC >::weight() const noexcept {
251  return _weight;
252  }
253 
255  template < typename T_DATA, template < typename > class ALLOC >
256  INLINE double& DBRow< T_DATA, ALLOC >::weight() noexcept {
257  return _weight;
258  }
259 
261  template < typename T_DATA, template < typename > class ALLOC >
262  INLINE void DBRow< T_DATA, ALLOC >::setWeight(const double new_weight) {
263  _weight = new_weight;
264  }
265 
267  template < typename T_DATA, template < typename > class ALLOC >
268  INLINE std::size_t DBRow< T_DATA, ALLOC >::size() const noexcept {
269  return _row.size();
270  }
271 
273  template < typename T_DATA, template < typename > class ALLOC >
274  INLINE void DBRow< T_DATA, ALLOC >::resize(const std::size_t new_size) {
275  _row.resize(new_size);
276  }
277 
279  template < typename T_DATA, template < typename > class ALLOC >
280  INLINE void DBRow< T_DATA, ALLOC >::reserve(const std::size_t new_size) {
281  _row.reserve(new_size);
282  }
283 
285  template < typename T_DATA, template < typename > class ALLOC >
286  INLINE void DBRow< T_DATA, ALLOC >::pushBack(const T_DATA& elt) {
287  _row.push_back(elt);
288  }
289 
291  template < typename T_DATA, template < typename > class ALLOC >
292  INLINE void DBRow< T_DATA, ALLOC >::pushBack(T_DATA&& elt) {
293  _row.push_back(std::move(elt));
294  }
295 
296 
297  } /* namespace learning */
298 
299 } /* namespace gum */
300 
301 
302 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
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
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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
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