print_doc.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_BINDINGS_R_PRINT_DOC_HPP
13 #define MLPACK_BINDINGS_R_PRINT_DOC_HPP
14 
15 #include "get_r_type.hpp"
16 #include <mlpack/prereqs.hpp>
18 
19 namespace mlpack {
20 namespace bindings {
21 namespace r {
22 
35 template<typename T>
37  const void* /* input */,
38  void* output)
39 {
40  bool out = *((bool*) output);
41  std::ostringstream oss;
42  if (out)
43  oss << "#' \\item{" << d.name << "}{";
44  else
45  oss << "#' @param " << d.name << " ";
46  oss << d.desc.substr(0, d.desc.size() - 1);
47  // Print a default, if possible.
48  if (!d.required)
49  {
50  if (d.cppType == "std::string" ||
51  d.cppType == "double" ||
52  d.cppType == "int" ||
53  d.cppType == "bool")
54  {
55  oss << ". Default value \"";
56  if (d.cppType == "std::string")
57  {
58  oss << boost::any_cast<std::string>(d.value);
59  }
60  else if (d.cppType == "double")
61  {
62  oss << boost::any_cast<double>(d.value);
63  }
64  else if (d.cppType == "int")
65  {
66  oss << boost::any_cast<int>(d.value);
67  }
68  else if (d.cppType == "bool")
69  {
70  oss << (boost::any_cast<bool>(d.value) ? "TRUE" : "FALSE");
71  }
72  oss << "\"";
73  }
74  }
75 
76  oss << " (" << GetRType<typename std::remove_pointer<T>::type>(d) << ").";
77 
78  if (out)
79  oss << "}";
80 
81  MLPACK_COUT_STREAM << util::HyphenateString(oss.str(), "#' ");
82 }
83 
84 } // namespace r
85 } // namespace bindings
86 } // namespace mlpack
87 
88 #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.
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
#define MLPACK_COUT_STREAM
Definition: prereqs.hpp:45
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, const std::string &prefix, const bool force=false)
Hyphenate a string or split it onto multiple 80-character lines, with some amount of padding on each ...
std::string cppType
The true name of the type, as it would be written in C++.
Definition: param_data.hpp:81
void PrintDoc(util::ParamData &d, const void *, void *output)
Print the docstring documentation for a given parameter.
Definition: print_doc.hpp:36