同步代码到 home-server
This commit is contained in:
parent
7320c729b0
commit
b177568612
@ -1,14 +1,12 @@
|
||||
#include <string>
|
||||
|
||||
#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;
|
||||
}
|
56
src-light-master/paras.cpp
Normal file
56
src-light-master/paras.cpp
Normal file
@ -0,0 +1,56 @@
|
||||
#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
|
||||
}
|
36
src-light-master/paras.hpp
Normal file
36
src-light-master/paras.hpp
Normal file
@ -0,0 +1,36 @@
|
||||
#ifndef _paras_hpp_INCLUDED
|
||||
#define _paras_hpp_INCLUDED
|
||||
|
||||
#include <cstring>
|
||||
#include <unordered_map>
|
||||
|
||||
// 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
|
@ -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
|
||||
|
||||
|
@ -58,7 +58,5 @@ void paras::print_change() {
|
||||
STR_PARAS
|
||||
#undef STR_PARA
|
||||
|
||||
|
||||
|
||||
printf("c --------------------------------------------------\n");
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user