Small update

This commit is contained in:
Vasilii Rogin 2023-05-15 18:54:37 +03:00
parent cf01118e93
commit 141d011722
1 changed files with 25 additions and 38 deletions

View File

@ -91,6 +91,29 @@ private:
stringValue[sLen] = '\0'; 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: public:
ArrayElement() ArrayElement()
: type(ArrayElementType::INT) : type(ArrayElementType::INT)
@ -102,47 +125,11 @@ public:
ArrayElement& operator=(const ArrayElement& rhs) = delete; ArrayElement& operator=(const ArrayElement& rhs) = delete;
ArrayElement(ArrayElement&& other) ArrayElement(ArrayElement&& other)
{ {
// Maybe this can be done simpler way? init_from_another(std::move(other));
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());
}
}; };
ArrayElement& operator=(ArrayElement&& other) ArrayElement& operator=(ArrayElement&& other)
{ {
// Maybe this can be done simpler way? init_from_another(std::move(other));
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());
}
return *this; return *this;
} }