io.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_CORE_UTIL_IO_HPP
14 #define MLPACK_CORE_UTIL_IO_HPP
15 
16 #include <iostream>
17 #include <list>
18 #include <map>
19 #include <string>
20 
21 #include <boost/any.hpp>
22 
23 #include <mlpack/prereqs.hpp>
24 
25 #include "timers.hpp"
26 #include "binding_details.hpp"
27 #include "program_doc.hpp"
28 #include "version.hpp"
29 
30 #include "param_data.hpp"
31 
34 
35 namespace mlpack {
36 
172 class IO
173 {
174  public:
181  static void Add(util::ParamData&& d);
182 
188  static bool HasParam(const std::string& identifier);
189 
196  template<typename T>
197  static T& GetParam(const std::string& identifier);
198 
207  template<typename T>
208  static std::string GetPrintableParam(const std::string& identifier);
209 
219  template<typename T>
220  static T& GetRawParam(const std::string& identifier);
221 
231  static void MakeInPlaceCopy(const std::string& outputParamName,
232  const std::string& inputParamName);
233 
245  static IO& GetSingleton();
246 
248  static std::map<std::string, util::ParamData>& Parameters();
250  static std::map<char, std::string>& Aliases();
251 
253  static std::string ProgramName();
254 
260  static void SetPassed(const std::string& name);
261 
270  static void StoreSettings(const std::string& name);
271 
281  static void RestoreSettings(const std::string& name, const bool fatal = true);
282 
286  static void ClearSettings();
287 
288  private:
290  std::map<char, std::string> aliases;
292  std::map<std::string, util::ParamData> parameters;
293 
294  public:
297  typedef std::map<std::string, std::map<std::string,
298  void (*)(util::ParamData&, const void*, void*)>> FunctionMapType;
300 
301  private:
303  std::map<std::string, std::tuple<std::map<std::string, util::ParamData>,
304  std::map<char, std::string>, FunctionMapType>> storageMap;
305 
306  public:
308  bool didParse;
309 
312  std::string programName;
313 
316 
318  friend class Timer;
319 
322  private:
326  IO();
327 
329  IO(const IO& other);
331  IO& operator=(const IO& other);
332 };
333 
334 } // namespace mlpack
335 
336 // Include the actual definitions of templated methods
337 #include "io_impl.hpp"
338 
339 #endif
Linear algebra utility functions, generally performed on matrices or vectors.
static void StoreSettings(const std::string &name)
Take all parameters and function mappings and store them, under the given name.
The core includes that mlpack expects; standard C++ includes and Armadillo.
static void Add(util::ParamData &&d)
Adds a parameter to the hierarchy; use the PARAM_*() macros instead of this (i.e. ...
bool didParse
True, if IO was used to parse command line options.
Definition: io.hpp:308
static void RestoreSettings(const std::string &name, const bool fatal=true)
Restore all of the parameters and function mappings of the given name, if they exist.
This structure holds all of the information about a single parameter, including its value (which is s...
Definition: param_data.hpp:52
static void MakeInPlaceCopy(const std::string &outputParamName, const std::string &inputParamName)
Given two (matrix) parameters, ensure that the first is an in-place copy of the second.
Parses the command line for parameters and holds user-specified parameters.
Definition: io.hpp:172
static T & GetRawParam(const std::string &identifier)
Get the raw value of the parameter before any processing that GetParam() might normally do...
static IO & GetSingleton()
Retrieve the singleton.
The timer class provides a way for mlpack methods to be timed.
Definition: timers.hpp:46
static std::map< char, std::string > & Aliases()
Return a modifiable list of aliases that IO knows about.
static void SetPassed(const std::string &name)
Mark a particular parameter as passed.
std::map< std::string, std::map< std::string, void(*)(util::ParamData &, const void *, void *)> > FunctionMapType
Map for functions and types.
Definition: io.hpp:298
static T & GetParam(const std::string &identifier)
Get the value of type T found while parsing.
static void ClearSettings()
Clear all of the settings, removing all parameters and function mappings.
static bool HasParam(const std::string &identifier)
See if the specified flag was found while parsing.
util::BindingDetails doc
Holds the bindingDetails objects.
Definition: io.hpp:321
Timers timer
Holds the timer objects.
Definition: io.hpp:315
FunctionMapType functionMap
Definition: io.hpp:299
static std::string GetPrintableParam(const std::string &identifier)
Cast the given parameter of the given type to a short, printable std::string, for use in status messa...
This structure holds all of the information about bindings documentation.
static std::map< std::string, util::ParamData > & Parameters()
Return a modifiable list of parameters that IO knows about.
std::string programName
Holds the name of the program for –version.
Definition: io.hpp:312
static std::string ProgramName()
Get the program name as set by the BINDING_NAME() macro.