]>
Commit | Line | Data |
---|---|---|
a0c715e9 JF |
1 | #ifndef LDID_HPP |
2 | #define LDID_HPP | |
3 | ||
4 | #include <cstdlib> | |
5 | #include <map> | |
6 | #include <streambuf> | |
7 | #include <string> | |
8 | ||
9 | namespace ldid { | |
10 | ||
e6a376fc JF |
11 | // I wish Apple cared about providing quality toolchains :/ |
12 | ||
13 | template <typename Function_> | |
14 | class Functor; | |
15 | ||
16 | template <typename Type_, typename... Args_> | |
17 | class Functor<Type_ (Args_...)> { | |
18 | public: | |
19 | virtual Type_ operator ()(Args_... args) const = 0; | |
20 | }; | |
21 | ||
22 | template <typename Function_> | |
23 | class FunctorImpl; | |
24 | ||
25 | template <typename Value_, typename Type_, typename... Args_> | |
26 | class FunctorImpl<Type_ (Value_::*)(Args_...) const> : | |
27 | public Functor<Type_ (Args_...)> | |
28 | { | |
29 | private: | |
30 | const Value_ *value_; | |
31 | ||
32 | public: | |
33 | FunctorImpl(const Value_ &value) : | |
34 | value_(&value) | |
35 | { | |
36 | } | |
37 | ||
38 | virtual Type_ operator ()(Args_... args) const { | |
39 | return (*value_)(args...); | |
40 | } | |
41 | }; | |
42 | ||
43 | template <typename Function_> | |
44 | FunctorImpl<decltype(&Function_::operator())> fun(const Function_ &value) { | |
45 | return value; | |
46 | } | |
47 | ||
23c11ee8 JF |
48 | class Folder { |
49 | public: | |
50 | virtual void Save(const std::string &path, const Functor<void (std::streambuf &)> &code) = 0; | |
51 | virtual bool Open(const std::string &path, const Functor<void (std::streambuf &)> &code) = 0; | |
52 | virtual void Find(const std::string &path, const Functor<void (const std::string &, const Functor<void (const Functor<void (std::streambuf &, std::streambuf &)> &)> &)> &code) = 0; | |
53 | }; | |
54 | ||
55 | class DiskFolder : | |
56 | public Folder | |
57 | { | |
58 | private: | |
59 | const std::string path_; | |
60 | std::map<std::string, std::string> commit_; | |
61 | ||
62 | std::string Path(const std::string &path); | |
63 | ||
54a0f854 JF |
64 | void Find(const std::string &root, const std::string &base, const Functor<void (const std::string &, const Functor<void (const Functor<void (std::streambuf &, std::streambuf &)> &)> &)>&code); |
65 | ||
23c11ee8 JF |
66 | public: |
67 | DiskFolder(const std::string &path); | |
68 | ~DiskFolder(); | |
69 | ||
70 | virtual void Save(const std::string &path, const Functor<void (std::streambuf &)> &code); | |
71 | virtual bool Open(const std::string &path, const Functor<void (std::streambuf &)> &code); | |
72 | virtual void Find(const std::string &path, const Functor<void (const std::string &, const Functor<void (const Functor<void (std::streambuf &, std::streambuf &)> &)> &)> &code); | |
73 | }; | |
74 | ||
75 | class SubFolder : | |
76 | public Folder | |
77 | { | |
78 | private: | |
2443500c | 79 | Folder &parent_; |
23c11ee8 JF |
80 | std::string path_; |
81 | ||
82 | public: | |
2443500c | 83 | SubFolder(Folder &parent, const std::string &path); |
23c11ee8 JF |
84 | |
85 | virtual void Save(const std::string &path, const Functor<void (std::streambuf &)> &code); | |
86 | virtual bool Open(const std::string &path, const Functor<void (std::streambuf &)> &code); | |
87 | virtual void Find(const std::string &path, const Functor<void (const std::string &, const Functor<void (const Functor<void (std::streambuf &, std::streambuf &)> &)> &)> &code); | |
88 | }; | |
89 | ||
886cb3f1 JF |
90 | class UnionFolder : |
91 | public Folder | |
92 | { | |
93 | private: | |
4d453c35 JF |
94 | class StringBuffer : |
95 | public std::stringbuf | |
96 | { | |
97 | public: | |
98 | StringBuffer() { | |
99 | } | |
100 | ||
101 | StringBuffer(const StringBuffer &rhs) : | |
102 | std::stringbuf(rhs.str()) | |
103 | { | |
104 | } | |
105 | }; | |
106 | ||
886cb3f1 | 107 | Folder &parent_; |
4d453c35 | 108 | std::map<std::string, StringBuffer> files_; |
886cb3f1 JF |
109 | |
110 | public: | |
111 | UnionFolder(Folder &parent); | |
112 | ||
113 | virtual void Save(const std::string &path, const Functor<void (std::streambuf &)> &code); | |
114 | virtual bool Open(const std::string &path, const Functor<void (std::streambuf &)> &code); | |
115 | virtual void Find(const std::string &path, const Functor<void (const std::string &, const Functor<void (const Functor<void (std::streambuf &, std::streambuf &)> &)> &)> &code); | |
116 | ||
117 | std::stringbuf &operator [](const std::string &path) { | |
118 | return files_[path]; | |
119 | } | |
120 | }; | |
121 | ||
4d03333f | 122 | 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); |
2dcf3faf | 123 | |
23c11ee8 | 124 | typedef std::map<uint32_t, std::vector<char>> Slots; |
a0c715e9 | 125 | |
ffdd1183 | 126 | void Sign(const void *idata, size_t isize, std::streambuf &output, const std::string &identifier, const std::string &entitlements, const std::string &key, const Slots &slots); |
a0c715e9 JF |
127 | |
128 | } | |
129 | ||
130 | #endif//LDID_HPP |