aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
IDBInitializer_tpl.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 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 >
69 
70 
71  /// move constructor with a given allocator
72  template < template < typename > class ALLOC >
75  const typename IDBInitializer< ALLOC >::allocator_type& alloc) :
79  }
80 
81 
82  /// move constructor
83  template < template < typename > class ALLOC >
86 
87 
88  /// destructor
89  template < template < typename > class ALLOC >
92  }
93 
94 
95  /// returns the names of the variables in the input database
96  template < template < typename > class ALLOC >
97  const std::vector< std::string, ALLOC< std::string > >&
100  return _var_names_;
101  }
102 
103 
104  // copy operator
105  template < template < typename > class ALLOC >
108  if (this != &from) {
111  _last_insertion_failed_ = false;
112  }
113  return *this;
114  }
115 
116 
117  // move constructor
118  template < template < typename > class ALLOC >
120  if (this != &from) {
123  _last_insertion_failed_ = false;
124  }
125  return *this;
126  }
127 
128 
129  /// fills the rows of the database
130  template < template < typename > class ALLOC >
131  template < template < template < typename > class > class DATABASE >
133  const bool retry_insertion) {
134  switch (_input_type_) {
135  case InputType::STRING:
137  return;
138 
139  case InputType::DBCELL:
141  return;
142 
143  default:
145  "fillDatabase has not been implemented yet for this "
146  "type of IDBInitializerInputType");
147  }
148  }
149 
150 
151  /// fills the rows of the database using string inputs
152  template < template < typename > class ALLOC >
153  template < template < template < typename > class > class DATABASE >
155  const bool retry_insertion) {
156  // if need be, try to reinsert the row that could not be inserted
159  _last_insertion_failed_ = false;
160  }
161 
162  // try to insert the next rows
163  while (this->nextRow_()) {
164  try {
165  // read a new line in the input file and insert it into the database
167  } catch (...) {
169  throw;
170  }
171  }
172  }
173 
174 
175  /// fills the rows of the database using DBCell inputs
176  template < template < typename > class ALLOC >
177  template < template < template < typename > class > class DATABASE >
179  const bool retry_insertion) {
180  // if need be, try to reinsert the row that could not be inserted
183  _last_insertion_failed_ = false;
184  }
185 
186  // try to insert the next rows
187  while (this->nextRow_()) {
188  try {
189  // read a new line in the input file and insert it into the database
191  } catch (...) {
193  throw;
194  }
195  }
196  }
197 
198 
199  /// asks the child class for the content of the current row using strings
200  template < template < typename > class ALLOC >
201  const std::vector< std::string, ALLOC< std::string > >&
204  "Method currentStringRow_ should not be used or it should be "
205  "overloaded in children classes.");
206  }
207 
208 
209  /// asks the child class for the content of the current row using dbcells
210  template < template < typename > class ALLOC >
213  "Method currentDBCellRow_ should not be used or it should be "
214  "overloaded in children classes.");
215  }
216 
217 
218  } /* namespace learning */
219 
220 } /* namespace gum */
221 
222 #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)