ensmallen
mlpack
fast, flexible C++ machine learning library
add_to_po.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_BINDINGS_CLI_ADD_TO_PO_HPP
14 #define MLPACK_BINDINGS_CLI_ADD_TO_PO_HPP
15 
17 #include <boost/program_options.hpp>
19 #include "map_parameter_name.hpp"
20 
21 namespace mlpack {
22 namespace bindings {
23 namespace cli {
24 
32 template<typename T>
33 void AddToPO(const std::string& boostName,
34  const std::string& descr,
35  boost::program_options::options_description& desc,
36  const typename boost::disable_if<util::IsStdVector<T>>::type* = 0,
37  const typename boost::disable_if<std::is_same<T, bool>>::type* = 0)
38 {
39  desc.add_options()(boostName.c_str(), boost::program_options::value<T>(),
40  descr.c_str());
41 }
42 
51 template<typename T>
52 void AddToPO(const std::string& boostName,
53  const std::string& descr,
54  boost::program_options::options_description& desc,
55  const typename boost::enable_if<util::IsStdVector<T>>::type* = 0,
56  const typename boost::disable_if<std::is_same<T, bool>>::type* = 0)
57 {
58  desc.add_options()(boostName.c_str(),
59  boost::program_options::value<T>()->multitoken(), descr.c_str());
60 }
61 
69 template<typename T>
70 void AddToPO(const std::string& boostName,
71  const std::string& descr,
72  boost::program_options::options_description& desc,
73  const typename boost::disable_if<util::IsStdVector<T>>::type* = 0,
74  const typename boost::enable_if<std::is_same<T, bool>>::type* = 0)
75 {
76  desc.add_options()(boostName.c_str(), descr.c_str());
77 }
78 
87 template<typename T>
88 void AddToPO(const util::ParamData& d,
89  const void* /* input */,
90  void* output)
91 {
92  // Cast boost::program_options::options_description object.
93  boost::program_options::options_description* desc =
94  (boost::program_options::options_description*) output;
95 
96  // Generate the name to be given to boost::program_options.
97  const std::string mappedName =
98  MapParameterName<typename std::remove_pointer<T>::type>(d.name);
99  std::string boostName = (d.alias != '\0') ? mappedName + "," +
100  std::string(1, d.alias) : mappedName;
101 
102  // Note that we have to add the option as type equal to the mapped type, not
103  // the true type of the option.
104  AddToPO<typename ParameterType<typename std::remove_pointer<T>::type>::type>(
105  boostName, d.desc, *desc);
106 }
107 
108 } // namespace cli
109 } // namespace bindings
110 } // namespace mlpack
111 
112 #endif
void AddToPO(const std::string &boostName, const std::string &descr, boost::program_options::options_description &desc, const typename boost::disable_if< util::IsStdVector< T >>::type *=0, const typename boost::disable_if< std::is_same< T, bool >>::type *=0)
Add a non-vector option to boost::program_options.
Definition: add_to_po.hpp:33
.hpp
Definition: add_to_po.hpp:21
std::string desc
Description of this parameter, if any.
Definition: param_data.hpp:58
This structure holds all of the information about a single parameter, including its value (which is s...
Definition: param_data.hpp:52
Metaprogramming structure for vector detection.
char alias
Alias for this parameter.
Definition: param_data.hpp:63
std::string name
Name of this parameter.
Definition: param_data.hpp:56