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"
23 #include "print_import_decl.hpp"
25 #include "print_method_config.hpp"
26 #include "print_method_init.hpp"
27 #include "print_model_util.hpp"
29 
30 namespace mlpack {
31 namespace bindings {
32 namespace go {
33 
34 // Defined in mlpack_main.hpp.
35 extern std::string programName;
36 
40 template<typename T>
41 class GoOption
42 {
43  public:
62  GoOption(const T defaultValue,
63  const std::string& identifier,
64  const std::string& description,
65  const std::string& alias,
66  const std::string& cppName,
67  const bool required = false,
68  const bool input = true,
69  const bool noTranspose = false,
70  const std::string& /*testName*/ = "")
71  {
72  // Create the ParamData object to give to CLI.
73  util::ParamData data;
74 
75  data.desc = description;
76  data.name = identifier;
77  data.tname = TYPENAME(T);
78  data.alias = alias[0];
79  data.wasPassed = false;
80  data.noTranspose = noTranspose;
81  data.required = required;
82  data.input = input;
83  data.loaded = false;
84  // Only "verbose" and "copy_all_inputs" will be persistent.
85  if (identifier == "verbose" /*|| identifier == "copy_all_inputs"*/)
86  data.persistent = true;
87  else
88  data.persistent = false;
89  data.cppType = cppName;
90 
91  data.value = boost::any(defaultValue);
92 
93  // Restore the parameters for this program.
94  if (identifier != "verbose" /*&& identifier != "copy_all_inputs"*/)
95  CLI::RestoreSettings(programName, false);
96 
97  // Set the function pointers that we'll need. All of these function
98  // pointers will be used by both the program that generates the .cpp,
99  // the .h, and the .go binding files.
100  CLI::GetSingleton().functionMap[data.tname]["GetParam"] = &GetParam<T>;
101  CLI::GetSingleton().functionMap[data.tname]["GetPrintableParam"] =
102  &GetPrintableParam<T>;
103 
104  CLI::GetSingleton().functionMap[data.tname]["DefaultParam"] =
105  &DefaultParam<T>;
106 
107  CLI::GetSingleton().functionMap[data.tname]["PrintModelUtilCPP"] =
108  &PrintModelUtilCPP<T>;
109  CLI::GetSingleton().functionMap[data.tname]["PrintModelUtilH"] =
110  &PrintModelUtilH<T>;
111  CLI::GetSingleton().functionMap[data.tname]["PrintModelUtilGo"] =
112  &PrintModelUtilGo<T>;
113  CLI::GetSingleton().functionMap[data.tname]["PrintDefnInput"] =
114  &PrintDefnInput<T>;
115  CLI::GetSingleton().functionMap[data.tname]["PrintDefnOutput"] =
116  &PrintDefnOutput<T>;
117  CLI::GetSingleton().functionMap[data.tname]["PrintDoc"] = &PrintDoc<T>;
118  CLI::GetSingleton().functionMap[data.tname]["PrintOutputProcessing"] =
119  &PrintOutputProcessing<T>;
120  CLI::GetSingleton().functionMap[data.tname]["PrintMethodConfig"] =
121  &PrintMethodConfig<T>;
122  CLI::GetSingleton().functionMap[data.tname]["PrintMethodInit"] =
123  &PrintMethodInit<T>;
124  CLI::GetSingleton().functionMap[data.tname]["ImportDecl"] =
125  &ImportDecl<T>;
126  CLI::GetSingleton().functionMap[data.tname]["PrintInputProcessing"] =
127  &PrintInputProcessing<T>;
128  CLI::GetSingleton().functionMap[data.tname]["GetType"] = &GetType<T>;
129 
130  // Add the ParamData object, then store. This is necessary because we may
131  // import more than one .so that uses CLI, so we have to keep the options
132  // separate. programName is a global variable from mlpack_main.hpp.
133  CLI::Add(std::move(data));
134  if (identifier != "verbose" /*&& identifier != "copy_all_inputs"*/)
135  CLI::StoreSettings(programName);
137  }
138 };
139 
140 } // namespace go
141 } // namespace bindings
142 } // namespace mlpack
143 
144 #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.
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.
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 &="")
Construct a GoOption object.
Definition: go_option.hpp:62
The Go option class.
Definition: go_option.hpp:41
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
std::string programName
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
static void Add(util::ParamData &&d)
Adds a parameter to the hierarchy; use the PARAM_*() macros instead of this (i.e. ...
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