aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
DBRowGeneratorIdentity.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright 2005-2020 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 A DBRowGenerator class that returns exactly the rows it gets in input
24  *
25  * @author Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@LIP6)
26  */
27 #ifndef GUM_LEARNING_DBROW_GENERATOR_IDENTITY_H
28 #define GUM_LEARNING_DBROW_GENERATOR_IDENTITY_H
29 
30 #include <agrum/agrum.h>
31 #include <agrum/tools/database/DBRowGenerator.h>
32 
33 namespace gum {
34 
35  namespace learning {
36 
37  /** @class DBRowGeneratorIdentity
38  * @headerfile DBRowGeneratorIdentity.h <agrum/tools/database/DBRowGeneratorIdentity.h>
39  * @brief A DBRowGenerator class that returns exactly the rows it gets
40  * in input
41  *
42  * @ingroup learning_database
43  *
44  * This class is a dummy DBRowGenerator that can be essentially used for
45  * debugging purposes. The DBRowGeneratorIdentity class is designed to
46  * take as input DBRow instances via its method setInputRow and to ouput
47  * them without any additional processing via its method generate. See
48  * class DBRowGenerator for further details on how DBRowGenerator works.
49  *
50  * The standard usage of a DBRowGenerator is the following:
51  * @code
52  * // create a DatabaseTable and fill it
53  * gum::learning::DBTranslatorSet<> set;
54  * for ( int i = 0; i < 10; ++i )
55  * set.insertTranslator(gum::learning::DBTranslator4LabelizedVariable<>(),i);
56  * gum::learning::DatabaseTable<> database ( set );
57  * // fill the database
58  *
59  * // keep in a vector the types of the columns in the database
60  * const std::vector<gum::learning::DBTranslatedValueType>
61  * column_types ( 10, gum::learning::DBTranslatedValueType::DISCRETE );
62  *
63  * // create the generator
64  * gum::learning::DBRowGeneratorIdentity<> generator ( col_types );
65  *
66  * // parse the database and produce output rows
67  * for ( auto dbrow : database ) {
68  * generator.setInputRow ( dbrow );
69  * const auto& output_dbrow = generator.generate ();
70  * // do something with the output dbrow
71  * }
72  * @endcode
73  */
74  template < template < typename > class ALLOC = std::allocator >
76  public:
77  /// type for the allocators passed in arguments of methods
79 
80  // ##########################################################################
81  /// @name Constructors / Destructors
82  // ##########################################################################
83 
84  /// @{
85 
86  /// default constructor
91 
92  /// copy constructor
93  DBRowGeneratorIdentity(const DBRowGeneratorIdentity< ALLOC >& from);
94 
95  /// copy constructor with a given allocator
96  DBRowGeneratorIdentity(const DBRowGeneratorIdentity< ALLOC >& from,
97  const allocator_type& alloc);
98 
99  /// move constructor
100  DBRowGeneratorIdentity(DBRowGeneratorIdentity< ALLOC >&& from);
101 
102  /// move constructor with a given allocator
103  DBRowGeneratorIdentity(DBRowGeneratorIdentity< ALLOC >&& from,
104  const allocator_type& alloc);
105 
106  /// virtual copy constructor
107  virtual DBRowGeneratorIdentity< ALLOC >* clone() const override final;
108 
109  /// virtual copy constructor with a given allocator
110  virtual DBRowGeneratorIdentity< ALLOC >*
111  clone(const allocator_type& alloc) const override final;
112 
113  /// destructor
115 
116  /// @}
117 
118 
119  // ##########################################################################
120  /// @name Operators
121  // ##########################################################################
122 
123  /// @{
124 
125  /// copy operator
128 
129  /// move operator
132 
133  /// @}
134 
135 
136  // ##########################################################################
137  /// @name Accessors / Modifiers
138  // ##########################################################################
139 
140  /// @{
141 
142  /// generates one ouput DBRow for each DBRow passed to method setInputRow
143  virtual const DBRow< DBTranslatedValue, ALLOC >& generate() final;
144 
145  /// returns the allocator used
147 
148  /// @}
149 
150 
151  protected:
152  /// computes the rows it will provide as output
153  virtual std::size_t
154  computeRows_(const DBRow< DBTranslatedValue, ALLOC >& row) final;
155 
156 
157 #ifndef DOXYGEN_SHOULD_SKIP_THIS
158 
159  private:
160  /// the row used as input to generate the output DBRows
161  const DBRow< DBTranslatedValue, ALLOC >* input_row__{nullptr};
162 
163 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
164  };
165 
166  } /* namespace learning */
167 
168 } /* namespace gum */
169 
170 
171 // always include the template implementation
172 #include <agrum/tools/database/DBRowGeneratorIdentity_tpl.h>
173 
174 #endif /* GUM_LEARNING_DBROW_GENERATOR_IDENTITY_H */
DBRowGeneratorIdentity(const DBRowGeneratorIdentity< ALLOC > &from, const allocator_type &alloc)
copy constructor with a given allocator
DBRowGeneratorIdentity(DBRowGeneratorIdentity< ALLOC > &&from)
move constructor
DBRowGeneratorIdentity(const DBRowGeneratorIdentity< ALLOC > &from)
copy constructor
allocator_type getAllocator() const
returns the allocator used
DBRowGeneratorIdentity(const std::vector< DBTranslatedValueType, ALLOC< DBTranslatedValueType > > column_types, const allocator_type &alloc=allocator_type())
default constructor
virtual DBRowGeneratorIdentity< ALLOC > * clone() const override final
virtual copy constructor
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:669
DBRowGeneratorIdentity< ALLOC > & operator=(DBRowGeneratorIdentity< ALLOC > &&from)
move operator
DBRowGeneratorIdentity< ALLOC > & operator=(const DBRowGeneratorIdentity< ALLOC > &from)
copy operator
A DBRowGenerator class that returns exactly the rows it gets in input.
virtual std::size_t computeRows_(const DBRow< DBTranslatedValue, ALLOC > &row) final
computes the rows it will provide as output
DBRowGeneratorIdentity(DBRowGeneratorIdentity< ALLOC > &&from, const allocator_type &alloc)
move constructor with a given allocator
virtual const DBRow< DBTranslatedValue, ALLOC > & generate() final
generates one ouput DBRow for each DBRow passed to method setInputRow
Database(const std::string &filename, const BayesNet< GUM_SCALAR > &bn, const std::vector< std::string > &missing_symbols)
virtual DBRowGeneratorIdentity< ALLOC > * clone(const allocator_type &alloc) const override final
virtual copy constructor with a given allocator