go_option.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_BINDINGS_GOLANG_GO_OPTION_HPP
13 #define MLPACK_BINDINGS_GOLANG_GO_OPTION_HPP
14 
16 #include "get_param.hpp"
17 #include "get_type.hpp"
18 #include "default_param.hpp"
19 #include "get_printable_param.hpp"
20 #include "print_defn_input.hpp"
21 #include "print_defn_output.hpp"
22 #include "print_doc.hpp"
24 #include "print_method_config.hpp"
25 #include "print_method_init.hpp"
27 
28 namespace mlpack {
29 namespace bindings {
30 namespace go {
31 
35 template<typename T>
36 class GoOption
37 {
38  public:
57  GoOption(const T defaultValue,
58  const std::string& identifier,
59  const std::string& description,
60  const std::string& alias,
61  const std::string& cppName,
62  const bool required = false,
63  const bool input = true,
64  const bool noTranspose = false,
65  const std::string& bindingName = "")
66  {
67  // Create the ParamData object to give to IO.
69 
70  data.desc = description;
71  data.name = identifier;
72  data.tname = TYPENAME(T);
73  data.alias = alias[0];
74  data.wasPassed = false;
75  data.noTranspose = noTranspose;
76  data.required = required;
77  data.input = input;
78  data.loaded = false;
79  data.cppType = cppName;
80 
81  data.value = ANY(defaultValue);
82 
83  // Set the function pointers that we'll need. All of these function
84  // pointers will be used by both the program that generates the .cpp,
85  // the .h, and the .go binding files.
86  IO::AddFunction(data.tname, "GetParam", &GetParam<T>);
87  IO::AddFunction(data.tname, "GetPrintableParam", &GetPrintableParam<T>);
88  IO::AddFunction(data.tname, "DefaultParam", &DefaultParam<T>);
89  IO::AddFunction(data.tname, "PrintDefnInput", &PrintDefnInput<T>);
90  IO::AddFunction(data.tname, "PrintDefnOutput", &PrintDefnOutput<T>);
91  IO::AddFunction(data.tname, "PrintDoc", &PrintDoc<T>);
92  IO::AddFunction(data.tname, "PrintOutputProcessing",
93  &PrintOutputProcessing<T>);
94  IO::AddFunction(data.tname, "PrintMethodConfig", &PrintMethodConfig<T>);
95  IO::AddFunction(data.tname, "PrintMethodInit", &PrintMethodInit<T>);
96  IO::AddFunction(data.tname, "PrintInputProcessing",
97  &PrintInputProcessing<T>);
98  IO::AddFunction(data.tname, "GetType", &GetType<T>);
99 
100  // Add the ParamData object to the IO class for the correct binding name.
101  IO::AddParameter(bindingName, std::move(data));
102  }
103 };
104 
105 } // namespace go
106 } // namespace bindings
107 } // namespace mlpack
108 
109 #endif
ANY value
The actual value that is held.
Definition: param_data.hpp:78
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:65
The Go option class.
Definition: go_option.hpp:36
go
Definition: CMakeLists.txt:6
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
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. ...
GoOption(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 a GoOption object.
Definition: go_option.hpp:57
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