aGrUM  0.14.2
DBRow.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
25 #ifndef GUM_LEARNING_DB_ROW_H
26 #define GUM_LEARNING_DB_ROW_H
27 
28 #include <cstddef>
29 #include <cstring>
30 #include <initializer_list>
31 #include <memory>
32 #include <vector>
33 
34 #include <agrum/agrum.h>
35 
36 namespace gum {
37 
38  namespace learning {
39 
51  template < typename T_DATA,
52  template < typename > class ALLOC = std::allocator >
53  class DBRow {
54  public:
55  using allocator_type = ALLOC< T_DATA >;
56 
57  // ##########################################################################
59  // ##########################################################################
60 
62 
64  DBRow();
65 
67  DBRow(const ALLOC< T_DATA >& alloc);
68 
70  DBRow(const std::size_t size,
71  const double weight = 1.0,
72  const ALLOC< T_DATA >& alloc = ALLOC< T_DATA >());
73 
75  DBRow(const std::size_t size,
76  const T_DATA default_value,
77  const double weight,
78  const ALLOC< T_DATA >& alloc = ALLOC< T_DATA >());
79 
81  DBRow(std::initializer_list< T_DATA > list,
82  const double weight = 1.0,
83  const ALLOC< T_DATA >& alloc = ALLOC< T_DATA >());
84 
86  template < template < typename > class OTHER_ALLOC >
87  DBRow(const std::vector< T_DATA, OTHER_ALLOC< T_DATA > >& cells,
88  const double weight = 1.0,
89  const ALLOC< T_DATA >& alloc = ALLOC< T_DATA >());
90 
92  DBRow(std::vector< T_DATA, ALLOC< T_DATA > >&& cells,
93  const double weight = 1.0,
94  const ALLOC< T_DATA >& alloc = ALLOC< T_DATA >());
95 
97  DBRow(const DBRow< T_DATA, ALLOC >& from);
98 
100  DBRow(const DBRow< T_DATA, ALLOC >& from, const ALLOC< T_DATA >& alloc);
101 
104 
106  DBRow(DBRow< T_DATA, ALLOC >&& from, const ALLOC< T_DATA >& alloc);
107 
109  DBRow< T_DATA, ALLOC >* clone() const;
110 
112  DBRow< T_DATA, ALLOC >* clone(const ALLOC< T_DATA >& alloc) const;
113 
115  ~DBRow();
116 
118 
119 
120  // ##########################################################################
122  // ##########################################################################
123 
125 
128 
131 
133 
136  T_DATA& operator[](const std::size_t i);
137 
139 
142  const T_DATA& operator[](const std::size_t i) const;
143 
145 
146 
147  // ##########################################################################
149  // ##########################################################################
150 
152 
154  const std::vector< T_DATA, ALLOC< T_DATA > >& row() const noexcept;
155 
157  std::vector< T_DATA, ALLOC< T_DATA > >& row() noexcept;
158 
160  const double& weight() const noexcept;
161 
163  double& weight() noexcept;
164 
166  template < template < typename > class OTHER_ALLOC >
167  void setRow(const std::vector< T_DATA, OTHER_ALLOC< T_DATA > >& new_row);
168 
170  void setRow(std::vector< T_DATA, ALLOC< T_DATA > >&& new_row);
171 
173  void setWeight(const double new_weight);
174 
176  std::size_t size() const noexcept;
177 
179  void resize(const std::size_t new_size);
180 
182  void reserve(const std::size_t new_size);
183 
185  void pushBack(const T_DATA& elt);
186 
188  void pushBack(T_DATA&& elt);
189 
191  ALLOC< T_DATA > getAllocator() const;
192 
194 
195 
196  protected:
198  std::vector< T_DATA, ALLOC< T_DATA > > _row;
199 
201  double _weight{1.0f};
202 
203  // used for constructors and operators
204  template < typename TX_DATA, template < typename > class OTHER_ALLOC >
205  friend class DBRow;
206  };
207 
208  } /* namespace learning */
209 
210 } /* namespace gum */
211 
214 
215 #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:201
STL namespace.
DBRow()
default constructor
DBRow< T_DATA, ALLOC > & operator=(const DBRow< T_DATA, ALLOC > &from)
copy operator
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
ALLOC< T_DATA > allocator_type
Definition: DBRow.h:55
std::vector< T_DATA, ALLOC< T_DATA > > _row
the row itself
Definition: DBRow.h:198
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:53
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
The class representing a record stored in a tabular database.