aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
DBRowGeneratorParser_tpl.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (c) 2005-2020 by Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@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 /** @file
21  * @brief Template implementation of the DBRowGeneratorParser class
22  *
23  * @author Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@LIP6)
24  */
25 
26 #ifndef DOXYGEN_SHOULD_SKIP_THIS
27 
28 namespace gum {
29 
30  namespace learning {
31 
32  /// default constructor
33  template <template<typename> class ALLOC>
34  DBRowGeneratorParser<ALLOC>::DBRowGeneratorParser(
35  const typename DatabaseTable<ALLOC>::Handler& handler,
36  const DBRowGeneratorSet<ALLOC>& generator_set,
37  const typename DBRowGeneratorParser<ALLOC>::allocator_type& alloc )
38  : _handler_(handler)
39  , _generator_set_(generator_set, alloc)
40  , _generator_size_ ( generator_set.size () ) {
41  GUM_CONSTRUCTOR(DBRowGeneratorParser);
42  }
43 
44 
45  /// copy constructor with a given allocator
46  template <template<typename> class ALLOC>
54  }
55 
56 
57  /// copy constructor
58  template <template<typename> class ALLOC>
62 
63 
64  /// move constructor with a given allocator
65  template <template<typename> class ALLOC>
73  }
74 
75 
76  /// move constructor
77  template <template<typename> class ALLOC>
81 
82 
83  /// virtual copy constructor with a given allocator
84  template <template<typename> class ALLOC>
86  const typename DBRowGeneratorParser<ALLOC>::allocator_type& alloc) const {
89  try {
90  allocator.construct ( new_parser, *this, alloc );
91  }
92  catch ( ... ) {
94  throw;
95  }
96  return new_parser;
97  }
98 
99 
100  /// virtual copy constructor
101  template <template<typename> class ALLOC>
103  DBRowGeneratorParser<ALLOC>::clone () const {
104  return clone ( this->getAllocator () );
105  }
106 
107 
108  /// destructor
109  template <template<typename> class ALLOC>
112  }
113 
114 
115  /// copy operator
116  template <template<typename> class ALLOC>
119  const DBRowGeneratorParser<ALLOC>& from) {
120  if (this != &from) {
124  }
125  return *this;
126  }
127 
128 
129  /// move operator
130  template <template<typename> class ALLOC>
133  if (this != &from) {
137  }
138  return *this;
139  }
140 
141 
142  /// returns true if there are still rows that can be output by the RowFilter
143  template <template<typename> class ALLOC>
145  if ( ! _generator_size_ ) return _handler_.hasRows();
146 
147  while ( ! _generator_set_.hasRows() ) {
148  if ( ! _handler_.hasRows () ) return false;
150  ++ _handler_;
151  }
152  return true;
153  }
154 
155 
156  /// returns a new output row with its corresponding weight
157  template <template<typename> class ALLOC>
160  // if there exists no generator in the generator set, we just return
161  // the row pointed to by the handler
162  if ( ! _generator_size_ ) {
163  const auto& pointed_row = * _handler_;
164  ++ _handler_;
165  return pointed_row;
166  }
167  else {
168  return _generator_set_.generate();
169  }
170  }
171 
172 
173  /// resets the filter
174  template <template<typename> class ALLOC>
176  _handler_.reset();
178  }
179 
180 
181  // returns the handler used by the filter
182  template <template<typename> class ALLOC>
183  INLINE typename DatabaseTable<ALLOC>::Handler&
185  return _handler_;
186  }
187 
188 
189  // returns the handler used by the filter
190  template <template<typename> class ALLOC>
191  INLINE const typename DatabaseTable<ALLOC>::Handler&
193  return _handler_;
194  }
195 
196 
197  /// returns a reference on the database
198  template <template<typename> class ALLOC>
199  INLINE const DatabaseTable< ALLOC >&
200  DBRowGeneratorParser<ALLOC>::database () const {
201  return static_cast<const DatabaseTable< ALLOC >&>
202  ( _handler_.database ());
203  }
204 
205 
206  /// returns the generator set that is actually used
207  template <template<typename> class ALLOC>
210  return _generator_set_;
211  }
212 
213 
214  /// sets the area in the database the handler will handle
215  template <template<typename> class ALLOC>
217  std::size_t end) {
219  }
220 
221 
222  /// returns the generator set that is actually used
223  template <template<typename> class ALLOC>
226  return _generator_set_;
227  }
228 
229 
230  /** @brief sets the columns of interest: the output DBRow needs only
231  * contain values fot these columns */
232  template <template<typename> class ALLOC>
236  }
237 
238 
239  /** @brief sets the columns of interest: the output DBRow needs only
240  * contain values fot these columns */
241  template <template<typename> class ALLOC>
245  }
246 
247 
248  /// assign a new Bayes net to all the generators that depend on a BN
249  template <template<typename> class ALLOC>
250  template < typename GUM_SCALAR >
252  const BayesNet<GUM_SCALAR>& new_bn) {
254  }
255 
256 
257  /// returns the allocator used
258  template <template<typename> class ALLOC>
261  return _generator_set_.getAllocator ();
262  }
263 
264 
265  } /* namespace learning */
266 
267 } /* namespace gum */
268 
269 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
Database(const std::string &filename, const BayesNet< GUM_SCALAR > &bn, const std::vector< std::string > &missing_symbols)