Arbiter  0.0.0
endpoint.hpp
1 #pragma once
2 
3 #include <string>
4 #include <vector>
5 #include <memory>
6 
7 #ifndef ARBITER_IS_AMALGAMATION
8 
9 #include <arbiter/util/http.hpp>
10 
11 #endif
12 
13 #ifdef ARBITER_CUSTOM_NAMESPACE
14 namespace ARBITER_CUSTOM_NAMESPACE
15 {
16 #endif
17 
18 namespace arbiter
19 {
20 
21 namespace drivers { class Http; }
22 
23 class Driver;
24 
34 class Endpoint
35 {
36  // Only Arbiter may construct.
37  friend class Arbiter;
38 
39 public:
44  std::string root() const;
45 
50  std::string prefixedRoot() const;
51 
52  // Driver passthroughs.
53 
55  std::string type() const;
56 
58  bool isRemote() const;
59 
61  bool isLocal() const;
62 
64  bool isHttpDerived() const;
65 
67  std::string get(std::string subpath) const;
68 
70  std::unique_ptr<std::string> tryGet(std::string subpath) const;
71 
73  std::vector<char> getBinary(std::string subpath) const;
74 
76  std::unique_ptr<std::vector<char>> tryGetBinary(std::string subpath) const;
77 
79  std::size_t getSize(std::string subpath) const;
80 
82  std::unique_ptr<std::size_t> tryGetSize(std::string subpath) const;
83 
85  void put(std::string subpath, const std::string& data) const;
86 
90  void put(std::string subpath, const std::vector<char>& data) const;
91 
92  // HTTP-specific passthroughs.
93 
96  std::string get(
97  std::string subpath,
98  http::Headers headers,
99  http::Query = http::Query()) const;
100 
103  std::unique_ptr<std::string> tryGet(
104  std::string subpath,
105  http::Headers headers,
106  http::Query = http::Query()) const;
107 
111  std::vector<char> getBinary(
112  std::string path,
113  http::Headers headers,
114  http::Query query = http::Query()) const;
115 
119  std::unique_ptr<std::vector<char>> tryGetBinary(
120  std::string path,
121  http::Headers headers,
122  http::Query query = http::Query()) const;
123 
127  void put(
128  std::string path,
129  const std::string& data,
130  http::Headers headers,
131  http::Query query = http::Query()) const;
132 
136  void put(
137  std::string path,
138  const std::vector<char>& data,
139  http::Headers headers,
140  http::Query query = http::Query()) const;
141 
142  // Endpoint specifics.
143 
147  std::string fullPath(const std::string& subpath) const;
148 
152  std::string prefixedFullPath(const std::string& subpath) const;
153 
155  Endpoint getSubEndpoint(std::string subpath) const;
156 
157 private:
158  Endpoint(const Driver& driver, std::string root);
159 
160  // If `isRemote()`, returns the type and delimiter, otherwise returns an
161  // empty string.
162  std::string softPrefix() const;
163 
164  const drivers::Http* tryGetHttpDriver() const;
165  const drivers::Http& getHttpDriver() const;
166 
167  const Driver& m_driver;
168  std::string m_root;
169 };
170 
171 } // namespace arbiter
172 
173 #ifdef ARBITER_CUSTOM_NAMESPACE
174 }
175 #endif
176 
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
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