Skip to content

Commit

Permalink
Base: minor code change for PropertyValueConversion::Variant
Browse files Browse the repository at this point in the history
  • Loading branch information
HuguesDelorme committed Jan 9, 2025
1 parent f90bd83 commit 2fa4c2b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
13 changes: 6 additions & 7 deletions src/base/property_value_conversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,34 +91,33 @@ static gp_XYZ xyzFromString(std::string_view str)
} // namespace

PropertyValueConversion::Variant::Variant(bool v)
: BaseType(v)
: BaseVariantType(v)
{}

PropertyValueConversion::Variant::Variant(int v)
: BaseType(v)
: BaseVariantType(v)
{}

PropertyValueConversion::Variant::Variant(float v)
: Variant(static_cast<double>(v))
{}

PropertyValueConversion::Variant::Variant(double v)
: BaseType(v)
: BaseVariantType(v)
{}

PropertyValueConversion::Variant::Variant(const char* str)
: BaseType(std::string(str))
: BaseVariantType(std::string(str))
{}

PropertyValueConversion::Variant::Variant(const std::string& str)
: BaseType(str)
: BaseVariantType(str)
{}

PropertyValueConversion::Variant::Variant(Span<const uint8_t> bytes)
: BaseType(std::vector<uint8_t>(bytes.begin(), bytes.end()))
: BaseVariantType(std::vector<uint8_t>(bytes.begin(), bytes.end()))
{}


PropertyValueConversion::Variant PropertyValueConversion::toVariant(const Property& prop) const
{
auto fnError = [&](std::string_view text) {
Expand Down
2 changes: 1 addition & 1 deletion src/base/property_value_conversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ namespace Mayo {
// Mechanism to convert value of a Property object to/from a basic variant type
class PropertyValueConversion {
public:
// Alias of the std::variant<...> type used by custom PropertyValueConversion::Variant
using BaseVariantType = std::variant<
std::monostate, bool, int, double, std::string, std::vector<uint8_t>
>;
// Variant type to be used when (de)serializing values
class Variant : public BaseVariantType {
public:
using BaseType = BaseVariantType;
Variant() = default;
Variant(bool v);
Variant(int v);
Expand Down

0 comments on commit 2fa4c2b

Please sign in to comment.