aGrUM 2.3.2
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-2025 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-2025 *
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#pragma once
41
42
48#ifndef DOXYGEN_SHOULD_SKIP_THIS
49
50# include <algorithm>
51
53
54namespace gum {
55
56 namespace learning {
57
59 template < typename T_DATA >
60 INLINE DBRow< T_DATA >::DBRow() {
61 GUM_CONSTRUCTOR(DBRow);
62 }
63
65 template < typename T_DATA >
66 INLINE DBRow< T_DATA >::DBRow(const std::size_t size,
67 const T_DATA default_cell,
68 const double weight) : row_(size, default_cell), weight_(weight) {
69 GUM_CONSTRUCTOR(DBRow);
70 }
71
73 template < typename T_DATA >
74 INLINE DBRow< T_DATA >::DBRow(const std::size_t size, const double weight) :
75 DBRow(size, T_DATA(), weight) {}
76
78 template < typename T_DATA >
79 INLINE DBRow< T_DATA >::DBRow(std::initializer_list< T_DATA > list, const double weight) :
80 row_(list), weight_(weight) {
81 GUM_CONSTRUCTOR(DBRow);
82 }
83
85 template < typename T_DATA >
86 INLINE void DBRow< T_DATA >::setRow(const std::vector< T_DATA >& new_row) {
87 const std::size_t size = new_row.size();
88 if (size) {
89 row_.resize(size);
90 std::copy(new_row.begin(), new_row.end(), row_.begin());
91 } else {
92 row_.clear();
93 }
94 }
95
97 template < typename T_DATA >
98 INLINE void DBRow< T_DATA >::setRow(std::vector< T_DATA >&& new_row) {
99 row_ = std::move(new_row);
100 }
101
103 template < typename T_DATA >
104 INLINE DBRow< T_DATA >::DBRow(const std::vector< T_DATA >& cells, const double weight) :
105 weight_(weight) {
106 setRow(cells);
107 GUM_CONSTRUCTOR(DBRow);
108 }
109
111 template < typename T_DATA >
112 INLINE DBRow< T_DATA >::DBRow(std::vector< T_DATA >&& cells, const double weight) :
113 row_(std::move(cells)), weight_(weight) {
114 GUM_CONSTRUCTOR(DBRow);
115 }
116
118 template < typename T_DATA >
119 INLINE DBRow< T_DATA >::DBRow(const DBRow< T_DATA >& from) :
120 row_(from.row_), weight_(from.weight_) {
121 GUM_CONS_CPY(DBRow);
122 }
123
125 template < typename T_DATA >
126 INLINE 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 INLINE DBRow< T_DATA >* DBRow< T_DATA >::clone() const {
134 return new DBRow< T_DATA >(*this);
135 }
136
138 template < typename T_DATA >
139 INLINE DBRow< T_DATA >::~DBRow() {
140 GUM_DESTRUCTOR(DBRow);
141 }
142
144 template < typename T_DATA >
145 INLINE 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 INLINE 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 INLINE T_DATA& DBRow< T_DATA >::operator[](const std::size_t i) {
166 return row_[i];
167 }
168
170 template < typename T_DATA >
171 INLINE 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 INLINE const std::vector< T_DATA >& DBRow< T_DATA >::row() const noexcept {
178 return row_;
179 }
180
182 template < typename T_DATA >
183 INLINE std::vector< T_DATA >& DBRow< T_DATA >::row() noexcept {
184 return row_;
185 }
186
188 template < typename T_DATA >
189 INLINE const double& DBRow< T_DATA >::weight() const noexcept {
190 return weight_;
191 }
192
194 template < typename T_DATA >
195 INLINE double& DBRow< T_DATA >::weight() noexcept {
196 return weight_;
197 }
198
200 template < typename T_DATA >
201 INLINE void DBRow< T_DATA >::setWeight(const double new_weight) {
202 weight_ = new_weight;
203 }
204
206 template < typename T_DATA >
207 INLINE std::size_t DBRow< T_DATA >::size() const noexcept {
208 return row_.size();
209 }
210
212 template < typename T_DATA >
213 INLINE void DBRow< T_DATA >::resize(const std::size_t new_size) {
214 row_.resize(new_size);
215 }
216
218 template < typename T_DATA >
219 INLINE void DBRow< T_DATA >::reserve(const std::size_t new_size) {
220 row_.reserve(new_size);
221 }
222
224 template < typename T_DATA >
225 INLINE void DBRow< T_DATA >::pushBack(const T_DATA& elt) {
226 row_.push_back(elt);
227 }
228
230 template < typename T_DATA >
231 INLINE 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:54
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
STL namespace.