-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOptions.h
78 lines (66 loc) · 2.64 KB
/
Options.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#ifndef OPTIONS_H
#define OPTIONS_H
#include <map>
#include <string>
#include <iostream>
#include <getopt.h>
#include <thread>
#include <err.h>
#include <stdlib.h>
#include "checkpoint.h"
#include "utils.h"
#include "measure.h"
#include <boost/program_options.hpp>
namespace po = boost::program_options;
// All options are stored as strings. The only problem this causes is for
// ncores and restart. Hopefully, consistency is worth the minor problem.
struct Option {
std::string name;
char shortflag;
char type; // currently unused, for future type checking
std::string description;
bool mandatory; // means the option must have a value.
bool has_argument;
std::string value;
std::string (*checksanity)(const std::string);
};
class Options {
const static unsigned int nopts = 9;
struct Option option_defs[nopts] {
{ "restart", 'r', 'b', "restart from checkpoint; optional; default: not restarting from checkpoint",
false, false, "", nullptr },
{ "fasta", 'f', 's', "fasta file containing sequences; required", true,
true, "", nullptr },
{ "measure", 'm', 's', "distance measure to use; required", true, true,
"", nullptr },
{ "submeasure", 's', 's', "submeasure to use; optional; depends on the distance measure",
false, true, "", nullptr },
{ "measureopt", 'o', 's', "options for the distance measure; depends on the measure",
false, true, "", nullptr },
{ "distmatfname", 'd', 's', "distance matrix file name; required", true,
true, "", nullptr },
{ "ncores", 'n', 'i', "number of CPU cores to use; optional; default: all",
false, true, "", nullptr },
{ "checkpointdir", 'c', 's', "checkpoint directory to use; default value exists",
false, true, "", nullptr },
{ "printresult", 'p', 's', "print the resulting distance matrix. Default: false",
false, true, "false", nullptr },
};
std::string checkpointfname = "options.checkpoint";
unsigned int findoption(std::string name) const;
public:
Options(int argc, char **argv);
void set(const char *key, const char *value) {
set(std::string(key), std::string(value));
};
void set(const std::string key, const std::string value);
std::string get(const char *key) const {return get(std::string(key));};
std::string get(const std::string key) const { return option_defs[findoption(key)].value; };
unsigned int get_ncores() const { return std::stoi(get("ncores")); }; //### need to get value from option_defs
bool get_restart() const { return option_defs[findoption("restart")].value.compare("true") == 0; };
void checkpoint(void);
void cleancheckpointdir(void);
void restore(void);
void print(void);
};
#endif // OPTIONS_H