Move to object_ptr

This commit is contained in:
Jiga228
2025-10-17 21:39:30 +07:00
parent 136235749a
commit 137522cefa
8 changed files with 58 additions and 48 deletions
+6 -6
View File
@@ -17,7 +17,7 @@ public:
}
void load(std::shared_ptr<SaveMap> save) override
{
num = save->GetInteger("num");
num = static_cast<int>(save->GetInteger("num"));
str = save->GetString("str");
dbl = save->GetDouble("dbl");
}
@@ -158,14 +158,14 @@ TEST(SaveMapTest, check_load_with_custom_type)
EXPECT_EQ(test_vector_string[i], save_map.GetVectorString("TestVectorString")[i]);
}
CustomObject* obj = reinterpret_cast<CustomObject*>(save_map.GetObject("CustomObject"));
UType::object_ptr<CustomObject> obj = static_cast<UType::object_ptr<CustomObject>>(save_map.GetObject("CustomObject"));
CustomObject test_obj;
test_obj.num = 123;
test_obj.str = "str123";
test_obj.dbl = 123.45;
EXPECT_EQ(*obj, test_obj);
EXPECT_EQ(*obj.get(), test_obj);
std::vector<CustomObject*> vec_obj = reinterpret_cast<std::vector<CustomObject*>&>(save_map.GetVectorObject("CustomObjects"));
std::vector<UType::object_ptr<CustomObject>> vec_obj = reinterpret_cast<std::vector<UType::object_ptr<CustomObject>>&>(save_map.GetVectorObject("CustomObjects"));
std::vector<CustomObject*> vec_obj_test = {
new CustomObject,
new CustomObject,
@@ -178,8 +178,8 @@ TEST(SaveMapTest, check_load_with_custom_type)
vec_obj_test[1]->dbl = 543.21;
for (auto i = 0; i < 2; i++)
{
EXPECT_EQ(*vec_obj[i], *vec_obj_test[i]);
delete vec_obj[i];
EXPECT_EQ(*vec_obj[i].get(), *vec_obj_test[i]);
vec_obj[i].destroy();
delete vec_obj_test[i];
}
}