Удалил UType::object_ptr и заменил его на комбинацию из std::shared_ptr и std::weak_ptr из-за ужасной реализации.

This commit is contained in:
2026-05-31 20:38:30 +07:00
parent fa3e987e93
commit 6389e6b25f
14 changed files with 67 additions and 311 deletions
+13 -13
View File
@@ -97,7 +97,7 @@ SaveMap::SaveMap(const std::string& json_data)
end = object_json.find('\"', begin);
std::string object_name = object_json.substr(begin, end - begin);
UType::object_ptr<ISave> object_ptr(MakeObjectByName(object_name));
std::shared_ptr<ISave> object_ptr(MakeObjectByName(object_name));
object_ptr->load(std::make_shared<SaveMap>(object_json));
save_objects[name.c_str() + 1] = object_ptr;
@@ -171,10 +171,10 @@ SaveMap::SaveMap(const std::string& json_data)
}
} else if (name[1] == 'o')
{
save_vector_objects[key] = std::vector<UType::object_ptr<ISave>>();
save_vector_objects[key] = std::vector<std::shared_ptr<ISave>>();
if (arr_data.length() == 2)
continue;
std::vector<UType::object_ptr<ISave>>& vector_object = save_vector_objects[key];
std::vector<std::shared_ptr<ISave>>& vector_object = save_vector_objects[key];
size_t j = 1;
while (j < arr_data.length())
@@ -198,7 +198,7 @@ SaveMap::SaveMap(const std::string& json_data)
size_t end_name = object_json.find('\"', begin_name);
std::string object_name = object_json.substr(begin_name, end_name - begin_name);
UType::object_ptr<ISave> object_ptr(MakeObjectByName(object_name));
std::shared_ptr<ISave> object_ptr(MakeObjectByName(object_name));
object_ptr->load(std::make_shared<SaveMap>(object_json));
vector_object.push_back(object_ptr);
@@ -272,10 +272,10 @@ SaveMap::SaveMap(const std::string& json_data)
}
} else if (name[1] == 'o')
{
save_list_objects[key] = std::list<UType::object_ptr<ISave>>();
save_list_objects[key] = std::list<std::shared_ptr<ISave>>();
if (arr_data.length() == 2)
continue;
std::list<UType::object_ptr<ISave>>& list_object = save_list_objects[key];
std::list<std::shared_ptr<ISave>>& list_object = save_list_objects[key];
size_t j = 1;
while (j < arr_data.length())
@@ -299,7 +299,7 @@ SaveMap::SaveMap(const std::string& json_data)
size_t end_name = object_json.find('\"', begin_name);
std::string object_name = object_json.substr(begin_name, end_name - begin_name);
UType::object_ptr<ISave> object_ptr(MakeObjectByName(object_name));
std::shared_ptr<ISave> object_ptr(MakeObjectByName(object_name));
object_ptr->load(std::make_shared<SaveMap>(object_json));
list_object.push_back(object_ptr);
@@ -389,7 +389,7 @@ std::shared_ptr<SaveMap> SaveMap::SaveString(const char* name, const std::string
return std::shared_ptr<SaveMap>(this);
}
std::shared_ptr<SaveMap> SaveMap::SaveObject(const char* name, UType::object_ptr<ISave> object) noexcept
std::shared_ptr<SaveMap> SaveMap::SaveObject(const char* name, std::shared_ptr<ISave> object) noexcept
{
save_objects[name] = object;
return std::shared_ptr<SaveMap>(this);
@@ -413,7 +413,7 @@ std::shared_ptr<SaveMap> SaveMap::SaveVectorStrings(const char* name, std::vecto
return std::shared_ptr<SaveMap>(this);
}
std::shared_ptr<SaveMap> SaveMap::SaveVectorObject(const char* name, std::vector<UType::object_ptr<ISave>>&& value) noexcept
std::shared_ptr<SaveMap> SaveMap::SaveVectorObject(const char* name, std::vector<std::shared_ptr<ISave>>&& value) noexcept
{
save_vector_objects[name] = std::move(value);
return std::shared_ptr<SaveMap>(this);
@@ -437,7 +437,7 @@ std::shared_ptr<SaveMap> SaveMap::SaveListStrings(const char* name, std::list<st
return std::shared_ptr<SaveMap>(this);
}
std::shared_ptr<SaveMap> SaveMap::SaveListObject(const char* name, std::list<UType::object_ptr<ISave>>&& value) noexcept
std::shared_ptr<SaveMap> SaveMap::SaveListObject(const char* name, std::list<std::shared_ptr<ISave>>&& value) noexcept
{
save_list_objects[name] = std::move(value);
return std::shared_ptr<SaveMap>(this);
@@ -458,7 +458,7 @@ std::string SaveMap::GetString(const char* name)
return save_string[name];
}
UType::object_ptr<ISave> SaveMap::GetObject(const char* name)
std::shared_ptr<ISave> SaveMap::GetObject(const char* name)
{
return save_objects[name];
}
@@ -478,7 +478,7 @@ std::vector<std::string> SaveMap::GetVectorString(const char* name)
return save_vector_strings[name];
}
std::vector<UType::object_ptr<ISave>>& SaveMap::GetVectorObject(const char* name)
std::vector<std::shared_ptr<ISave>>& SaveMap::GetVectorObject(const char* name)
{
return save_vector_objects[name];
}
@@ -498,7 +498,7 @@ std::list<std::string>& SaveMap::GetListString(const char* name)
return save_list_strings[name];
}
std::list<UType::object_ptr<ISave>>& SaveMap::GetListObject(const char* name)
std::list<std::shared_ptr<ISave>>& SaveMap::GetListObject(const char* name)
{
return save_list_objects[name];
}
+9 -10
View File
@@ -1,7 +1,6 @@
#pragma once
#include "ISave.h"
#include "Types/object_ptr.hpp"
#include <unordered_map>
#include <memory>
@@ -18,18 +17,18 @@ class SaveMap final
std::unordered_map<std::string, long long> save_long;
std::unordered_map<std::string, double> save_double;
std::unordered_map<std::string, std::string> save_string;
std::unordered_map<std::string, UType::object_ptr<ISave>> save_objects;
std::unordered_map<std::string, std::shared_ptr<ISave>> save_objects;
// Массивы
std::unordered_map<std::string, std::vector<long long>> save_vector_integer;
std::unordered_map<std::string, std::vector<double>> save_vector_double;
std::unordered_map<std::string, std::vector<UType::object_ptr<ISave>>> save_vector_objects;
std::unordered_map<std::string, std::vector<std::shared_ptr<ISave>>> save_vector_objects;
std::unordered_map<std::string, std::vector<std::string>> save_vector_strings;
// Связаные списки
std::unordered_map<std::string, std::list<long long>> save_list_integer;
std::unordered_map<std::string, std::list<double>> save_list_double;
std::unordered_map<std::string, std::list<UType::object_ptr<ISave>>> save_list_objects;
std::unordered_map<std::string, std::list<std::shared_ptr<ISave>>> save_list_objects;
std::unordered_map<std::string, std::list<std::string>> save_list_strings;
static ISave* MakeObjectByName(const std::string& name);
@@ -48,29 +47,29 @@ public:
std::shared_ptr<SaveMap> SaveInteger(const char* name, int value) noexcept;
std::shared_ptr<SaveMap> SaveDouble(const char* name, double value) noexcept;
std::shared_ptr<SaveMap> SaveString(const char* name, const std::string& value) noexcept;
std::shared_ptr<SaveMap> SaveObject(const char* name, UType::object_ptr<ISave> object) noexcept;
std::shared_ptr<SaveMap> SaveObject(const char* name, std::shared_ptr<ISave> object) noexcept;
std::shared_ptr<SaveMap> SaveVectorInteger(const char* name, std::vector<long long>&& value) noexcept;
std::shared_ptr<SaveMap> SaveVectorDouble(const char* name, std::vector<double>&& value) noexcept;
std::shared_ptr<SaveMap> SaveVectorStrings(const char* name, std::vector<std::string>&& value) noexcept;
std::shared_ptr<SaveMap> SaveVectorObject(const char* name, std::vector<UType::object_ptr<ISave>>&& value) noexcept;
std::shared_ptr<SaveMap> SaveVectorObject(const char* name, std::vector<std::shared_ptr<ISave>>&& value) noexcept;
std::shared_ptr<SaveMap> SaveListInteger(const char* name, std::list<long long>&& value) noexcept;
std::shared_ptr<SaveMap> SaveListDouble(const char* name, std::list<double>&& value) noexcept;
std::shared_ptr<SaveMap> SaveListStrings(const char* name, std::list<std::string>&& value) noexcept;
std::shared_ptr<SaveMap> SaveListObject(const char* name, std::list<UType::object_ptr<ISave>>&& value) noexcept;
std::shared_ptr<SaveMap> SaveListObject(const char* name, std::list<std::shared_ptr<ISave>>&& value) noexcept;
// Методы получения значенй
long long GetInteger(const char* name);
double GetDouble(const char* name);
std::string GetString(const char* name);
UType::object_ptr<ISave> GetObject(const char* name);
std::shared_ptr<ISave> GetObject(const char* name);
std::vector<long long>& GetVectorInteger(const char* name);
std::vector<double>& GetVectorDouble(const char* name);
std::vector<std::string> GetVectorString(const char* name);
std::vector<UType::object_ptr<ISave>>& GetVectorObject(const char* name);
std::vector<std::shared_ptr<ISave>>& GetVectorObject(const char* name);
std::list<long long>& GetListInteger(const char* name);
std::list<double>& GetListDouble(const char* name);
std::list<std::string>& GetListString(const char* name);
std::list<UType::object_ptr<ISave>>& GetListObject(const char* name);
std::list<std::shared_ptr<ISave>>& GetListObject(const char* name);
std::shared_ptr<SaveMap> getParent() const { return parent_; }
const std::string& getClassName() const { return class_name; }