forked from LostPointer/KeyValueTutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsum_command.cpp
More file actions
33 lines (27 loc) · 721 Bytes
/
Copy pathsum_command.cpp
File metadata and controls
33 lines (27 loc) · 721 Bytes
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
#include "sum_command.hpp"
namespace command {
SumCommand::SumCommand(const std::vector<Arg>& args) : BaseCommand(args) {}
Value SumCommand::Execute(std::map<std::string, Value>& storage) {
try {
int int_result = 0;
for (const auto& arg : args_) {
int_result += arg.ToInt();
}
return std::to_string(int_result);
} catch (const BadConvert&) {
}
try {
double double_result = 0;
for (const auto& arg : args_) {
double_result += arg.ToDouble();
}
return std::to_string(double_result);
} catch (const BadConvert&) {
}
std::string result;
for (const auto& arg : args_) {
result += arg.Get(storage).ToString();
}
return result;
}
} // namespace command