From 141d0117225ac4451b2789034e1083f9471173a7 Mon Sep 17 00:00:00 2001 From: Vasilii Rogin Date: Mon, 15 May 2023 18:54:37 +0300 Subject: [PATCH] Small update --- src/sfall_arrays.cc | 63 ++++++++++++++++++--------------------------- 1 file changed, 25 insertions(+), 38 deletions(-) diff --git a/src/sfall_arrays.cc b/src/sfall_arrays.cc index 8d5e5ce..a32859a 100644 --- a/src/sfall_arrays.cc +++ b/src/sfall_arrays.cc @@ -91,6 +91,29 @@ private: stringValue[sLen] = '\0'; } + void init_from_another(ArrayElement&& other) + { + // Maybe this can be done simpler way? + type = other.type; + switch (type) { + case ArrayElementType::INT: + integerValue = other.integerValue; + break; + case ArrayElementType::FLOAT: + floatValue = other.floatValue; + break; + case ArrayElementType::POINTER: + pointerValue = other.pointerValue; + break; + case ArrayElementType::STRING: + stringValue = other.stringValue; + other.stringValue = nullptr; + break; + default: + throw(std::exception()); + } + } + public: ArrayElement() : type(ArrayElementType::INT) @@ -102,47 +125,11 @@ public: ArrayElement& operator=(const ArrayElement& rhs) = delete; ArrayElement(ArrayElement&& other) { - // Maybe this can be done simpler way? - type = other.type; - switch (type) { - case ArrayElementType::INT: - integerValue = other.integerValue; - break; - case ArrayElementType::FLOAT: - floatValue = other.floatValue; - break; - case ArrayElementType::POINTER: - pointerValue = other.pointerValue; - break; - case ArrayElementType::STRING: - stringValue = other.stringValue; - other.stringValue = nullptr; - break; - default: - throw(std::exception()); - } + init_from_another(std::move(other)); }; ArrayElement& operator=(ArrayElement&& other) { - // Maybe this can be done simpler way? - type = other.type; - switch (type) { - case ArrayElementType::INT: - integerValue = other.integerValue; - break; - case ArrayElementType::FLOAT: - floatValue = other.floatValue; - break; - case ArrayElementType::POINTER: - pointerValue = other.pointerValue; - break; - case ArrayElementType::STRING: - stringValue = other.stringValue; - other.stringValue = nullptr; - break; - default: - throw(std::exception()); - } + init_from_another(std::move(other)); return *this; }