mlpack 3.4.2
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
20#include "get_param.hpp"
23
24namespace mlpack {
25namespace bindings {
26namespace tests {
27
28// Defined in mlpack_main.hpp.
29extern std::string programName;
30
39template<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 IO.
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 IO::RestoreSettings(testName, false);
90
91 // Set some function pointers that we need.
92 IO::GetSingleton().functionMap[tname]["GetPrintableParam"] =
93 &GetPrintableParam<N>;
94 IO::GetSingleton().functionMap[tname]["GetParam"] = &GetParam<N>;
95 IO::GetSingleton().functionMap[tname]["GetAllocatedMemory"] =
96 &GetAllocatedMemory<N>;
97 IO::GetSingleton().functionMap[tname]["DeleteAllocatedMemory"] =
98 &DeleteAllocatedMemory<N>;
99
100 IO::Add(std::move(data));
101
102 // If this is an output option, set it as passed.
103 if (!input)
104 IO::SetPassed(identifier);
105
106 IO::StoreSettings(testName);
108 }
109};
110
111} // namespace tests
112} // namespace bindings
113} // namespace mlpack
114
115#endif
static void SetPassed(const std::string &name)
Mark a particular parameter as passed.
FunctionMapType functionMap
Definition: io.hpp:299
static IO & GetSingleton()
Retrieve the singleton.
static void ClearSettings()
Clear all of the settings, removing all parameters and function mappings.
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.
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.
A static object whose constructor registers a parameter with the IO class.
Definition: test_option.hpp:41
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
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
#define TYPENAME(x)
The TYPENAME macro is used internally to convert a type into a string.
Definition: param_data.hpp:22
This structure holds all of the information about a single parameter, including its value (which is s...
Definition: param_data.hpp:53
bool noTranspose
True if this is a matrix that should not be transposed.
Definition: param_data.hpp:69
char alias
Alias for this parameter.
Definition: param_data.hpp:63
std::string desc
Description of this parameter, if any.
Definition: param_data.hpp:58
bool wasPassed
True if the option was passed to the program.
Definition: param_data.hpp:66
boost::any value
The actual value that is held.
Definition: param_data.hpp:82
std::string tname
Type information of this parameter.
Definition: param_data.hpp:61
bool required
True if this option is required.
Definition: param_data.hpp:71
bool input
True if this option is an input option (otherwise, it is output).
Definition: param_data.hpp:73
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
std::string name
Name of this parameter.
Definition: param_data.hpp:56
std::string cppType
The true name of the type, as it would be written in C++.
Definition: param_data.hpp:84
bool persistent
If this should be preserved across different settings (i.e.
Definition: param_data.hpp:79