forked from LostPointer/KeyValueTutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharg.cpp
More file actions
39 lines (32 loc) · 826 Bytes
/
Copy patharg.cpp
File metadata and controls
39 lines (32 loc) · 826 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
34
35
36
37
38
39
#include "arg.hpp"
#include <iostream>
#include "command.hpp"
Arg::Arg(const std::string& arg) : arg_(arg) {}
Value Arg::Get(std::map<std::string, Value>& storage) const {
if (IsCommand()) {
auto command = command::MakeCommand(arg_);
return command->Execute(storage);
} else {
return arg_;
}
}
int Arg::ToInt() const {
try {
if (arg_.find(".") != std::string::npos)
throw BadConvert("Can't convert to double");
return std::stoi(arg_);
} catch (const std::exception&) {
throw BadConvert("Can't convert to int");
}
}
double Arg::ToDouble() const {
try {
return std::stod(arg_);
} catch (const std::exception&) {
throw BadConvert("Can't convert to double");
}
}
bool Arg::IsCommand() const {
if (arg_.find(" ") != std::string::npos) return true;
return false;
}