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