Skip to content

Commit

Permalink
Require user to store streambufs for UnionFolders.
Browse files Browse the repository at this point in the history
  • Loading branch information
saurik committed Dec 27, 2017
1 parent f74652a commit 4e6d856
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
11 changes: 6 additions & 5 deletions ldid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1978,19 +1978,20 @@ void UnionFolder::Open(const std::string &path, const Functor<void (std::streamb
return parent_.Open(Map(path), code);
auto &entry(file->second);

auto &data(entry.first);
auto &data(*entry.data_);
auto length(data.pubseekoff(0, std::ios::end, std::ios::in));
data.pubseekpos(0, std::ios::in);
code(data, length, entry.second);
code(data, length, entry.flag_);
}

void UnionFolder::Find(const std::string &path, const Functor<void (const std::string &)> &code, const Functor<void (const std::string &, const Functor<std::string ()> &)> &link) const {
for (auto &reset : resets_)
Map(path, code, reset.first, fun([&](const Functor<void (std::streambuf &, size_t, const void *)> &code) {
auto &entry(reset.second);
auto length(entry.first.pubseekoff(0, std::ios::end, std::ios::in));
entry.first.pubseekpos(0, std::ios::in);
code(entry.first, length, entry.second);
auto &data(*entry.data_);
auto length(data.pubseekoff(0, std::ios::end, std::ios::in));
data.pubseekpos(0, std::ios::in);
code(data, length, entry.flag_);
}));

for (auto &remap : remaps_)
Expand Down
22 changes: 7 additions & 15 deletions ldid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,24 +99,16 @@ class UnionFolder :
public Folder
{
private:
class StringBuffer :
public std::stringbuf
{
public:
StringBuffer() {
}

StringBuffer(const StringBuffer &rhs) :
std::stringbuf(rhs.str())
{
}
struct Reset {
const void *flag_;
std::streambuf *data_;
};

Folder &parent_;
std::set<std::string> deletes_;

std::map<std::string, std::string> remaps_;
mutable std::map<std::string, std::pair<StringBuffer, const void *>> resets_;
mutable std::map<std::string, Reset> resets_;

std::string Map(const std::string &path) const;
void Map(const std::string &path, const Functor<void (const std::string &)> &code, const std::string &file, const Functor<void (const Functor<void (std::streambuf &, size_t, const void *)> &)> &save) const;
Expand All @@ -138,11 +130,11 @@ class UnionFolder :
remaps_[to] = from;
}

std::stringbuf &operator ()(const std::string &from, const void *flag) {
void operator ()(const std::string &from, const void *flag, std::streambuf &data) {
operator ()(from);
auto &reset(resets_[from]);
reset.second = flag;
return reset.first;
reset.flag_ = flag;
reset.data_ = &data;
}
};

Expand Down

0 comments on commit 4e6d856

Please sign in to comment.