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
17 
18 #include <mlpack/core/util/io.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 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;
94  IO::GetSingleton().functionMap[tname]["GetParam"] = &GetParam;
95  IO::GetSingleton().functionMap[tname]["GetAllocatedMemory"] =
96  &GetAllocatedMemory;
97  IO::GetSingleton().functionMap[tname]["DeleteAllocatedMemory"] =
98  &DeleteAllocatedMemory;
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
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. ...
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
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.
static void SetPassed(const std::string &name)
Mark a particular parameter as passed.
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 IO class.
Definition: test_option.hpp:40
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
bool noTranspose
True if this is a matrix that should not be transposed.
Definition: param_data.hpp:69