mlpack  2.2.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
param.hpp
Go to the documentation of this file.
1 
15 #ifndef MLPACK_CORE_UTIL_PARAM_HPP
16 #define MLPACK_CORE_UTIL_PARAM_HPP
17 
18 #include <mlpack/core/util/cli.hpp>
19 
37 #define PROGRAM_INFO(NAME, DESC) static mlpack::util::ProgramDoc \
38  cli_programdoc_dummy_object = mlpack::util::ProgramDoc(NAME, DESC);
39 
57 #define PARAM_FLAG(ID, DESC, ALIAS) \
58  PARAM_FLAG_INTERNAL(ID, DESC, ALIAS);
59 
81 #define PARAM_INT_IN(ID, DESC, ALIAS, DEF) \
82  PARAM_IN(int, ID, DESC, ALIAS, DEF, false)
83 
109 #define PARAM_INT_OUT(ID, DESC) \
110  PARAM_OUT(int, ID, DESC, "", 0, false)
111 
133 #define PARAM_DOUBLE_IN(ID, DESC, ALIAS, DEF) \
134  PARAM_IN(double, ID, DESC, ALIAS, DEF, false)
135 
161 #define PARAM_DOUBLE_OUT(ID, DESC) \
162  PARAM_OUT(double, ID, DESC, "", 0.0, false)
163 
186 #define PARAM_STRING_IN(ID, DESC, ALIAS, DEF) \
187  PARAM_IN(std::string, ID, DESC, ALIAS, DEF, false)
188 
223 #define PARAM_STRING_OUT(ID, DESC, ALIAS) \
224  PARAM_OUT(std::string, ID, DESC, ALIAS, "", false)
225 
247 #define PARAM_VECTOR_IN(T, ID, DESC, ALIAS) \
248  PARAM_IN(std::vector<T>, ID, DESC, ALIAS, std::vector<T>(), false)
249 
276 #define PARAM_VECTOR_OUT(T, ID) \
277  PARAM_OUT(std::vector<T>, ID, DESC, "", std::vector<T>(), false)
278 
298 #define PARAM_INT_IN_REQ(ID, DESC, ALIAS) \
299  PARAM_IN(int, ID, DESC, ALIAS, 0, true)
300 
320 #define PARAM_DOUBLE_IN_REQ(ID, DESC, ALIAS) \
321  PARAM_IN(double, ID, DESC, ALIAS, 0.0d, true)
322 
342 #define PARAM_STRING_IN_REQ(ID, DESC, ALIAS) \
343  PARAM_IN(std::string, ID, DESC, ALIAS, "", true)
344 
365 #define PARAM_VECTOR_IN_REQ(T, ID, DESC, ALIAS) \
366  PARAM_IN(std::vector<T>, ID, DESC, ALIAS, std::vector<T>(), true);
367 
373 // These are ugly, but necessary utility functions we must use to generate a
374 // unique identifier inside of the PARAM() module.
375 #define JOIN(x, y) JOIN_AGAIN(x, y)
376 #define JOIN_AGAIN(x, y) x ## y
377 
393 #ifdef __COUNTER__
394  #define PARAM_IN(T, ID, DESC, ALIAS, DEF, REQ) \
395  static mlpack::util::Option<T> \
396  JOIN(cli_option_dummy_object_in_, __COUNTER__) \
397  (false, DEF, ID, DESC, ALIAS, REQ, true);
398 
399  #define PARAM_OUT(T, ID, DESC, ALIAS, DEF, REQ) \
400  static mlpack::util::Option<T> \
401  JOIN(cli_option_dummy_object_out_, __COUNTER__) \
402  (false, DEF, ID, DESC, ALIAS, REQ, false);
403 
405  #define PARAM_FLAG_INTERNAL(ID, DESC, ALIAS) static \
406  mlpack::util::Option<bool> JOIN(__io_option_flag_object_, __COUNTER__) \
407  (ID, DESC, ALIAS);
408 
410 #else
411  // We have to do some really bizarre stuff since __COUNTER__ isn't defined. I
412  // don't think we can absolutely guarantee success, but it should be "good
413  // enough". We use the __LINE__ macro and the type of the parameter to try
414  // and get a good guess at something unique.
415  #define PARAM_IN(T, ID, DESC, ALIAS, DEF, REQ) \
416  static mlpack::util::Option<T> \
417  JOIN(JOIN(io_option_dummy_object_in_, __LINE__), opt) \
418  (false, DEF, ID, DESC, ALIAS, REQ, true);
419 
420  #define PARAM_OUT(T, ID, DESC, ALIAS, DEF, REQ) \
421  static mlpack::util::Option<T> \
422  JOIN(JOIN(io_option_dummy_object_out_, __LINE__), opt) \
423  (false, DEF, ID, DESC, ALIAS, REQ, false);
424 
426  #define PARAM_FLAG_INTERNAL(ID, DESC, ALIAS) static \
427  mlpack::util::Option<bool> JOIN(__io_option_flag_object_, __LINE__) \
428  (ID, DESC, ALIAS);
429 
431 #endif
432 
433 #endif