[ox/model] Fix move constructors and operators in ModelValue system

This commit is contained in:
Gary Talent 2022-07-19 20:59:08 -05:00
parent e71866b1a2
commit 6ddeb29c92

View File

@ -345,11 +345,9 @@ class ModelObject {
} }
constexpr ModelObject(ModelObject &&other) noexcept { constexpr ModelObject(ModelObject &&other) noexcept {
for (auto &f : other.m_fieldsOrder) { m_fields = std::move(other.m_fields);
auto &field = m_fieldsOrder.emplace_back(std::move(f)); m_fieldsOrder = std::move(other.m_fieldsOrder);
m_fields[field->name] = &field->value; m_typeName = std::move(other.m_typeName);
}
m_typeName = other.m_typeName;
m_typeVersion = other.m_typeVersion; m_typeVersion = other.m_typeVersion;
} }
@ -430,11 +428,9 @@ class ModelObject {
if (&other == this) [[unlikely]] { if (&other == this) [[unlikely]] {
return *this; return *this;
} }
for (auto &f : other.m_fieldsOrder) { m_fields = std::move(other.m_fields);
auto &field = m_fieldsOrder.emplace_back(std::move(f)); m_fieldsOrder = std::move(other.m_fieldsOrder);
m_fields[field->name] = &field->value; m_typeName = std::move(other.m_typeName);
}
m_typeName = other.m_typeName;
m_typeVersion = other.m_typeVersion; m_typeVersion = other.m_typeVersion;
return *this; return *this;
} }
@ -509,6 +505,14 @@ class ModelUnion {
m_unionIdx = other.m_unionIdx; m_unionIdx = other.m_unionIdx;
} }
constexpr ModelUnion(ModelUnion &&other) noexcept {
m_fieldsOrder = std::move(other.m_fieldsOrder);
m_fields = std::move(other.m_fields);
m_typeName = std::move(other.m_typeName);
m_typeVersion = other.m_typeVersion;
m_unionIdx = other.m_unionIdx;
}
static constexpr Result<UniquePtr<ModelUnion>> make(const DescriptorType *type) noexcept { static constexpr Result<UniquePtr<ModelUnion>> make(const DescriptorType *type) noexcept {
UniquePtr<ModelUnion> out(new ModelUnion); UniquePtr<ModelUnion> out(new ModelUnion);
oxReturnError(out->setType(type)); oxReturnError(out->setType(type));
@ -674,13 +678,16 @@ constexpr ModelValue::ModelValue(ModelValue &&other) noexcept {
other.m_data.str = new String; other.m_data.str = new String;
break; break;
case Type::Union: case Type::Union:
m_data.uni = new ModelUnion(*other.m_data.uni); m_data.uni = other.m_data.uni;
other.m_data.uni = new ModelUnion;
break; break;
case Type::Object: case Type::Object:
m_data.obj = new ModelObject(*other.m_data.obj); m_data.obj = other.m_data.obj;
other.m_data.obj = new ModelObject;
break; break;
case Type::Vector: case Type::Vector:
m_data.vec = new ModelValueVector(*other.m_data.vec); m_data.vec = other.m_data.vec;
other.m_data.vec = new ModelValueVector;
break; break;
} }
} }
@ -839,13 +846,16 @@ constexpr ModelValue &ModelValue::operator=(ModelValue &&other) noexcept {
other.m_data.str = new String; other.m_data.str = new String;
break; break;
case Type::Object: case Type::Object:
m_data.obj = new ModelObject(*other.m_data.obj); m_data.obj = other.m_data.obj;
other.m_data.obj = new ModelObject;
break; break;
case Type::Union: case Type::Union:
m_data.uni = new ModelUnion(*other.m_data.uni); m_data.uni = other.m_data.uni;
other.m_data.uni = new ModelUnion;
break; break;
case Type::Vector: case Type::Vector:
m_data.vec = new ModelValueVector(*other.m_data.vec); m_data.vec = other.m_data.vec;
other.m_data.vec = new ModelValueVector;
break; break;
} }
return *this; return *this;
@ -890,9 +900,7 @@ constexpr ModelValueVector::ModelValueVector(const ModelValueVector &other) noex
} }
constexpr ModelValueVector::ModelValueVector(ModelValueVector &&other) noexcept { constexpr ModelValueVector::ModelValueVector(ModelValueVector &&other) noexcept {
for (auto &v : other.m_vec) { m_vec = std::move(other.m_vec);
m_vec.emplace_back(std::move(v));
}
m_templateValue = std::move(other.m_templateValue); m_templateValue = std::move(other.m_templateValue);
m_typeName = std::move(other.m_typeName); m_typeName = std::move(other.m_typeName);
m_typeVersion = other.m_typeVersion; m_typeVersion = other.m_typeVersion;
@ -915,9 +923,7 @@ constexpr ModelValueVector &ModelValueVector::operator=(ModelValueVector &&other
if (this == &other) { if (this == &other) {
return *this; return *this;
} }
for (auto &v : other.m_vec) { m_vec = std::move(other.m_vec);
m_vec.emplace_back(std::move(v));
}
m_templateValue = std::move(other.m_templateValue); m_templateValue = std::move(other.m_templateValue);
m_typeName = std::move(other.m_typeName); m_typeName = std::move(other.m_typeName);
m_typeVersion = other.m_typeVersion; m_typeVersion = other.m_typeVersion;