-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.h
More file actions
137 lines (115 loc) · 5.61 KB
/
Copy pathoptions.h
File metadata and controls
137 lines (115 loc) · 5.61 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include "strategy.h"
#include "client.h"
class Options {
public:
explicit Options(int argc, char* argv[]) {
if (argc < 3) {
std::cerr << GetUsageMessage(std::string(argv[0]));
exit(0);
}
std::string port = "-1";
std::string str = "0";
std::string mov_str;
std::string count;
std::string confidence = "1";
int cur_param = 1;
while (cur_param < argc) {
std::string cur_param_name = std::string(argv[cur_param]);
if (cur_param_name == PORT_PARAM_NAME) {
port = argv[cur_param + 1];
cur_param += 2;
} else if (cur_param_name == GLOBAL_STR_PARAM_NAME) {
str = argv[cur_param + 1];
cur_param += 2;
} else if (cur_param_name == MOVEMENT_STR_PARAM_NAME) {
mov_str = argv[cur_param + 1];
cur_param += 2;
} else if (cur_param_name == COINS_COUNT_PARAM_NAME) {
count = argv[cur_param + 1];
cur_param += 2;
} else if (cur_param_name == STRATEGY_CONFIDENCE) {
confidence = argv[cur_param + 1];
cur_param += 2;
} else if (cur_param_name == HELP_MESSAGE_NAME) {
std::cerr << GetHelpMessage(argv[0]) << "\n";
exit(0);
} else {
std::cerr << GetUnknownParameterMessage(argv[0], argv[cur_param]) << "\n";
std::cerr << GetHelpMessage(argv[0]) << "\n";
exit(0);
}
}
port_ = std::atoi(port.c_str());
if (str == NEAREST_COIN_STR) {
// globalStrategy_ = std::make_shared<GlobalStrategy>(new NearestCoinStrategy(1));
globalStrategy_.reset(new NearestCoinStrategy(std::atoi(confidence.c_str())));
} else if (str == K_NEAREST_COIN_STR) {
// globalStrategy_ = std::make_shared<GlobalStrategy>(new KNearestCoinsStrategy(1, std::atoi(count.c_str())));
globalStrategy_.reset(new KNearestCoinsStrategy(std::atoi(confidence.c_str()), std::atoi(count.c_str())));
} else {
std::cerr << GetWrongParameterMessage(argv[0], GLOBAL_STR_PARAM_NAME);
exit(0);
}
if (mov_str == MOVE_STR_FIRST) {
//movementStrategy_ = std::make_shared<MovementStrategy>(new FirstMovementStrategyImpl());
movementStrategy_.reset(new FirstMovementStrategyImpl());
} else if (mov_str == MOVE_STR_SECOND) {
// movementStrategy_ = std::make_shared<MovementStrategy>(new SecondMovementStrategyImpl());
movementStrategy_.reset(new SecondMovementStrategyImpl());
} else if (mov_str == MOVE_STR_RANDOM) {
// movementStrategy_ = std::make_shared<MovementStrategy>(new RandomMovementStrategyImpl());
movementStrategy_.reset(new RandomMovementStrategyImpl());
} else {
std::cerr << GetWrongParameterMessage(argv[0], MOVEMENT_STR_PARAM_NAME);
exit(0);
}
}
int GetPort() const {
return port_;
}
std::shared_ptr<GlobalStrategy> GetGlobalStrategy() {
return globalStrategy_;
}
std::shared_ptr<MovementStrategy> GetMovementStrategy() {
return movementStrategy_;
}
private:
const std::string PORT_PARAM_NAME = "--port";
const std::string GLOBAL_STR_PARAM_NAME = "--global-strategy";
const std::string MOVEMENT_STR_PARAM_NAME = "--movement-strategy";
const std::string COINS_COUNT_PARAM_NAME = "--coins-count";
const std::string STRATEGY_CONFIDENCE = "--global-update-time";
const std::string HELP_MESSAGE_NAME = "--help";
const std::string NEAREST_COIN_STR = "nearest-coins-strategy";
const std::string K_NEAREST_COIN_STR = "k-nearest-coins-strategy";
const std::string MOVE_STR_FIRST = "first";
const std::string MOVE_STR_SECOND = "second";
const std::string MOVE_STR_RANDOM = "random";
std::string GetUnknownParameterMessage(const std::string& app_name, const std::string& par_name) {
std::string message = app_name + ": unknown option " + par_name;
return message;
}
std::string GetWrongParameterMessage(const std::string& app_name, const std::string& par_name) {
std::string message = app_name + ": unknown argument for " + par_name;
return message;
}
std::string GetUsageMessage(const std::string& app_name) {
std::string message = "Try \'" + app_name + " " + HELP_MESSAGE_NAME + "\' for more information";
return message;
}
std::string GetHelpMessage(const std::string& app_name) {
std::string help_message = "Usage: " + app_name + " " +
PORT_PARAM_NAME + " PORT " +
GLOBAL_STR_PARAM_NAME + " STRATEGY " +
MOVEMENT_STR_PARAM_NAME + " MOVEMENT-STRATEGY " +
COINS_COUNT_PARAM_NAME + " COUNT" + "\n" +
STRATEGY_CONFIDENCE + " COUNT" + "\n" +
" " + GLOBAL_STR_PARAM_NAME + " nearest-coins-strategy, k-nearest-coin-strategy" + "\n" +
" " + COINS_COUNT_PARAM_NAME + " parameter for k-nearest coin strategy" + "\n" +
" " + MOVEMENT_STR_PARAM_NAME + " first, second or random";
return help_message;
}
int port_;
std::shared_ptr<GlobalStrategy> globalStrategy_;
std::shared_ptr<MovementStrategy> movementStrategy_;
};