aGrUM  0.21.0
a C++ library for (probabilistic) graphical models
DBRow_tpl.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright (c) 2005-2021 by Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4  * info_at_agrum_dot_org
5  *
6  * This library is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 
22 /** @file
23  * @brief The class representing a record stored in a tabular database
24  *
25  * @author Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@LIP6)
26  */
27 #ifndef DOXYGEN_SHOULD_SKIP_THIS
28 
29 # include <algorithm>
30 # include <agrum/tools/database/DBRow.h>
31 
32 namespace gum {
33 
34  namespace learning {
35 
36  /// returns the allocator used by the DBRow
37  template < typename T_DATA, template < typename > class ALLOC >
38  INLINE ALLOC< T_DATA > DBRow< T_DATA, ALLOC >::getAllocator() const {
39  return row_.get_allocator();
40  }
41 
42 
43  /// default constructor with specific allocator
44  template < typename T_DATA, template < typename > class ALLOC >
45  INLINE DBRow< T_DATA, ALLOC >::DBRow(const ALLOC< T_DATA >& alloc) : row_(alloc) {
47  }
48 
49 
50  /// default constructor
51  template < typename T_DATA, template < typename > class ALLOC >
52  INLINE DBRow< T_DATA, ALLOC >::DBRow() : DBRow(ALLOC< T_DATA >()) {}
53 
54 
55  /// constructor with a given size for the row
56  template < typename T_DATA, template < typename > class ALLOC >
58  const T_DATA default_cell,
59  const double weight,
60  const ALLOC< T_DATA >& alloc) :
62  weight_(weight) {
64  }
65 
66 
67  /// constructor with a given size for the row
68  template < typename T_DATA, template < typename > class ALLOC >
70  const double weight,
71  const ALLOC< T_DATA >& alloc) :
72  DBRow(size, T_DATA(), weight, alloc) {}
73 
74  /// initializer list constructor
75  template < typename T_DATA, template < typename > class ALLOC >
77  const double weight,
78  const ALLOC< T_DATA >& alloc) :
79  row_(list, alloc),
80  weight_(weight) {
82  }
83 
84 
85  /// sets a new row
86  template < typename T_DATA, template < typename > class ALLOC >
87  template < template < typename > class OTHER_ALLOC >
88  INLINE void
90  const std::size_t size = new_row.size();
91  if (size) {
92  row_.resize(size);
94  } else {
95  row_.clear();
96  }
97  }
98 
99 
100  /// sets a new row
101  template < typename T_DATA, template < typename > class ALLOC >
103  row_ = std::move(new_row);
104  }
105 
106 
107  /// initializer from a vector of cells
108  template < typename T_DATA, template < typename > class ALLOC >
109  template < template < typename > class OTHER_ALLOC >
111  const double weight,
112  const ALLOC< T_DATA >& alloc) :
113  row_(alloc),
114  weight_(weight) {
115  setRow(cells);
117  }
118 
119 
120  /// initializer from a vector of cells
121  template < typename T_DATA, template < typename > class ALLOC >
123  const double weight,
124  const ALLOC< T_DATA >& alloc) :
125  row_(std::move(cells), alloc),
126  weight_(weight) {
128  }
129 
130 
131  /// copy constructor with a given allocator
132  template < typename T_DATA, template < typename > class ALLOC >
133  INLINE DBRow< T_DATA, ALLOC >::DBRow(const DBRow< T_DATA, ALLOC >& from,
134  const ALLOC< T_DATA >& alloc) :
135  row_(from.row_, alloc),
136  weight_(from.weight_) {
138  }
139 
140 
141  /// copy constructor
142  template < typename T_DATA, template < typename > class ALLOC >
143  INLINE DBRow< T_DATA, ALLOC >::DBRow(const DBRow< T_DATA, ALLOC >& from) :
145 
146 
147  /// move constructor with a given allocator
148  template < typename T_DATA, template < typename > class ALLOC >
150  const ALLOC< T_DATA >& alloc) :
151  row_(std::move(from.row_), alloc),
152  weight_(from.weight_) {
154  }
155 
156 
157  /// move constructor
158  template < typename T_DATA, template < typename > class ALLOC >
161 
162 
163  /// virtual copy constructor with a given allocator
164  template < typename T_DATA, template < typename > class ALLOC >
165  DBRow< T_DATA, ALLOC >* DBRow< T_DATA, ALLOC >::clone(const ALLOC< T_DATA >& alloc) const {
168  try {
169  allocator.construct(row, *this, alloc);
170  } catch (...) {
172  throw;
173  }
174  return row;
175  }
176 
177 
178  /// virtual copy constructor
179  template < typename T_DATA, template < typename > class ALLOC >
180  DBRow< T_DATA, ALLOC >* DBRow< T_DATA, ALLOC >::clone() const {
181  return clone(this->getAllocator());
182  }
183 
184 
185  /// destructor
186  template < typename T_DATA, template < typename > class ALLOC >
187  INLINE DBRow< T_DATA, ALLOC >::~DBRow() {
189  }
190 
191 
192  /// copy operator
193  template < typename T_DATA, template < typename > class ALLOC >
194  INLINE DBRow< T_DATA, ALLOC >&
195  DBRow< T_DATA, ALLOC >::operator=(const DBRow< T_DATA, ALLOC >& from) {
196  if (this != &from) {
197  row_ = from.row_;
198  weight_ = from.weight_;
199  }
200  return *this;
201  }
202 
203 
204  /// move operator
205  template < typename T_DATA, template < typename > class ALLOC >
206  INLINE DBRow< T_DATA, ALLOC >&
208  if (this != &from) {
209  row_ = std::move(from.row_);
210  weight_ = from.weight_;
211  }
212  return *this;
213  }
214 
215  /// returns the ith T_DATA of the row
216  template < typename T_DATA, template < typename > class ALLOC >
217  INLINE T_DATA& DBRow< T_DATA, ALLOC >::operator[](const std::size_t i) {
218  return row_[i];
219  }
220 
221  /// returns the ith T_DATA of the row
222  template < typename T_DATA, template < typename > class ALLOC >
223  INLINE const T_DATA& DBRow< T_DATA, ALLOC >::operator[](const std::size_t i) const {
224  return row_[i];
225  }
226 
227  /// returns the current row
228  template < typename T_DATA, template < typename > class ALLOC >
229  INLINE const std::vector< T_DATA, ALLOC< T_DATA > >&
230  DBRow< T_DATA, ALLOC >::row() const noexcept {
231  return row_;
232  }
233 
234  /// returns the current row
235  template < typename T_DATA, template < typename > class ALLOC >
236  INLINE std::vector< T_DATA, ALLOC< T_DATA > >& DBRow< T_DATA, ALLOC >::row() noexcept {
237  return row_;
238  }
239 
240  /// returns the weight
241  template < typename T_DATA, template < typename > class ALLOC >
242  INLINE const double& DBRow< T_DATA, ALLOC >::weight() const noexcept {
243  return weight_;
244  }
245 
246  /// returns the weight
247  template < typename T_DATA, template < typename > class ALLOC >
248  INLINE double& DBRow< T_DATA, ALLOC >::weight() noexcept {
249  return weight_;
250  }
251 
252  /// sets a new weight
253  template < typename T_DATA, template < typename > class ALLOC >
254  INLINE void DBRow< T_DATA, ALLOC >::setWeight(const double new_weight) {
256  }
257 
258  /// returns the size of the row
259  template < typename T_DATA, template < typename > class ALLOC >
260  INLINE std::size_t DBRow< T_DATA, ALLOC >::size() const noexcept {
261  return row_.size();
262  }
263 
264  /// resize a given row
265  template < typename T_DATA, template < typename > class ALLOC >
266  INLINE void DBRow< T_DATA, ALLOC >::resize(const std::size_t new_size) {
268  }
269 
270  /// reserve a size for the elements of a given row
271  template < typename T_DATA, template < typename > class ALLOC >
272  INLINE void DBRow< T_DATA, ALLOC >::reserve(const std::size_t new_size) {
274  }
275 
276  /// adds a new element at the end of the row
277  template < typename T_DATA, template < typename > class ALLOC >
278  INLINE void DBRow< T_DATA, ALLOC >::pushBack(const T_DATA& elt) {
279  row_.push_back(elt);
280  }
281 
282  /// adds a new element at the end of the row
283  template < typename T_DATA, template < typename > class ALLOC >
284  INLINE void DBRow< T_DATA, ALLOC >::pushBack(T_DATA&& elt) {
286  }
287 
288 
289  } /* namespace learning */
290 
291 } /* namespace gum */
292 
293 
294 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
Database(const std::string &filename, const BayesNet< GUM_SCALAR > &bn, const std::vector< std::string > &missing_symbols)