4 /* SPDX-License-Identifier: AGPL-3.0-only */
16 // I wish Apple cared about providing quality toolchains :/
18 template <typename Function_>
21 template <typename Type_, typename... Args_>
22 class Functor<Type_ (Args_...)> {
24 virtual Type_ operator ()(Args_... args) const = 0;
27 template <typename Function_>
30 template <typename Value_, typename Type_, typename... Args_>
31 class FunctorImpl<Type_ (Value_::*)(Args_...) const> :
32 public Functor<Type_ (Args_...)>
38 FunctorImpl(const Value_ &value) :
43 virtual Type_ operator ()(Args_... args) const {
44 return (*value_)(args...);
48 template <typename Function_>
49 FunctorImpl<decltype(&Function_::operator())> fun(const Function_ &value) {
54 virtual void operator()(const std::string &value) const = 0;
55 virtual void operator()(double value) const = 0;
60 virtual void Save(const std::string &path, bool edit, const void *flag, const Functor<void (std::streambuf &)> &code) = 0;
61 virtual bool Look(const std::string &path) const = 0;
62 virtual void Open(const std::string &path, const Functor<void (std::streambuf &, size_t, const void *)> &code) const = 0;
63 virtual void Find(const std::string &path, const Functor<void (const std::string &)> &code, const Functor<void (const std::string &, const Functor<std::string ()> &)> &link) const = 0;
70 const std::string path_;
71 std::map<std::string, std::string> commit_;
74 std::string Path(const std::string &path) const;
77 void Find(const std::string &root, const std::string &base, const Functor<void (const std::string &)> &code, const Functor<void (const std::string &, const Functor<std::string ()> &)> &link) const;
80 DiskFolder(const std::string &path);
83 virtual void Save(const std::string &path, bool edit, const void *flag, const Functor<void (std::streambuf &)> &code);
84 virtual bool Look(const std::string &path) const;
85 virtual void Open(const std::string &path, const Functor<void (std::streambuf &, size_t, const void *)> &code) const;
86 virtual void Find(const std::string &path, const Functor<void (const std::string &)> &code, const Functor<void (const std::string &, const Functor<std::string ()> &)> &link) const;
97 SubFolder(Folder &parent, const std::string &path);
99 std::string Path(const std::string &path) const;
101 virtual void Save(const std::string &path, bool edit, const void *flag, const Functor<void (std::streambuf &)> &code);
102 virtual bool Look(const std::string &path) const;
103 virtual void Open(const std::string &path, const Functor<void (std::streambuf &, size_t, const void *)> &code) const;
104 virtual void Find(const std::string &path, const Functor<void (const std::string &)> &code, const Functor<void (const std::string &, const Functor<std::string ()> &)> &link) const;
113 std::streambuf *data_;
117 std::set<std::string> deletes_;
119 std::map<std::string, std::string> remaps_;
120 mutable std::map<std::string, Reset> resets_;
122 std::string Map(const std::string &path) const;
123 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;
126 UnionFolder(Folder &parent);
128 virtual void Save(const std::string &path, bool edit, const void *flag, const Functor<void (std::streambuf &)> &code);
129 virtual bool Look(const std::string &path) const;
130 virtual void Open(const std::string &path, const Functor<void (std::streambuf &, size_t, const void *)> &code) const;
131 virtual void Find(const std::string &path, const Functor<void (const std::string &)> &code, const Functor<void (const std::string &, const Functor<std::string ()> &)> &link) const;
133 void operator ()(const std::string &from) {
134 deletes_.insert(from);
137 void operator ()(const std::string &from, const std::string &to) {
142 void operator ()(const std::string &from, const void *flag, std::streambuf &data) {
144 auto &reset(resets_[from]);
152 uint8_t sha256_[0x20];
160 Bundle Sign(const std::string &root, Folder &folder, const std::string &key, const std::string &requirements, const Functor<std::string (const std::string &, const std::string &)> &alter, bool merge, const Progress &progress);
162 typedef std::map<uint32_t, Hash> Slots;
164 Hash Sign(const void *idata, size_t isize, std::streambuf &output, const std::string &identifier, const std::string &entitlements, bool merge, const std::string &requirements, const std::string &key, const Slots &slots, uint32_t flags, uint8_t platform, const Progress &progress);