15 #include <immer/box.hpp>
16 #include <immer/flex_vector.hpp>
51 template<
class DeriveT>
53 : m_d(
std::make_unique<Model<
std::decay_t<DeriveT>>>(
54 std::forward<DeriveT>(o))) {}
64 template<
class Callback>
65 void read(
int maxSize, Callback readCallback) { m_d->read(maxSize, readCallback); }
74 template<
class Callback>
75 void write(
DataT data, Callback writeCallback) { m_d->write(data, writeCallback); }
81 virtual ~Concept() =
default;
83 using WriteCallback = std::function<void(
FileOpRetCode,
int)>;
85 virtual void read(
int maxSize, ReadCallback callback) = 0;
86 virtual void write(
DataT data, WriteCallback callback) = 0;
89 template<
class DeriveT>
90 struct Model :
public Concept
92 explicit Model(
const DeriveT &o) : obj(o) {}
93 explicit Model(DeriveT &&o) : obj(
std::move(o)) {}
94 ~Model()
override =
default;
95 void read(
int maxSize, ReadCallback callback)
override {
96 return obj.read(maxSize, callback);
98 void write(
DataT data, WriteCallback callback)
override {
99 return obj.write(data, callback);
105 std::unique_ptr<Concept> m_d;
128 template<
class DeriveT>
130 : m_d(
std::make_unique<Model<
std::decay_t<DeriveT>>>(
131 std::forward<DeriveT>(o))) {}
137 m_d = that.m_d->clone();
142 m_d = std::move(that.m_d);
153 return m_d->getStream(mode);
159 virtual ~Concept() =
default;
160 virtual std::unique_ptr<Concept> clone()
const = 0;
164 template<
class DeriveT>
165 struct Model :
public Concept
167 explicit Model(
const DeriveT &o) : obj(o) {}
168 explicit Model(DeriveT &&o) : obj(
std::move(o)) {}
169 ~Model()
override =
default;
170 std::unique_ptr<Concept> clone()
const override {
171 return std::make_unique<Model>(obj);
174 return obj.getStream(mode);
180 std::unique_ptr<Concept> m_d;
191 template<
class Callback>
192 void read(
int maxSize, Callback callback) {
202 template<
class Callback>
239 std::optional<std::string>
contentType = std::nullopt)
258 inline std::optional<std::string>
name()
const {
return m_name; }
263 inline std::optional<std::string>
contentType()
const {
return m_contentType; }
270 std::optional<std::string> m_name;
271 std::optional<std::string> m_contentType;
294 template<
class DeriveT>
296 : m_d(
std::make_unique<Model<
std::decay_t<DeriveT>>>(
297 std::forward<DeriveT>(o))) {}
306 return m_d->getProviderFor(std::move(desc));
312 virtual ~Concept() =
default;
316 template<
class DeriveT>
317 struct Model :
public Concept
319 explicit Model(
const DeriveT &o) : obj(o) {}
320 explicit Model(DeriveT &&o) : obj(
std::move(o)) {}
321 ~Model()
override =
default;
323 return obj.getProviderFor(std::move(desc));
329 std::unique_ptr<Concept> m_d;
Definition: file-desc.hpp:275
DumbFileProvider getProviderFor(FileDesc desc) const
Definition: file-desc.cpp:25
Definition: file-desc.hpp:225
std::optional< std::string > contentType() const
Get the content type for this FileDesc.
Definition: file-desc.hpp:263
FileProvider provider(const FileInterface &fh) const
Get the FileProvider for this FileDesc using FileInterface.
Definition: file-desc.cpp:17
FileDesc(std::string name, std::optional< std::string > contentType=std::nullopt)
Construct a FileDesc with name and contentType.
Definition: file-desc.hpp:238
FileDesc(FileContent content)
Construct an in-memory FileDesc with content.
Definition: file-desc.hpp:230
std::optional< std::string > name() const
Get the name for this FileDesc.
Definition: file-desc.hpp:258
bool operator==(const FileDesc &that) const
Definition: file-desc.cpp:45
Definition: file-desc.hpp:281
FileProvider getProviderFor(FileDesc desc) const
Get the provider for desc from this.
Definition: file-desc.hpp:305
FileInterface(DeriveT &&o)
Constructor.
Definition: file-desc.hpp:295
Definition: file-desc.hpp:109
FileProvider(const FileProvider &that)
Definition: file-desc.hpp:133
FileStream getStream(FileOpenMode mode=FileOpenMode::Read) const
Get the file stream provided by this.
Definition: file-desc.hpp:152
FileProvider & operator=(FileProvider &&that)
Definition: file-desc.hpp:141
FileProvider & operator=(const FileProvider &that)
Definition: file-desc.hpp:136
FileProvider(FileProvider &&that)
Definition: file-desc.hpp:134
FileProvider(DeriveT &&o)
Constructor.
Definition: file-desc.hpp:129
Definition: file-desc.hpp:36
void read(int maxSize, Callback readCallback)
Read at most maxSize bytes from the stream.
Definition: file-desc.hpp:65
FileStream(DeriveT &&o)
Constructor.
Definition: file-desc.hpp:52
FileContent DataT
Definition: file-desc.hpp:38
void write(DataT data, Callback writeCallback)
Write data into the stream.
Definition: file-desc.hpp:75
Definition: location.hpp:10
immer::flex_vector< char > FileContent
Definition: file-desc.hpp:33
FileOpRetCode
Definition: file-desc.hpp:21
FileOpenMode
Definition: file-desc.hpp:28
Definition: clientutil.hpp:217
Definition: file-desc.hpp:212
DumbFileProvider(FileContent content)
Definition: file-desc.hpp:213
FileContent m_content
Definition: file-desc.hpp:221
DumbFileStream getStream(FileOpenMode) const
Definition: file-desc.hpp:217
Definition: file-desc.hpp:188
void write(FileContent data, Callback callback)
Definition: file-desc.hpp:203
FileContent remaining
Definition: file-desc.hpp:208
void read(int maxSize, Callback callback)
Definition: file-desc.hpp:192
DumbFileStream(FileContent r)
Definition: file-desc.hpp:189