mlpack
default_param_impl.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_BINDINGS_CLI_DEFAULT_PARAM_IMPL_HPP
13 #define MLPACK_BINDINGS_CLI_DEFAULT_PARAM_IMPL_HPP
14 
15 #include "default_param.hpp"
16 
17 namespace mlpack {
18 namespace bindings {
19 namespace cli {
20 
24 template<typename T>
25 std::string DefaultParamImpl(
27  const typename std::enable_if<!arma::is_arma_type<T>::value>::type* /* junk */,
28  const typename std::enable_if<!util::IsStdVector<T>::value>::type* /* junk */,
29  const typename std::enable_if<!data::HasSerialize<T>::value>::type* /* junk */,
30  const typename std::enable_if<!std::is_same<T,
31  std::string>::value>::type*,
32  const typename std::enable_if<!std::is_same<T,
33  std::tuple<mlpack::data::DatasetInfo, arma::mat>>::value>::type* /* junk */)
34 {
35  std::ostringstream oss;
36  if (!std::is_same<T, bool>::value)
37  oss << boost::any_cast<T>(data.value);
38 
39  return oss.str();
40 }
41 
45 template<typename T>
46 std::string DefaultParamImpl(
48  const typename std::enable_if<util::IsStdVector<T>::value>::type* /* junk */)
49 {
50  // Print each element in an array delimited by square brackets.
51  std::ostringstream oss;
52  const T& vector = boost::any_cast<T>(data.value);
53  oss << "[";
54  if (std::is_same<T, std::vector<std::string>>::value)
55  {
56  if (vector.size() > 0)
57  {
58  for (size_t i = 0; i < vector.size() - 1; ++i)
59  {
60  oss << "'" << vector[i] << "', ";
61  }
62 
63  oss << "'" << vector[vector.size() - 1] << "'";
64  }
65 
66  oss << "]";
67  }
68  else
69  {
70  if (vector.size() > 0)
71  {
72  for (size_t i = 0; i < vector.size() - 1; ++i)
73  {
74  oss << vector[i] << ", ";
75  }
76 
77  oss << vector[vector.size() - 1];
78  }
79 
80  oss << "]";
81  }
82 
83  return oss.str();
84 }
85 
89 template<typename T>
90 std::string DefaultParamImpl(
92  const typename std::enable_if<std::is_same<T, std::string>::value>::type*)
93 {
94  const std::string& s = *boost::any_cast<std::string>(&data.value);
95  return "'" + s + "'";
96 }
97 
101 template<typename T>
102 std::string DefaultParamImpl(
103  util::ParamData& /* data */,
104  const typename std::enable_if<
105  arma::is_arma_type<T>::value ||
106  std::is_same<T, std::tuple<mlpack::data::DatasetInfo,
107  arma::mat>>::value>::type* /* junk */)
108 {
109  // The filename will always be empty.
110  return "''";
111 }
112 
116 template<typename T>
117 std::string DefaultParamImpl(
118  util::ParamData& /* data */,
119  const typename std::enable_if<!arma::is_arma_type<T>::value>::type* /* junk */,
120  const typename std::enable_if<data::HasSerialize<T>::value>::type* /* junk */)
121 {
122  return "''";
123 }
124 
125 
126 } // namespace cli
127 } // namespace bindings
128 } // namespace mlpack
129 
130 #endif
Auxiliary information for a dataset, including mappings to/from strings (or other types) and the data...
Definition: dataset_mapper.hpp:41
Definition: has_serialize.hpp:47
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
This structure holds all of the information about a single parameter, including its value (which is s...
Definition: param_data.hpp:52
std::string DefaultParamImpl(util::ParamData &data, const typename std::enable_if<!arma::is_arma_type< T >::value >::type *=0, const typename std::enable_if<!util::IsStdVector< 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::string >::value >::type *=0, const typename std::enable_if<!std::is_same< T, std::tuple< mlpack::data::DatasetInfo, arma::mat >>::value >::type *=0)
Return the default value of an option.
Definition: default_param_impl.hpp:25
Metaprogramming structure for vector detection.
Definition: is_std_vector.hpp:23
boost::any value
The actual value that is held.
Definition: param_data.hpp:82