cloud-sat/src/paras.cpp

62 lines
1.5 KiB
C++
Raw Normal View History

2022-08-30 15:42:35 +08:00
#include "paras.hpp"
#include <cstdio>
#include <iostream>
2023-03-20 21:40:19 +08:00
#include <string>
2022-08-30 15:42:35 +08:00
void paras::init_paras() {
2023-03-27 15:44:39 +08:00
#define PARA(N, T, S, M, D, L, H, C) \
2022-08-30 15:42:35 +08:00
if (!strcmp(#T, "int")) map_int[#N] = D; \
2023-03-20 21:40:19 +08:00
else map_double[#N] = D;
2022-08-30 15:42:35 +08:00
PARAS
#undef PARA
2023-03-20 21:40:19 +08:00
2023-03-27 15:44:39 +08:00
#define STR_PARA(N, S, M, D, C) \
2023-03-20 21:40:19 +08:00
map_string[#N] = D;
STR_PARAS
#undef STR_PARA
2022-08-30 15:42:35 +08:00
}
void paras::sync_paras() {
2023-03-27 15:44:39 +08:00
#define PARA(N, T, S, M, D, L, H, C) \
2022-08-30 15:42:35 +08:00
if (!strcmp(#T, "int")) N = map_int[#N]; \
2023-03-20 21:40:19 +08:00
else N = map_double[#N];
2022-08-30 15:42:35 +08:00
PARAS
#undef PARA
2023-03-27 15:44:39 +08:00
#define STR_PARA(N, S, M, D, C) \
2023-03-20 21:40:19 +08:00
N = map_string[#N];
STR_PARAS
#undef STR_PARAs
2022-08-30 15:42:35 +08:00
}
void paras::set_para(char *name, int val) {
map_int[name] = val;
}
void paras::set_para(char *name, double val) {
map_double[name] = val;
}
2023-03-20 21:40:19 +08:00
void paras::set_para(char *name, char* val) {
map_string[name] = val;
}
2022-08-30 15:42:35 +08:00
void paras::print_change() {
printf("c ------------------- Paras list -------------------\n");
printf("c %-20s\t %-10s\t %-10s\t %-10s\t %s\n",
"Name", "Type", "Now", "Default", "Comment");
2023-03-27 15:44:39 +08:00
#define PARA(N, T, S, M, D, L, H, C) \
2022-08-30 15:42:35 +08:00
if (map_int.count(#N)) printf("c %-20s\t %-10s\t %-10d\t %-10s\t %s\n", (#N), (#T), N, (#D), (C)); \
2023-03-20 21:40:19 +08:00
else printf("c %-20s\t %-10s\t %-10f\t %-10s\t %s\n", (#N), (#T), N, (#D), (C));
2022-08-30 15:42:35 +08:00
PARAS
#undef PARA
2023-03-27 15:44:39 +08:00
#define STR_PARA(N, S, M, D, C) \
2023-03-20 21:40:19 +08:00
printf("c %-20s\t string\t\t %-10s\t %-10s\t %s\n", (#N), N.c_str(), (#D), (C));
STR_PARAS
#undef STR_PARA
2022-08-30 15:42:35 +08:00
printf("c --------------------------------------------------\n");
}