md_option.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_BINDINGS_MARKDOWN_MD_OPTION_HPP
13 #define MLPACK_BINDINGS_MARKDOWN_MD_OPTION_HPP
14 
16 #include <mlpack/core/util/io.hpp>
17 #include "default_param.hpp"
18 #include "get_param.hpp"
19 #include "get_printable_param.hpp"
20 #include "get_printable_param_name.hpp" // For cli bindings.
21 #include "get_printable_param_value.hpp" // For cli bindings.
22 #include "get_printable_type.hpp"
23 #include "is_serializable.hpp"
24 
25 namespace mlpack {
26 namespace bindings {
27 namespace markdown {
28 
32 template<typename T>
33 class MDOption
34 {
35  public:
41  MDOption(const T defaultValue,
42  const std::string& identifier,
43  const std::string& description,
44  const std::string& alias,
45  const std::string& cppName,
46  const bool required = false,
47  const bool input = true,
48  const bool noTranspose = false,
49  const std::string& bindingName = "")
50  {
51  // Create the ParamData object to give to CLI.
53 
54  data.desc = description;
55  data.name = identifier;
56  data.tname = TYPENAME(T);
57  data.alias = alias[0];
58  data.wasPassed = false;
59  data.noTranspose = noTranspose;
60  data.required = required;
61  data.input = input;
62  data.loaded = false;
63  data.cppType = cppName;
64 
65  // Every parameter we'll get from Markdown will have the correct type.
66  data.value = ANY(defaultValue);
67 
68  // Set the function pointers that we'll need. Most of these simply delegate
69  // to the current binding type's implementation. Any new language will need
70  // to have all of these implemented, and the Markdown implementation will
71  // need to properly delegate.
72  IO::AddFunction(data.tname, "DefaultParam", &DefaultParam<T>);
73  IO::AddFunction(data.tname, "GetParam", &GetParam<T>);
74  IO::AddFunction(data.tname, "GetPrintableParam", &GetPrintableParam<T>);
75  IO::AddFunction(data.tname, "GetPrintableParamName",
76  &GetPrintableParamName<T>);
77  IO::AddFunction(data.tname, "GetPrintableParamValue",
78  &GetPrintableParamValue<T>);
79  IO::AddFunction(data.tname, "GetPrintableType", &GetPrintableType<T>);
80  IO::AddFunction(data.tname, "IsSerializable", &IsSerializable<T>);
81 
82  // Add the option.
83  if (identifier != "verbose" && identifier != "copy_all_inputs" &&
84  identifier != "help" && identifier != "info" && identifier != "version")
85  {
86  IO::AddParameter(bindingName, std::move(data));
87  }
88  else
89  {
91  if (p.Parameters().count(identifier) == 0)
92  IO::AddParameter("", std::move(data));
93  }
94  }
95 };
96 
97 } // namespace markdown
98 } // namespace bindings
99 } // namespace mlpack
100 
101 #endif
ANY value
The actual value that is held.
Definition: param_data.hpp:78
Linear algebra utility functions, generally performed on matrices or vectors.
MDOption(const T defaultValue, const std::string &identifier, const std::string &description, const std::string &alias, const std::string &cppName, const bool required=false, const bool input=true, const bool noTranspose=false, const std::string &bindingName="")
Construct an MDOption object.
Definition: md_option.hpp:41
bool wasPassed
True if the option was passed to the program.
Definition: param_data.hpp:65
The Markdown option class.
Definition: md_option.hpp:33
static util::Params Parameters(const std::string &bindingName)
Return a new Params object initialized with all the parameters of the binding bindingName.
std::string desc
Description of this parameter, if any.
Definition: param_data.hpp:57
#define ANY
Definition: prereqs.hpp:82
bool input
True if this option is an input option (otherwise, it is output).
Definition: param_data.hpp:72
std::map< std::string, ParamData > & Parameters()
Get the map of parameters.
Definition: params.hpp:96
This structure holds all of the information about a single parameter, including its value (which is s...
Definition: param_data.hpp:51
bool loaded
If this is an input parameter that needs extra loading, this indicates whether or not it has been loa...
Definition: param_data.hpp:75
constexpr auto data(Container const &container) noexcept -> decltype(container.data())
Definition: iterator.hpp:79
#define TYPENAME(x)
The TYPENAME macro is used internally to convert a type into a string.
Definition: param_data.hpp:21
char alias
Alias for this parameter.
Definition: param_data.hpp:62
std::string tname
Type information of this parameter.
Definition: param_data.hpp:60
std::string name
Name of this parameter.
Definition: param_data.hpp:55
static void AddFunction(const std::string &type, const std::string &name, void(*func)(util::ParamData &, const void *, void *))
Add a function to the function map.
bool required
True if this option is required.
Definition: param_data.hpp:70
static void AddParameter(const std::string &bindingName, util::ParamData &&d)
Adds a parameter to the hierarchy; use the PARAM_*() macros instead of this (i.e. ...
The Params class holds all information about the parameters passed to a specific binding.
Definition: params.hpp:20
std::string cppType
The true name of the type, as it would be written in C++.
Definition: param_data.hpp:80
auto move(Range &&rng, OutputIt &&it) -> enable_if_t< is_range< Range >::value, decay_t< OutputIt > >
Definition: algorithm.hpp:736
bool noTranspose
True if this is a matrix that should not be transposed.
Definition: param_data.hpp:68