56 lines
1.3 KiB
C++
56 lines
1.3 KiB
C++
|
#include <cstdio>
|
||
|
#include <iostream>
|
||
|
#include <string>
|
||
|
|
||
|
#include "paras.hpp"
|
||
|
#include "cmdline.h"
|
||
|
|
||
|
paras* opt;
|
||
|
|
||
|
void paras::print_paras() {
|
||
|
// print arguments
|
||
|
printf("------------ arguments ------------\n");
|
||
|
|
||
|
#define STR_PARA(N, S, M, D, C) \
|
||
|
printf("%-20s: %s\n", #N, OPT(N).c_str());
|
||
|
STR_PARAS
|
||
|
#undef STR_PARA
|
||
|
|
||
|
#define PARA(N, T, S, M, D, L, H, C) \
|
||
|
if (!strcmp(#T, "int")) printf("%-20s: %-10d\n", #N, OPT(N)); \
|
||
|
else printf("%-20s: %-10.2f\n", #N, OPT(N));
|
||
|
PARAS
|
||
|
#undef PARA
|
||
|
|
||
|
printf("-----------------------------------\n");
|
||
|
}
|
||
|
|
||
|
void paras::parse(int argc, char* argv[]) {
|
||
|
opt = new paras();
|
||
|
|
||
|
cmdline::parser parser;
|
||
|
|
||
|
#define STR_PARA(N, S, M, D, C) \
|
||
|
parser.add<std::string>(#N, S, C, M, D);
|
||
|
STR_PARAS
|
||
|
#undef STR_PARA
|
||
|
|
||
|
#define PARA(N, T, S, M, D, L, H, C) \
|
||
|
if (!strcmp(#T, "int")) parser.add<int>(#N, S, C, M, D, cmdline::range((int)L, (int)H)); \
|
||
|
else parser.add<double>(#N, S, C, M, D, cmdline::range((double)L, (double)H));
|
||
|
PARAS
|
||
|
#undef PARA
|
||
|
|
||
|
parser.parse_check(argc, argv);
|
||
|
|
||
|
#define STR_PARA(N, S, M, D, C) \
|
||
|
OPT(N) = parser.get<std::string>(#N);
|
||
|
STR_PARAS
|
||
|
#undef STR_PARA
|
||
|
|
||
|
#define PARA(N, T, S, M, D, L, H, C) \
|
||
|
if (!strcmp(#T, "int")) OPT(N) = parser.get<int>(#N); \
|
||
|
else OPT(N) = parser.get<double>(#N);
|
||
|
PARAS
|
||
|
#undef PARA
|
||
|
}
|