aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
IDBInitializer_tpl.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 The base class for initializing DatabaseTables and RawDatabaseTables
24  * from files or sql databases
25  *
26  * @author Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@LIP6)
27  */
28 #ifndef DOXYGEN_SHOULD_SKIP_THIS
29 
30 namespace gum {
31 
32  namespace learning {
33 
34 
35  /// returns the allocator used
36  template < template < typename > class ALLOC >
38  IDBInitializer< ALLOC >::getAllocator() const {
39  return var_names__.get_allocator();
40  }
41 
42 
43  /// default constructor
44  template < template < typename > class ALLOC >
46  typename IDBInitializer< ALLOC >::InputType type,
47  const typename IDBInitializer< ALLOC >::allocator_type& alloc) :
51  }
52 
53 
54  /// copy constructor with a given allocator
55  template < template < typename > class ALLOC >
57  const IDBInitializer< ALLOC >& from,
58  const typename IDBInitializer< ALLOC >::allocator_type& alloc) :
62  }
63 
64 
65  /// copy constructor
66  template < template < typename > class ALLOC >
68  const IDBInitializer< ALLOC >& from) :
70 
71 
72  /// move constructor with a given allocator
73  template < template < typename > class ALLOC >
76  const typename IDBInitializer< ALLOC >::allocator_type& alloc) :
80  }
81 
82 
83  /// move constructor
84  template < template < typename > class ALLOC >
85  INLINE
88 
89 
90  /// destructor
91  template < template < typename > class ALLOC >
94  }
95 
96 
97  /// returns the names of the variables in the input database
98  template < template < typename > class ALLOC >
99  const std::vector< std::string, ALLOC< std::string > >&
101  if (var_names__.empty()) var_names__ = this->variableNames_();
102  return var_names__;
103  }
104 
105 
106  // copy operator
107  template < template < typename > class ALLOC >
110  if (this != &from) {
113  last_insertion_failed__ = false;
114  }
115  return *this;
116  }
117 
118 
119  // move constructor
120  template < template < typename > class ALLOC >
123  if (this != &from) {
126  last_insertion_failed__ = false;
127  }
128  return *this;
129  }
130 
131 
132  /// fills the rows of the database
133  template < template < typename > class ALLOC >
134  template < template < template < typename > class > class DATABASE >
136  const bool retry_insertion) {
137  switch (input_type__) {
138  case InputType::STRING:
140  return;
141 
142  case InputType::DBCELL:
144  return;
145 
146  default:
148  "fillDatabase has not been implemented yet for this "
149  "type of IDBInitializerInputType");
150  }
151  }
152 
153 
154  /// fills the rows of the database using string inputs
155  template < template < typename > class ALLOC >
156  template < template < template < typename > class > class DATABASE >
158  DATABASE< ALLOC >& database,
159  const bool retry_insertion) {
160  // if need be, try to reinsert the row that could not be inserted
163  last_insertion_failed__ = false;
164  }
165 
166  // try to insert the next rows
167  while (this->nextRow_()) {
168  try {
169  // read a new line in the input file and insert it into the database
171  } catch (...) {
173  throw;
174  }
175  }
176  }
177 
178 
179  /// fills the rows of the database using DBCell inputs
180  template < template < typename > class ALLOC >
181  template < template < template < typename > class > class DATABASE >
183  DATABASE< ALLOC >& database,
184  const bool retry_insertion) {
185  // if need be, try to reinsert the row that could not be inserted
188  last_insertion_failed__ = false;
189  }
190 
191  // try to insert the next rows
192  while (this->nextRow_()) {
193  try {
194  // read a new line in the input file and insert it into the database
196  } catch (...) {
198  throw;
199  }
200  }
201  }
202 
203 
204  /// asks the child class for the content of the current row using strings
205  template < template < typename > class ALLOC >
206  const std::vector< std::string, ALLOC< std::string > >&
209  "Method currentStringRow_ should not be used or it should be "
210  "overloaded in children classes.");
211  }
212 
213 
214  /// asks the child class for the content of the current row using dbcells
215  template < template < typename > class ALLOC >
218  "Method currentDBCellRow_ should not be used or it should be "
219  "overloaded in children classes.");
220  }
221 
222 
223  } /* namespace learning */
224 
225 } /* namespace gum */
226 
227 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:669
Database(const std::string &filename, const BayesNet< GUM_SCALAR > &bn, const std::vector< std::string > &missing_symbols)