aGrUM 3.2.0
a C++ library for (probabilistic) graphical models
DBRowGeneratorParser_inl.h
Go to the documentation of this file.
1/***************************************************************************
2 * Copyright (c) 2005-2024 by Christophe GONZALES(_at_AMU) and Pierre-Henri WUILLEMIN(_at_LIP6) *
3 * info_at_agrum_dot_org *
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 ***************************************************************************/
20#pragma once
21
27
28#include <agrum/base/database/DBRowGeneratorParser.h> // to ease IDE parser
29#ifndef DOXYGEN_SHOULD_SKIP_THIS
30
31namespace gum {
32
33 namespace learning {
34
37 if (this != &from) {
38 _handler_ = from._handler_;
39 _generator_set_ = from._generator_set_;
40 _generator_size_ = from._generator_size_;
41 }
42 return *this;
43 }
44
45
48 if (this != &from) {
49 _handler_ = std::move(from._handler_);
50 _generator_set_ = std::move(from._generator_set_);
51 _generator_size_ = from._generator_size_;
52 }
53 return *this;
54 }
55
56
58 INLINE bool DBRowGeneratorParser::hasRows() {
59 if (!_generator_size_) return _handler_.hasRows();
60
61 while (!_generator_set_.hasRows()) {
62 if (!_handler_.hasRows()) return false;
64 ++_handler_;
65 }
66 return true;
67 }
68
69
72 // if there exists no generator in the generator set, we just return
73 // the row pointed to by the handler
74 if (!_generator_size_) {
75 const auto& pointed_row = *_handler_;
76 ++_handler_;
77 return pointed_row;
78 } else {
80 }
81 }
82
83
85 INLINE void DBRowGeneratorParser::reset() {
86 _handler_.reset();
88 }
89
90
91 // returns the handler used by the filter
93
94
95 // returns the handler used by the filter
96 INLINE const typename DatabaseTable::Handler& DBRowGeneratorParser::handler() const {
97 return _handler_;
98 }
99
100
102 INLINE const DatabaseTable& DBRowGeneratorParser::database() const {
103 return static_cast< const DatabaseTable& >(_handler_.database());
104 }
105
106
109
110
112 INLINE void DBRowGeneratorParser::setRange(std::size_t begin, std::size_t end) {
113 _handler_.setRange(begin, end);
114 }
115
116
119 return _generator_set_;
120 }
121
122
126 const std::vector< std::size_t >& cols_of_interest) {
127 _generator_set_.setColumnsOfInterest(cols_of_interest);
128 }
129
130
133 INLINE void
134 DBRowGeneratorParser::setColumnsOfInterest(std::vector< std::size_t >&& cols_of_interest) {
135 _generator_set_.setColumnsOfInterest(std::move(cols_of_interest));
136 }
137
138
139 } /* namespace learning */
140
141} /* namespace gum */
142
143#endif /* DOXYGEN_SHOULD_SKIP_THIS */
The class for parsing DatabaseTable rows and generating output rows.
the class used to read a row in the database and to transform it into a set of DBRow instances that c...
void reset()
resets the parser
std::size_t _generator_size_
the size of the generator set
const DatabaseTable & database() const
returns a reference on the database
DBRowGeneratorParser & operator=(const DBRowGeneratorParser &from)
copy operator
bool hasRows()
returns true if there are still rows that can be output by the DBRowGeneratorParser
void setRange(std::size_t begin, std::size_t end)
sets the area in the database the handler will handle
void setColumnsOfInterest(const std::vector< std::size_t > &cols_of_interest)
sets the columns of interest: the output DBRow needs only contain values fot these columns
DBRowGeneratorSet _generator_set_
the set of DBRow generators (might be empty)
DatabaseTable::Handler _handler_
the handler that is really used to parse the database
DBRowGeneratorSet & generatorSet()
returns the generator set that is actually used
const DBRow< DBTranslatedValue > & row()
returns a new output row with its corresponding weight
DatabaseTable::Handler & handler()
returns the handler used by the parser
The class used to pack sets of generators.
bool hasRows()
returns true if there are still rows that can be output by the set of generators
void reset()
resets all the generators
void setColumnsOfInterest(const std::vector< std::size_t > &cols_of_interest)
sets the columns of interest: the output DBRow needs only contain correct values fot these columns
bool setInputRow(const DBRow< DBTranslatedValue > &input_row)
sets the input row from which the generators will create new rows
const DBRow< DBTranslatedValue > & generate()
generates a new output row from the input row
The class for storing a record in a database.
Definition DBRow.h:75
The class representing a tabular database as used by learning tasks.
typename IDatabaseTable< DBTranslatedValue >::Handler Handler
the unsafe handler type
include the inlined functions if necessary
Definition CSVParser.h:55
gum is the global namespace for all aGrUM entities
Definition agrum.h:46