Skip to content

Commit

Permalink
shared pointers for Get/SetArchives
Browse files Browse the repository at this point in the history
  • Loading branch information
briaguya-ai committed Dec 14, 2024
1 parent 8280f41 commit d73dbff
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
21 changes: 16 additions & 5 deletions src/resource/archive/ArchiveManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void ArchiveManager::Init(const std::vector<std::string>& archivePaths,

ArchiveManager::~ArchiveManager() {
SPDLOG_TRACE("destruct archive manager");
SetArchives({});
SetArchives(nullptr);
}

bool ArchiveManager::IsLoaded() {
Expand Down Expand Up @@ -82,8 +82,12 @@ void ArchiveManager::AddGameVersion(uint32_t newGameVersion) {
mGameVersions.push_back(newGameVersion);
}

std::vector<std::shared_ptr<Archive>> ArchiveManager::GetArchives() {
return mArchives;
std::shared_ptr<std::vector<std::shared_ptr<Archive>>> ArchiveManager::GetArchives() {
auto archives = std::make_shared<std::vector<std::shared_ptr<Archive>>>();
for (const auto& archive : mArchives) {
archives->push_back(archive);
}
return archives;
}

void ArchiveManager::ResetVirtualFileSystem() {
Expand Down Expand Up @@ -118,8 +122,15 @@ size_t ArchiveManager::RemoveArchive(std::shared_ptr<Archive> archive) {
return RemoveArchive(archive->GetPath());
}

void ArchiveManager::SetArchives(const std::vector<std::shared_ptr<Archive>>& archives) {
mArchives = archives;
void ArchiveManager::SetArchives(std::shared_ptr<std::vector<std::shared_ptr<Archive>>> archives) {
mArchives.clear();

if (archives) {
for (const auto& archive : *archives) {
mArchives.push_back(archive);
}
}

ResetVirtualFileSystem();
}

Expand Down
4 changes: 2 additions & 2 deletions src/resource/archive/ArchiveManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class ArchiveManager {

std::shared_ptr<Archive> AddArchive(const std::string& archivePath);
std::shared_ptr<Archive> AddArchive(std::shared_ptr<Archive> archive);
std::vector<std::shared_ptr<Archive>> GetArchives();
void SetArchives(const std::vector<std::shared_ptr<Archive>>& archives);
std::shared_ptr<std::vector<std::shared_ptr<Archive>>> GetArchives();
void SetArchives(std::shared_ptr<std::vector<std::shared_ptr<Archive>>> archives);
size_t RemoveArchive(std::shared_ptr<Archive> archive);
size_t RemoveArchive(const std::string& path);

Expand Down

0 comments on commit d73dbff

Please sign in to comment.