Skip to content

Commit

Permalink
add << and >> operator for SM command line parsing.
Browse files Browse the repository at this point in the history
cxxopts use >> to parse opts.

Signed-off-by: Xiaoxi Chen <[email protected]>
  • Loading branch information
xiaoxichen committed Apr 19, 2024
1 parent 8436d39 commit 6910d0f
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/include/homeobject/homeobject.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,34 @@ ENUM(DevType, uint8_t, AUTO_DETECT = 1, HDD, NVME, UNSUPPORTED);
struct device_info_t {
explicit device_info_t(std::string name, DevType dtype = DevType::AUTO_DETECT) : path{std::filesystem::canonical(name)}, type{dtype} {}
bool operator ==(device_info_t const& rhs) const { return path == rhs.path && type == rhs.type; }
friend istream &operator>>( istream &input, device_info_t &di ) {
string t_input;
input >> di.path >> t_input;
if (t_input == "HDD") {
di.type = DevType::HDD;
} else if (t_input == "NVME") {
di.type = t_input::NVME;
} else {
di.type = DevType::AUTO_DETECT;
}
return input;
}
ostream& operator<<(ostream& os, const device_info_t& di)
{
os << "Device: {Path: " << di.path << ", Type: ";
switch (di.type) {
case DevType::HDD:
os << "HDD";
break;
case DevType::NVME:
os << "NVME";
break;
default:
os << "AUTO_DETECT";
break;
}
return os;
}
std::filesystem::path path;
DevType type;
};
Expand Down

0 comments on commit 6910d0f

Please sign in to comment.