test_option.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_CORE_BINDINGS_TESTS_TEST_OPTION_HPP
14 #define MLPACK_CORE_BINDINGS_TESTS_TEST_OPTION_HPP
15 
16 #include <string>
17 
18 #include <mlpack/core/util/cli.hpp>
19 #include "get_printable_param.hpp"
20 #include "get_param.hpp"
21 #include "get_allocated_memory.hpp"
23 
24 namespace mlpack {
25 namespace bindings {
26 namespace tests {
27 
28 // Defined in mlpack_main.hpp.
29 extern std::string programName;
30 
39 template<typename N>
41 {
42  public:
61  TestOption(const N defaultValue,
62  const std::string& identifier,
63  const std::string& description,
64  const std::string& alias,
65  const std::string& cppName,
66  const bool required = false,
67  const bool input = true,
68  const bool noTranspose = false,
69  const std::string& testName = "")
70  {
71  // Create the ParamData object to give to CLI.
72  util::ParamData data;
73 
74  data.desc = description;
75  data.name = identifier;
76  data.tname = TYPENAME(N);
77  data.alias = alias[0];
78  data.wasPassed = false;
79  data.noTranspose = noTranspose;
80  data.required = required;
81  data.input = input;
82  data.loaded = false;
83  data.cppType = cppName;
84  data.value = boost::any(defaultValue);
85  data.persistent = false;
86 
87  const std::string tname = data.tname;
88 
89  CLI::RestoreSettings(testName, false);
90 
91  // Set some function pointers that we need.
92  CLI::GetSingleton().functionMap[tname]["GetPrintableParam"] =
93  &GetPrintableParam<N>;
94  CLI::GetSingleton().functionMap[tname]["GetParam"] = &GetParam<N>;
95  CLI::GetSingleton().functionMap[tname]["GetAllocatedMemory"] =
96  &GetAllocatedMemory<N>;
97  CLI::GetSingleton().functionMap[tname]["DeleteAllocatedMemory"] =
98  &DeleteAllocatedMemory<N>;
99 
100  CLI::Add(std::move(data));
101 
102  // If this is an output option, set it as passed.
103  if (!input)
104  CLI::SetPassed(identifier);
105 
106  CLI::StoreSettings(testName);
108  }
109 };
110 
120 {
121  public:
131  ProgramDoc(const std::string& programName,
132  const std::string& documentation);
133 
135  std::string programName;
137  std::string documentation;
138 };
139 
140 } // namespace tests
141 } // namespace bindings
142 } // namespace mlpack
143 
144 #endif
A static object whose constructor registers program documentation with the CLI class.
static void SetPassed(const std::string &name)
Mark a particular parameter as passed.
std::string programName
The name of the program.
boost::any value
The actual value that is held.
Definition: param_data.hpp:82
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: add_to_po.hpp:21
bool wasPassed
True if the option was passed to the program.
Definition: param_data.hpp:66
static CLI & GetSingleton()
Retrieve the singleton.
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.
TestOption(const N 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 &testName="")
Construct an Option object.
Definition: test_option.hpp:61
std::string desc
Description of this parameter, if any.
Definition: param_data.hpp:58
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
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
A static object whose constructor registers a parameter with the CLI class.
Definition: test_option.hpp:40
static void Add(util::ParamData &&d)
Adds a parameter to the hierarchy; use the PARAM_*() macros instead of this (i.e. ...
std::string documentation
Documentation for what the program does.
std::string cppType
The true name of the type, as it would be written in C++.
Definition: param_data.hpp:84
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.
FunctionMapType functionMap
Definition: cli.hpp:302
bool noTranspose
True if this is a matrix that should not be transposed.
Definition: param_data.hpp:69