R_option.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_BINDINGS_R_R_OPTION_HPP
13 #define MLPACK_BINDINGS_R_R_OPTION_HPP
15 #include "get_param.hpp"
16 #include "get_printable_param.hpp"
17 #include "print_input_param.hpp"
20 #include "print_doc.hpp"
21 #include "print_serialize_util.hpp"
22 
23 namespace mlpack {
24 namespace bindings {
25 namespace r {
26 
30 template<typename T>
31 class ROption
32 {
33  public:
52  ROption(const T defaultValue,
53  const std::string& identifier,
54  const std::string& description,
55  const std::string& alias,
56  const std::string& cppName,
57  const bool required = false,
58  const bool input = true,
59  const bool noTranspose = false,
60  const std::string& /* testName */ = "")
61  {
62  // Create the ParamData object to give to IO.
63  util::ParamData data;
64  data.desc = description;
65  data.name = identifier;
66  data.tname = TYPENAME(T);
67  data.alias = alias[0];
68  data.wasPassed = false;
69  data.noTranspose = noTranspose;
70  data.required = required;
71  data.input = input;
72  data.loaded = false;
73 
74  // Only "verbose" will be persistent.
75  if (identifier == "verbose")
76  data.persistent = true;
77  else
78  data.persistent = false;
79  data.cppType = cppName;
80 
81  // Every parameter we'll get from R will have the correct type.
82  data.value = boost::any(defaultValue);
83 
84  // Restore the parameters for this program.
85  if (identifier != "verbose")
87 
88  // Set the function pointers that we'll need. All of these function
89  // pointers will be used by both the program that generates the R, and
90  // also the binding itself. (The binding itself will only use GetParam,
91  // GetPrintableParam, and GetRawParam.)
92  IO::GetSingleton().functionMap[data.tname]["GetParam"] = &GetParam<T>;
93  IO::GetSingleton().functionMap[data.tname]["GetPrintableParam"] =
94  &GetPrintableParam<T>;
95 
96  // These are used by the R generator.
97  IO::GetSingleton().functionMap[data.tname]["PrintDoc"] = &PrintDoc<T>;
98  IO::GetSingleton().functionMap[data.tname]["PrintInputParam"] =
99  &PrintInputParam<T>;
100  IO::GetSingleton().functionMap[data.tname]["PrintOutputProcessing"] =
101  &PrintOutputProcessing<T>;
102  IO::GetSingleton().functionMap[data.tname]["PrintInputProcessing"] =
103  &PrintInputProcessing<T>;
104  IO::GetSingleton().functionMap[data.tname]["PrintSerializeUtil"] =
105  &PrintSerializeUtil<T>;
106 
107  // Add the ParamData object, then store. This is necessary because we may
108  // import more than one .so or .o that uses IO, so we have to keep the
109  // options separate. programName is a global variable from mlpack_main.hpp.
110  IO::Add(std::move(data));
111  if (identifier != "verbose")
114  }
115 };
116 
117 } // namespace r
118 } // namespace bindings
119 } // namespace mlpack
120 
121 #endif
boost::any value
The actual value that is held.
Definition: param_data.hpp:82
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
bool persistent
If this should be preserved across different settings (i.e.
Definition: param_data.hpp:79
static void StoreSettings(const std::string &name)
Take all parameters and function mappings and store them, under the given name.
static void Add(util::ParamData &&d)
Adds a parameter to the hierarchy; use the PARAM_*() macros instead of this (i.e. ...
ROption(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 &="")
Construct a ROption object.
Definition: R_option.hpp:52
std::string desc
Description of this parameter, if any.
Definition: param_data.hpp:58
static void RestoreSettings(const std::string &name, const bool fatal=true)
Restore all of the parameters and function mappings of the given name, if they exist.
bool input
True if this option is an input option (otherwise, it is output).
Definition: param_data.hpp:73
This structure holds all of the information about a single parameter, including its value (which is s...
Definition: param_data.hpp:52
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:76
#define TYPENAME(x)
The TYPENAME macro is used internally to convert a type into a string.
Definition: param_data.hpp:22
static IO & GetSingleton()
Retrieve the singleton.
char alias
Alias for this parameter.
Definition: param_data.hpp:63
std::string tname
Type information of this parameter.
Definition: param_data.hpp:61
static void ClearSettings()
Clear all of the settings, removing all parameters and function mappings.
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
FunctionMapType functionMap
Definition: io.hpp:299
std::string cppType
The true name of the type, as it would be written in C++.
Definition: param_data.hpp:84
The R option class.
Definition: R_option.hpp:31
bool noTranspose
True if this is a matrix that should not be transposed.
Definition: param_data.hpp:69
static std::string ProgramName()
Get the program name as set by the BINDING_NAME() macro.