set_param.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_BINDINGS_CLI_SET_PARAM_HPP
13 #define MLPACK_BINDINGS_CLI_SET_PARAM_HPP
14 
15 #include <mlpack/prereqs.hpp>
16 #include "parameter_type.hpp"
17 
18 namespace mlpack {
19 namespace bindings {
20 namespace cli {
21 
26 template<typename T>
27 void SetParam(
28  util::ParamData& d,
29  const boost::any& value,
30  const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
31  const typename std::enable_if<!data::HasSerialize<T>::value>::type* = 0,
32  const typename std::enable_if<!std::is_same<T,
33  std::tuple<mlpack::data::DatasetInfo, arma::mat>>::value>::type* = 0,
34  const typename std::enable_if<!std::is_same<T, bool>::value>::type* = 0)
35 {
36  // No mapping is needed.
37  d.value = value;
38 }
39 
43 template<typename T>
44 void SetParam(
45  util::ParamData& d,
46  const boost::any& /* value */,
47  const typename std::enable_if<std::is_same<T, bool>::value>::type* = 0)
48 {
49  // Force set to the value of whether or not this was passed.
50  d.value = d.wasPassed;
51 }
52 
57 template<typename T>
58 void SetParam(
59  util::ParamData& d,
60  const boost::any& value,
61  const typename std::enable_if<arma::is_arma_type<T>::value ||
62  std::is_same<T,
63  std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0)
64 {
65  // We're setting the string filename.
66  typedef std::tuple<T, typename ParameterType<T>::type> TupleType;
67  TupleType& tuple = *boost::any_cast<TupleType>(&d.value);
68  std::get<0>(std::get<1>(tuple)) = boost::any_cast<std::string>(value);
69 }
70 
75 template<typename T>
76 void SetParam(
77  util::ParamData& d,
78  const boost::any& value,
79  const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
80  const typename std::enable_if<data::HasSerialize<T>::value>::type* = 0)
81 {
82  // We're setting the string filename.
83  typedef std::tuple<T*, typename ParameterType<T>::type> TupleType;
84  TupleType& tuple = *boost::any_cast<TupleType>(&d.value);
85  std::get<1>(tuple) = boost::any_cast<std::string>(value);
86 }
87 
96 template<typename T>
97 void SetParam(util::ParamData& d, const void* input, void* /* output */)
98 {
99  SetParam<typename std::remove_pointer<T>::type>(
100  const_cast<util::ParamData&>(d), *((boost::any*) input));
101 }
102 
103 } // namespace cli
104 } // namespace bindings
105 } // namespace mlpack
106 
107 #endif
boost::any value
The actual value that is held.
Definition: param_data.hpp:79
Linear algebra utility functions, generally performed on matrices or vectors.
bool wasPassed
True if the option was passed to the program.
Definition: param_data.hpp:66
The core includes that mlpack expects; standard C++ includes and Armadillo.
void SetParam(util::ParamData &d, const boost::any &value, const typename std::enable_if<!arma::is_arma_type< T >::value >::type *=0, const typename std::enable_if<!data::HasSerialize< T >::value >::type *=0, const typename std::enable_if<!std::is_same< T, std::tuple< mlpack::data::DatasetInfo, arma::mat >>::value >::type *=0, const typename std::enable_if<!std::is_same< T, bool >::value >::type *=0)
This overload is called when nothing special needs to happen to the name of the parameter.
Definition: set_param.hpp:27
This structure holds all of the information about a single parameter, including its value (which is s...
Definition: param_data.hpp:52