forked from opa334/ldid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathldid.hpp
98 lines (74 loc) · 3.01 KB
/
ldid.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#ifndef LDID_HPP
#define LDID_HPP
#include <cstdlib>
#include <map>
#include <streambuf>
#include <string>
namespace ldid {
// I wish Apple cared about providing quality toolchains :/
template <typename Function_>
class Functor;
template <typename Type_, typename... Args_>
class Functor<Type_ (Args_...)> {
public:
virtual Type_ operator ()(Args_... args) const = 0;
};
template <typename Function_>
class FunctorImpl;
template <typename Value_, typename Type_, typename... Args_>
class FunctorImpl<Type_ (Value_::*)(Args_...) const> :
public Functor<Type_ (Args_...)>
{
private:
const Value_ *value_;
public:
FunctorImpl(const Value_ &value) :
value_(&value)
{
}
virtual Type_ operator ()(Args_... args) const {
return (*value_)(args...);
}
};
template <typename Function_>
FunctorImpl<decltype(&Function_::operator())> fun(const Function_ &value) {
return value;
}
class Folder {
public:
virtual void Save(const std::string &path, const Functor<void (std::streambuf &)> &code) = 0;
virtual bool Open(const std::string &path, const Functor<void (std::streambuf &)> &code) = 0;
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;
};
class DiskFolder :
public Folder
{
private:
const std::string path_;
std::map<std::string, std::string> commit_;
std::string Path(const std::string &path);
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);
public:
DiskFolder(const std::string &path);
~DiskFolder();
virtual void Save(const std::string &path, const Functor<void (std::streambuf &)> &code);
virtual bool Open(const std::string &path, const Functor<void (std::streambuf &)> &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);
};
class SubFolder :
public Folder
{
private:
Folder &parent_;
std::string path_;
public:
SubFolder(Folder &parent, const std::string &path);
virtual void Save(const std::string &path, const Functor<void (std::streambuf &)> &code);
virtual bool Open(const std::string &path, const Functor<void (std::streambuf &)> &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);
};
std::string Bundle(const std::string &root, Folder &folder, const std::string &key, std::map<std::string, std::vector<char>> &remote);
typedef std::map<uint32_t, std::vector<char>> Slots;
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);
}
#endif//LDID_HPP