Ditto 4.1.0
Attachment.hpp
1#ifndef _DITTO_ATTACHMENT_
2#define _DITTO_ATTACHMENT_
3
4#include "DiskUsage.hpp"
5#include "json.hpp"
6
7#include <map>
8#include <memory>
9#include <string>
10#include <vector>
11
12struct AttachmentHandle;
13
14namespace ditto {
15class DittoHandleWrapper;
16class AttachmentInner;
17
23 friend class Collection;
24 friend class AttachmentFetcher;
25
26public:
32 std::vector<uint8_t> get_data() const;
33
39 bool copy_to_path(const std::string &dest_path);
40
46 std::map<std::string, std::string> get_metadata() const;
47
48 // TODO: Hide these behind some sort of private implementation. They only need
49 // to be public for now because of their usage in the `to_json` function
50 // that's implemented for the `Attachment` type.
51 uint64_t get_type() const;
52 nlohmann::json::binary_t get_id() const;
53 uint64_t get_len() const;
54
61
62private:
63 Attachment(std::vector<uint8_t> id, uint64_t len,
64 std::map<std::string, std::string> metadata,
65 struct AttachmentHandle *handle,
66 std::shared_ptr<DittoHandleWrapper> ditto_handle_wrapper);
67
68 std::map<std::string, std::string> metadata;
69 std::vector<uint8_t> id;
70 uint64_t len;
71 std::shared_ptr<AttachmentInner> handle;
72 std::shared_ptr<DittoHandleWrapper> ditto_handle_wrapper;
73 DiskUsage disk_usage;
74 std::string path;
75 const char *get_path() const;
76 void update_path();
77};
78
79void to_json(nlohmann::json &j, const Attachment &a);
80
81} // namespace ditto
82#endif
These objects are returned by calls to Collection::fetch_attachment.
Definition: AttachmentFetcher.hpp:31
Represents an attachment and can be used to insert the associated attachment into a document at a spe...
Definition: Attachment.hpp:22
DiskUsage & get_disk_usage() const
Provides access to the Attachment's disk usage.
std::vector< uint8_t > get_data() const
Returns the attachment's data as a byte array.
Definition: Attachment.cpp:39
bool copy_to_path(const std::string &dest_path)
Copies the attachment to the specified file path.
Definition: Attachment.cpp:61
std::map< std::string, std::string > get_metadata() const
Gets the attachment's metadata.
Definition: Attachment.cpp:89
A reference to a collection in a Store.
Definition: Collection.hpp:26
Provides an interface to be able to monitor local files.
Definition: DiskUsage.hpp:65
basic_json<> json
default JSON class
Definition: json.hpp:2933