aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
DBRow_tpl.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2026 by *
5 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
6 * - Christophe GONZALES(_at_AMU) *
7 * *
8 * The aGrUM/pyAgrum library is free software; you can redistribute it *
9 * and/or modify it under the terms of either : *
10 * *
11 * - the GNU Lesser General Public License as published by *
12 * the Free Software Foundation, either version 3 of the License, *
13 * or (at your option) any later version, *
14 * - the MIT license (MIT), *
15 * - or both in dual license, as here. *
16 * *
17 * (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18 * *
19 * This aGrUM/pyAgrum library is distributed in the hope that it will be *
20 * useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26 * OTHER DEALINGS IN THE SOFTWARE. *
27 * *
28 * See LICENCES for more details. *
29 * *
30 * SPDX-FileCopyrightText: Copyright 2005-2026 *
31 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
32 * - Christophe GONZALES(_at_AMU) *
33 * SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34 * *
35 * Contact : info_at_agrum_dot_org *
36 * homepage : http://agrum.gitlab.io *
37 * gitlab : https://gitlab.com/agrumery/agrum *
38 * *
39 ****************************************************************************/
40
41#pragma once
42
43
49#include <agrum/base/database/DBRow.h> // to ease IDE parser
50#ifndef DOXYGEN_SHOULD_SKIP_THIS
51
52# include <algorithm>
53
55
56namespace gum {
57
58 namespace learning {
59
61 template < typename T_DATA >
63 GUM_CONSTRUCTOR(DBRow);
64 }
65
67 template < typename T_DATA >
68 DBRow< T_DATA >::DBRow(const std::size_t size, const T_DATA default_cell, const double weight) :
69 row_(size, default_cell), weight_(weight) {
70 GUM_CONSTRUCTOR(DBRow);
71 }
72
74 template < typename T_DATA >
75 DBRow< T_DATA >::DBRow(const std::size_t size, const double weight) :
76 DBRow(size, T_DATA(), weight) {}
77
79 template < typename T_DATA >
80 DBRow< T_DATA >::DBRow(std::initializer_list< T_DATA > list, const double weight) :
81 row_(list), weight_(weight) {
82 GUM_CONSTRUCTOR(DBRow);
83 }
84
86 template < typename T_DATA >
87 void DBRow< T_DATA >::setRow(const std::vector< T_DATA >& new_row) {
88 const std::size_t size = new_row.size();
89 if (size) {
90 row_.resize(size);
91 std::copy(new_row.begin(), new_row.end(), row_.begin());
92 } else {
93 row_.clear();
94 }
95 }
96
98 template < typename T_DATA >
99 void DBRow< T_DATA >::setRow(std::vector< T_DATA >&& new_row) {
100 row_ = std::move(new_row);
101 }
102
104 template < typename T_DATA >
105 DBRow< T_DATA >::DBRow(const std::vector< T_DATA >& cells, const double weight) :
106 weight_(weight) {
107 setRow(cells);
108 GUM_CONSTRUCTOR(DBRow);
109 }
110
112 template < typename T_DATA >
113 DBRow< T_DATA >::DBRow(std::vector< T_DATA >&& cells, const double weight) :
114 row_(std::move(cells)), weight_(weight) {
115 GUM_CONSTRUCTOR(DBRow);
116 }
117
119 template < typename T_DATA >
120 DBRow< T_DATA >::DBRow(const DBRow< T_DATA >& from) : row_(from.row_), weight_(from.weight_) {
121 GUM_CONS_CPY(DBRow);
122 }
123
125 template < typename T_DATA >
126 DBRow< T_DATA >::DBRow(DBRow< T_DATA >&& from) :
127 row_(std::move(from.row_)), weight_(from.weight_) {
128 GUM_CONS_MOV(DBRow);
129 }
130
132 template < typename T_DATA >
133 DBRow< T_DATA >* DBRow< T_DATA >::clone() const {
134 return new DBRow< T_DATA >(*this);
135 }
136
138 template < typename T_DATA >
139 DBRow< T_DATA >::~DBRow() {
140 GUM_DESTRUCTOR(DBRow);
141 }
142
144 template < typename T_DATA >
145 DBRow< T_DATA >& DBRow< T_DATA >::operator=(const DBRow< T_DATA >& from) {
146 if (this != &from) {
147 row_ = from.row_;
148 weight_ = from.weight_;
149 }
150 return *this;
151 }
152
154 template < typename T_DATA >
155 DBRow< T_DATA >& DBRow< T_DATA >::operator=(DBRow< T_DATA >&& from) {
156 if (this != &from) {
157 row_ = std::move(from.row_);
158 weight_ = from.weight_;
159 }
160 return *this;
161 }
162
164 template < typename T_DATA >
165 T_DATA& DBRow< T_DATA >::operator[](const std::size_t i) {
166 return row_[i];
167 }
168
170 template < typename T_DATA >
171 const T_DATA& DBRow< T_DATA >::operator[](const std::size_t i) const {
172 return row_[i];
173 }
174
176 template < typename T_DATA >
177 const std::vector< T_DATA >& DBRow< T_DATA >::row() const noexcept {
178 return row_;
179 }
180
182 template < typename T_DATA >
183 std::vector< T_DATA >& DBRow< T_DATA >::row() noexcept {
184 return row_;
185 }
186
188 template < typename T_DATA >
189 const double& DBRow< T_DATA >::weight() const noexcept {
190 return weight_;
191 }
192
194 template < typename T_DATA >
195 double& DBRow< T_DATA >::weight() noexcept {
196 return weight_;
197 }
198
200 template < typename T_DATA >
201 void DBRow< T_DATA >::setWeight(const double new_weight) {
202 weight_ = new_weight;
203 }
204
206 template < typename T_DATA >
207 std::size_t DBRow< T_DATA >::size() const noexcept {
208 return row_.size();
209 }
210
212 template < typename T_DATA >
213 void DBRow< T_DATA >::resize(const std::size_t new_size) {
214 row_.resize(new_size);
215 }
216
218 template < typename T_DATA >
219 void DBRow< T_DATA >::reserve(const std::size_t new_size) {
220 row_.reserve(new_size);
221 }
222
224 template < typename T_DATA >
225 void DBRow< T_DATA >::pushBack(const T_DATA& elt) {
226 row_.push_back(elt);
227 }
228
230 template < typename T_DATA >
231 void DBRow< T_DATA >::pushBack(T_DATA&& elt) {
232 row_.push_back(std::move(elt));
233 }
234
235
236 } /* namespace learning */
237
238} /* namespace gum */
239
240
241#endif /* DOXYGEN_SHOULD_SKIP_THIS */
The class representing a record stored in a tabular database.
The class for storing a record in a database.
Definition DBRow.h:75
DBRow()
default constructor
include the inlined functions if necessary
Definition CSVParser.h:55
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
STL namespace.