mlpack  3.0.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
print_doc.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_BINDINGS_PYTHON_PRINT_DOC_HPP
13 #define MLPACK_BINDINGS_PYTHON_PRINT_DOC_HPP
14 
15 #include <mlpack/prereqs.hpp>
17 #include "get_python_type.hpp"
18 
19 namespace mlpack {
20 namespace bindings {
21 namespace python {
22 
35 template<typename T>
36 void PrintDoc(const util::ParamData& d,
37  const void* input,
38  void* /* output */)
39 {
40  const size_t indent = *((size_t*) input);
41  std::ostringstream oss;
42  oss << " - ";
43  if (d.name == "lambda") // Don't print Python keywords.
44  oss << d.name << "_ (";
45  else
46  oss << d.name << " (";
47  oss << GetPythonType<typename std::remove_pointer<T>::type>(d) << "): "
48  << d.desc;
49 
50  // Print a default, if possible.
51  if (!d.required)
52  {
53  if (d.cppType == "std::string")
54  {
55  oss << " Default value '" << boost::any_cast<std::string>(d.value)
56  << "'.";
57  }
58  else if (d.cppType == "double")
59  {
60  oss << " Default value " << boost::any_cast<double>(d.value) << ".";
61  }
62  else if (d.cppType == "int")
63  {
64  oss << " Default value " << boost::any_cast<int>(d.value) << ".";
65  }
66  }
67 
68  std::cout << util::HyphenateString(oss.str(), indent + 4);
69 }
70 
71 } // namespace python
72 } // namespace bindings
73 } // namespace mlpack
74 
75 #endif
boost::any value
The actual value that is held.
Definition: param_data.hpp:82
void PrintDoc(const util::ParamData &d, const void *input, void *)
Print the docstring documentation for a given parameter.
Definition: print_doc.hpp:36
The core includes that mlpack expects; standard C++ includes and Armadillo.
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
std::string name
Name of this parameter.
Definition: param_data.hpp:56
bool required
True if this option is required.
Definition: param_data.hpp:71
std::string HyphenateString(const std::string &str, int padding)
 * Hyphenate a string or split it onto multiple 80-character lines, with some  * amount of padding ...
std::string cppType
The true name of the type, as it would be written in C++.
Definition: param_data.hpp:84