Arbiter  0.0.0
arbiter.hpp
1 #pragma once
2 
3 #include <vector>
4 #include <string>
5 
6 #if defined(_WIN32) || defined(WIN32) || defined(_MSC_VER)
7 #define ARBITER_WINDOWS
8 #endif
9 
10 #ifndef ARBITER_IS_AMALGAMATION
11 
12 #include <arbiter/driver.hpp>
13 #include <arbiter/endpoint.hpp>
14 #include <arbiter/drivers/fs.hpp>
15 #include <arbiter/drivers/test.hpp>
16 #include <arbiter/drivers/http.hpp>
17 #include <arbiter/drivers/s3.hpp>
18 #include <arbiter/drivers/dropbox.hpp>
19 
20 #ifndef ARBITER_EXTERNAL_JSON
21 #include <arbiter/third/json/json.hpp>
22 #endif
23 
24 #endif
25 
26 
27 
28 #ifdef ARBITER_EXTERNAL_JSON
29 #include <json/json.h>
30 #endif
31 
32 #ifdef ARBITER_CUSTOM_NAMESPACE
33 namespace ARBITER_CUSTOM_NAMESPACE
34 {
35 #endif
36 
37 namespace arbiter
38 {
39 
41 class ArbiterError : public std::runtime_error
42 {
43 public:
44  ArbiterError(std::string msg) : std::runtime_error(msg) { }
45 };
46 
59 class Arbiter
60 {
61 public:
65  Arbiter();
66 
68  Arbiter(const Json::Value& json);
69 
71  bool hasDriver(std::string path) const;
72 
84  void addDriver(std::string type, std::unique_ptr<Driver> driver);
85 
87  std::string get(std::string path) const;
88 
90  std::unique_ptr<std::string> tryGet(std::string path) const;
91 
93  std::vector<char> getBinary(std::string path) const;
94 
96  std::unique_ptr<std::vector<char>> tryGetBinary(std::string path) const;
97 
99  std::size_t getSize(std::string path) const;
100 
102  std::unique_ptr<std::size_t> tryGetSize(std::string path) const;
103 
105  void put(std::string path, const std::string& data) const;
106 
108  void put(std::string path, const std::vector<char>& data) const;
109 
112  std::string get(
113  std::string path,
114  http::Headers headers,
115  http::Query query = http::Query()) const;
116 
119  std::unique_ptr<std::string> tryGet(
120  std::string path,
121  http::Headers headers,
122  http::Query query = http::Query()) const;
123 
126  std::vector<char> getBinary(
127  std::string path,
128  http::Headers headers,
129  http::Query query = http::Query()) const;
130 
133  std::unique_ptr<std::vector<char>> tryGetBinary(
134  std::string path,
135  http::Headers headers,
136  http::Query query = http::Query()) const;
137 
140  void put(
141  std::string path,
142  const std::string& data,
143  http::Headers headers,
144  http::Query query = http::Query()) const;
145 
148  void put(
149  std::string path,
150  const std::vector<char>& data,
151  http::Headers headers,
152  http::Query query = http::Query()) const;
153 
164  void copy(std::string src, std::string dst, bool verbose = false) const;
165 
174  void copyFile(std::string file, std::string to, bool verbose = false) const;
175 
179  bool isRemote(std::string path) const;
180 
184  bool isLocal(std::string path) const;
185 
193  bool exists(std::string path) const;
194 
199  bool isHttpDerived(std::string path) const;
200 
232  std::vector<std::string> resolve(
233  std::string path,
234  bool verbose = false) const;
235 
237  Endpoint getEndpoint(std::string root) const;
238 
247  const Driver& getDriver(std::string path) const;
248 
269  std::unique_ptr<fs::LocalHandle> getLocalHandle(
270  std::string path,
271  const Endpoint& tempEndpoint) const;
272 
278  std::unique_ptr<fs::LocalHandle> getLocalHandle(
279  std::string path,
280  std::string tempPath = "") const;
281 
285  static std::string getType(std::string path);
286 
288  static std::string stripType(std::string path);
289 
292  static std::string getExtension(std::string path);
293 
297  http::Pool& httpPool() { return m_pool; }
298 
299 private:
300  // Registers all available default Driver instances.
301  void init(const Json::Value& json);
302 
303  const drivers::Http* tryGetHttpDriver(std::string path) const;
304  const drivers::Http& getHttpDriver(std::string path) const;
305 
306  DriverMap m_drivers;
307  http::Pool m_pool;
308 };
309 
310 } // namespace arbiter
311 
312 #ifdef ARBITER_CUSTOM_NAMESPACE
313 }
314 #endif
http::Pool & httpPool()
Definition: arbiter.hpp:297
Base class for interacting with a storage type.
Definition: driver.hpp:34
HTTP driver. Intended as both a standalone driver as well as a base for derived drivers build atop HT...
Definition: http.hpp:29
Exception class for all internally thrown runtime errors.
Definition: arbiter.hpp:41
Definition: arbiter.cpp:16
The primary interface for storage abstraction.
Definition: arbiter.hpp:59
A utility class to drive usage from a common root directory.
Definition: endpoint.hpp:34