+class UnionFolder :
+ public Folder
+{
+ private:
+ class StringBuffer :
+ public std::stringbuf
+ {
+ public:
+ StringBuffer() {
+ }
+
+ StringBuffer(const StringBuffer &rhs) :
+ std::stringbuf(rhs.str())
+ {
+ }
+ };
+
+ Folder &parent_;
+ std::set<std::string> deletes_;
+
+ std::map<std::string, std::string> remaps_;
+ std::map<std::string, std::pair<StringBuffer, const void *>> resets_;
+
+ std::string Map(const std::string &path);
+ void Map(const std::string &path, const Functor<void (const std::string &, const Functor<void (const Functor<void (std::streambuf &, std::streambuf &)> &)> &)> &code, const std::string &file, const Functor<void (const Functor<void (std::streambuf &, const void *)> &)> &save);
+
+ public:
+ UnionFolder(Folder &parent);
+
+ virtual void Save(const std::string &path, const void *flag, const Functor<void (std::streambuf &)> &code);
+ virtual bool Open(const std::string &path, const Functor<void (std::streambuf &, const void *)> &code);
+ virtual void Find(const std::string &path, const Functor<void (const std::string &, const Functor<void (const Functor<void (std::streambuf &, std::streambuf &)> &)> &)> &code);
+
+ void operator ()(const std::string &from) {
+ deletes_.insert(from);
+ }
+
+ void operator ()(const std::string &from, const std::string &to) {
+ operator ()(from);
+ remaps_[to] = from;
+ }
+
+ std::stringbuf &operator ()(const std::string &from, const void *flag) {
+ operator ()(from);
+ auto &reset(resets_[from]);
+ reset.second = flag;
+ return reset.first;
+ }
+};
+
+std::string Bundle(const std::string &root, Folder &folder, const std::string &key, std::map<std::string, std::vector<char>> &remote, const std::string &entitlements, const std::string &requirement);