From: Jay Freeman (saurik) Date: Sat, 10 Oct 2015 21:04:44 +0000 (-0700) Subject: UnionFolder (code for Impactor) should be in ldid. X-Git-Tag: v2.1.0~71 X-Git-Url: https://git.saurik.com/ldid.git/commitdiff_plain/886cb3f1cf485d307519e2024ef141314d42e713 UnionFolder (code for Impactor) should be in ldid. --- diff --git a/ldid.cpp b/ldid.cpp index eb535fd..33b1859 100644 --- a/ldid.cpp +++ b/ldid.cpp @@ -1661,6 +1661,41 @@ void SubFolder::Find(const std::string &path, const Functor &code) { + return parent_.Save(path, code); +} + +bool UnionFolder::Open(const std::string &path, const Functor &code) { + auto file(files_.find(path)); + if (file == files_.end()) + return parent_.Open(path, code); + + auto &data(file->second); + data.pubseekpos(0, std::ios::in); + code(data); + return true; +} + +void UnionFolder::Find(const std::string &path, const Functor &)> &)> &code) { + parent_.Find(path, fun([&](const std::string &name, const Functor &)> &save) { + if (files_.find(name) == files_.end()) + code(name, save); + })); + + for (auto &file : files_) + code(file.first, fun([&](const Functor &code) { + parent_.Save(file.first, fun([&](std::streambuf &save) { + file.second.pubseekpos(0, std::ios::in); + code(file.second, save); + })); + })); +} + static size_t copy(std::streambuf &source, std::streambuf &target) { size_t total(0); for (;;) { diff --git a/ldid.hpp b/ldid.hpp index 4320bef..b7bbdaf 100644 --- a/ldid.hpp +++ b/ldid.hpp @@ -87,6 +87,25 @@ class SubFolder : virtual void Find(const std::string &path, const Functor &)> &)> &code); }; +class UnionFolder : + public Folder +{ + private: + Folder &parent_; + std::map files_; + + public: + UnionFolder(Folder &parent); + + virtual void Save(const std::string &path, const Functor &code); + virtual bool Open(const std::string &path, const Functor &code); + virtual void Find(const std::string &path, const Functor &)> &)> &code); + + std::stringbuf &operator [](const std::string &path) { + return files_[path]; + } +}; + std::string Bundle(const std::string &root, Folder &folder, const std::string &key, std::map> &remote); typedef std::map> Slots;