From e75652afc3ea26760f35fbe1bf462ab714dd4c25 Mon Sep 17 00:00:00 2001 From: ProgramSnail Date: Thu, 18 May 2023 20:10:50 +0300 Subject: [PATCH] values comparation (equality, using Same function) --- src/values.cpp | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/values.cpp b/src/values.cpp index af8b4cb..f099d71 100644 --- a/src/values.cpp +++ b/src/values.cpp @@ -4,7 +4,30 @@ namespace info::value { bool InternalValue::Same(const InternalValue& other_value) const { + size_t this_index = value.index(); + size_t other_index = other_value.value.index(); + if (this_index == other_index) { + switch (this_index) { + case 0: + return std::get(value) == std::get(other_value.value); + case 1: + return std::get(value) == std::get(other_value.value); + case 2: + return std::get(value) == std::get(other_value.value); + case 3: + return std::get(value) == std::get(other_value.value); + case 4: + return std::get(value) == std::get(other_value.value); + case 5: // Unit + return true; + default: + // error + break; + } + } + + return false; } std::optional InternalValue::GetFieldValue(const std::string& name) const { @@ -14,12 +37,12 @@ std::optional InternalValue::GetFieldValue(const std::string& nam // bool TupleValue::Same(const TupleValue& other_value) const { - // TODO: check, that type is same + // TODO: check, that type is same ?? (checked in typecheck ??) if (fields.size() != other_value.fields.size()) { return false; } - for (size_t i = 0; i < fields.size(); ++i) { - if (!) { + for (size_t i = 0; i < fields.size(); ++i) { // compare field names ?? (checked in typecheck ??) + if (!value_manager_->GetAnyValue(fields[i].second)->Same(*value_manager_->GetAnyValue(other_value.fields[i].second))) { return false; } } @@ -38,7 +61,7 @@ std::optional TupleValue::GetFieldValue(const std::string& name) // bool VariantValue::Same(const VariantValue& other_value) const { - // TODO: check, that type is same + // TODO: check, that type is same ?? (checked in typecheck ??) }