From b1775686128c5a15f5e53810445b54ae0987ebe4 Mon Sep 17 00:00:00 2001 From: YuhangQ Date: Mon, 27 Mar 2023 16:10:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=BB=A3=E7=A0=81=E5=88=B0?= =?UTF-8?q?=20home-server?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-light-master/master.cpp | 10 +++---- src-light-master/paras.cpp | 56 +++++++++++++++++++++++++++++++++++++ src-light-master/paras.hpp | 36 ++++++++++++++++++++++++ src-light-solver/light.cpp | 2 +- src-light-solver/paras.cpp | 2 -- 5 files changed, 97 insertions(+), 9 deletions(-) create mode 100644 src-light-master/paras.cpp create mode 100644 src-light-master/paras.hpp diff --git a/src-light-master/master.cpp b/src-light-master/master.cpp index 300ae74..8c8b442 100644 --- a/src-light-master/master.cpp +++ b/src-light-master/master.cpp @@ -1,14 +1,12 @@ #include #include "master.h" +#include "paras.hpp" -int main() { - printf("=====================================\n"); - - - - +int main(int argc, char* argv[]) { + paras::parse(argc, argv); + opt->print_paras(); return 0; } \ No newline at end of file diff --git a/src-light-master/paras.cpp b/src-light-master/paras.cpp new file mode 100644 index 0000000..1ef5680 --- /dev/null +++ b/src-light-master/paras.cpp @@ -0,0 +1,56 @@ +#include +#include +#include + +#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(#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(#N, S, C, M, D, cmdline::range((int)L, (int)H)); \ + else parser.add(#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(#N); + STR_PARAS + #undef STR_PARA + + #define PARA(N, T, S, M, D, L, H, C) \ + if (!strcmp(#T, "int")) OPT(N) = parser.get(#N); \ + else OPT(N) = parser.get(#N); + PARAS + #undef PARA +} \ No newline at end of file diff --git a/src-light-master/paras.hpp b/src-light-master/paras.hpp new file mode 100644 index 0000000..718776b --- /dev/null +++ b/src-light-master/paras.hpp @@ -0,0 +1,36 @@ +#ifndef _paras_hpp_INCLUDED +#define _paras_hpp_INCLUDED + +#include +#include + +// name, type, short-name,must-need, default ,low, high, comments +#define PARAS \ + PARA( simplify , int , 's' , false , 1 , 0 , 1 , "Use Simplify (only preprocess)") \ + PARA( port , int , 'p' , false , 2389 , 0 , 1 , "Master Server Listerning Port") \ + +// name, short-name, must-need, default, comments +#define STR_PARAS \ + STR_PARA( instance , 'i' , true , "" , "CNF format instance") \ + STR_PARA( solvers , '\0' , true , "" , "A Solver List of \"ip:port\" Format, Seperate by ,") + +struct paras +{ +#define PARA(N, T, S, M, D, L, H, C) \ + T N = D; + PARAS +#undef PARA + +#define STR_PARA(N, S, M, D, C) \ + std::string N = D; + STR_PARAS +#undef STR_PARA + static void parse(int argc, char* argv[]); + void print_paras (); +}; + +extern paras* opt; + +#define OPT(N) (opt->N) + +#endif \ No newline at end of file diff --git a/src-light-solver/light.cpp b/src-light-solver/light.cpp index 41619b9..c4113f5 100644 --- a/src-light-solver/light.cpp +++ b/src-light-solver/light.cpp @@ -95,7 +95,7 @@ void light::arg_parse(int argc, char **argv) { printf("------------ arguments ------------\n"); #define STR_PARA(N, S, M, D, C) \ - printf("%-20s: %s\n", #N, OPT(N)); + printf("%-20s: %s\n", #N, OPT(N).c_str()); STR_PARAS #undef STR_PARA diff --git a/src-light-solver/paras.cpp b/src-light-solver/paras.cpp index 2b71c0e..51c6c99 100644 --- a/src-light-solver/paras.cpp +++ b/src-light-solver/paras.cpp @@ -58,7 +58,5 @@ void paras::print_change() { STR_PARAS #undef STR_PARA - - printf("c --------------------------------------------------\n"); } \ No newline at end of file