| 1 |
#include <pbcopper/cli2/Result.h> |
| 2 |
|
| 3 |
#include <ostream> |
| 4 |
#include <type_traits> |
| 5 |
|
| 6 |
namespace PacBio { |
| 7 |
namespace CLI_v2 { |
| 8 |
|
| 9 |
Result::Result(OptionValue data, SetByMode setBy) : data_{std::move(data)}, setBy_{setBy} {} |
| 10 |
|
| 11 |
bool Result::IsUserProvided() const { return setBy_ == SetByMode::USER; } |
| 12 |
|
| 13 |
bool Result::IsDefault() const { return setBy_ == SetByMode::DEFAULT; } |
| 14 |
|
| 15 |
SetByMode Result::SetBy() const { return setBy_; } |
| 16 |
|
| 17 |
Result& Result::SetBy(SetByMode setBy) |
| 18 |
{ |
| 19 |
setBy_ = setBy; |
| 20 |
return *this; |
| 21 |
} |
| 22 |
|
| 23 |
Result::operator float() const |
| 24 |
{ |
| 25 |
const auto x = OptionValueToDouble(data_); |
| 26 |
return static_cast<float>(x); |
| 27 |
} |
| 28 |
|
| 29 |
Result::operator double() const { return OptionValueToDouble(data_); } |
| 30 |
|
| 31 |
Result::operator bool() const { return OptionValueToBool(data_); } |
| 32 |
|
| 33 |
Result::operator std::string() const { return OptionValueToString(data_); } |
| 34 |
|
| 35 |
Result::operator int8_t() const |
| 36 |
{ |
| 37 |
const auto x = OptionValueToInt(data_); |
| 38 |
return static_cast<int8_t>(x); |
| 39 |
} |
| 40 |
|
| 41 |
Result::operator uint8_t() const |
| 42 |
{ |
| 43 |
const auto x = OptionValueToUInt(data_); |
| 44 |
return static_cast<uint8_t>(x); |
| 45 |
} |
| 46 |
|
| 47 |
Result::operator int16_t() const |
| 48 |
{ |
| 49 |
const auto x = OptionValueToInt(data_); |
| 50 |
return static_cast<int16_t>(x); |
| 51 |
} |
| 52 |
|
| 53 |
Result::operator uint16_t() const |
| 54 |
{ |
| 55 |
const auto x = OptionValueToUInt(data_); |
| 56 |
return static_cast<uint16_t>(x); |
| 57 |
} |
| 58 |
|
| 59 |
Result::operator int32_t() const |
| 60 |
{ |
| 61 |
const auto x = OptionValueToInt(data_); |
| 62 |
return static_cast<int32_t>(x); |
| 63 |
} |
| 64 |
|
| 65 |
Result::operator uint32_t() const |
| 66 |
{ |
| 67 |
const auto x = OptionValueToUInt(data_); |
| 68 |
return static_cast<uint32_t>(x); |
| 69 |
} |
| 70 |
|
| 71 |
Result::operator int64_t() const |
| 72 |
{ |
| 73 |
const auto x = OptionValueToInt(data_); |
| 74 |
return static_cast<int64_t>(x); |
| 75 |
} |
| 76 |
|
| 77 |
Result::operator uint64_t() const |
| 78 |
{ |
| 79 |
const auto x = OptionValueToUInt(data_); |
| 80 |
return static_cast<uint64_t>(x); |
| 81 |
} |
| 82 |
|
| 83 |
size_t Result::which() const { return data_.index(); } |
| 84 |
|
| 85 |
const OptionValue& Result::RawValue() const { return data_; } |
| 86 |
|
| 87 |
std::ostream& operator<<(std::ostream& out, const Result& result) |
| 88 |
{ |
| 89 |
out << result.RawValue(); |
| 90 |
return out; |
| 91 |
} |
| 92 |
|
| 93 |
} // namespace CLI_v2 |
| 94 |
} // namespace PacBio |