aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
DBRowGeneratorIdentity.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 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
90 
91  /// copy constructor
92  DBRowGeneratorIdentity(const DBRowGeneratorIdentity< ALLOC >& from);
93 
94  /// copy constructor with a given allocator
95  DBRowGeneratorIdentity(const DBRowGeneratorIdentity< ALLOC >& from,
96  const allocator_type& alloc);
97 
98  /// move constructor
99  DBRowGeneratorIdentity(DBRowGeneratorIdentity< ALLOC >&& from);
100 
101  /// move constructor with a given allocator
102  DBRowGeneratorIdentity(DBRowGeneratorIdentity< ALLOC >&& from, const allocator_type& alloc);
103 
104  /// virtual copy constructor
105  virtual DBRowGeneratorIdentity< ALLOC >* clone() const override final;
106 
107  /// virtual copy constructor with a given allocator
108  virtual DBRowGeneratorIdentity< ALLOC >*
109  clone(const allocator_type& alloc) const override final;
110 
111  /// destructor
113 
114  /// @}
115 
116 
117  // ##########################################################################
118  /// @name Operators
119  // ##########################################################################
120 
121  /// @{
122 
123  /// copy operator
125 
126  /// move operator
128 
129  /// @}
130 
131 
132  // ##########################################################################
133  /// @name Accessors / Modifiers
134  // ##########################################################################
135 
136  /// @{
137 
138  /// generates one ouput DBRow for each DBRow passed to method setInputRow
139  virtual const DBRow< DBTranslatedValue, ALLOC >& generate() final;
140 
141  /// returns the allocator used
143 
144  /// @}
145 
146 
147  protected:
148  /// computes the rows it will provide as output
149  virtual std::size_t computeRows_(const DBRow< DBTranslatedValue, ALLOC >& row) final;
150 
151 
152 #ifndef DOXYGEN_SHOULD_SKIP_THIS
153 
154  private:
155  /// the row used as input to generate the output DBRows
156  const DBRow< DBTranslatedValue, ALLOC >* _input_row_{nullptr};
157 
158 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
159  };
160 
161  } /* namespace learning */
162 
163 } /* namespace gum */
164 
165 
166 // always include the template implementation
167 #include <agrum/tools/database/DBRowGeneratorIdentity_tpl.h>
168 
169 #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:643
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