libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
metadata.h
Go to the documentation of this file.
1
8#pragma once
9
12#include <promeki/core/map.h>
13#include <promeki/core/util.h>
14#include <promeki/core/json.h>
16
17#define PROMEKI_ENUM_METADATA_ID \
18 X(Invalid, std::monostate) \
19 X(Timecode, class Timecode) \
20 X(Gamma, double) \
21 X(Title, String) \
22 X(Copyright, String) \
23 X(Software, String) \
24 X(Artist, String) \
25 X(Comment, String) \
26 X(Date, String) \
27 X(Album, String) \
28 X(License, String) \
29 X(TrackNumber, int) \
30 X(Genre, String) \
31 X(EnableBWF, bool) \
32 X(Description, String) \
33 X(Originator, String) \
34 X(OriginatorReference, String) \
35 X(OriginationDateTime, String) \
36 X(FrameRate, Rational<int>) \
37 X(UMID, String) \
38 X(CodingHistory, String) \
39 X(CompressionLevel, double) \
40 X(EnableVBR, bool) \
41 X(VBRQuality, double) \
42 X(CompressedSize, int) \
43 X(EndOfStream, bool)
46
47class StringList;
48
68class Metadata {
70 public:
73
75 #define X(name, type) name,
77 #undef X
78
84 static const String &idToString(ID id);
85
91 static ID stringToID(const String &val);
92
99 static Metadata fromJson(const JsonObject &json, Error *err = nullptr);
100
102 Metadata() = default;
103
110 template <typename T> void set(ID id, const T &value) {
111 _map[id] = Variant(value);
112 return;
113 }
114
120 const Variant &get(ID id) const { return _map[id]; }
121
127 bool contains(ID id) const { return _map.contains(id); }
128
133 void remove(ID id) { _map.remove(id); return; }
134
136 void clear() { _map.clear(); return; }
137
142 size_t size() const { return _map.size(); }
143
148 bool isEmpty() const { return _map.size() == 0; }
149
155 template <typename Func> void forEach(Func &&func) const {
156 for(const auto &[id, value] : _map) {
157 func(id, value);
158 }
159 return;
160 }
161
167
173 bool operator==(const Metadata &other) const {
174 if(_map.size() != other._map.size()) return false;
175 return toJson() == other.toJson();
176 }
177
184 for(const auto &[id, value] : _map) {
185 ret.setFromVariant(idToString(id), value);
186 }
187 return ret;
188 }
189
190 private:
191 Map<ID, Variant> _map;
192};
193
Lightweight error code wrapper for the promeki library.
Definition error.h:39
JSON object container wrapping nlohmann::json.
Definition json.h:44
Dynamic array container wrapping std::vector.
Definition list.h:40
bool contains(const T &val) const
Returns true if the list contains the given value.
Definition list.h:593
Iterator remove(ConstIterator pos)
Removes the element at the given iterator position.
Definition list.h:402
size_t size() const noexcept
Returns the number of elements in the list.
Definition list.h:301
void clear() noexcept
Removes all elements from the list.
Definition list.h:330
Key-value metadata container using typed Variant values.
Definition metadata.h:68
JsonObject toJson() const
Serializes this Metadata to a JSON object.
Definition metadata.h:182
StringList dump() const
Returns a human-readable dump of all metadata entries.
bool operator==(const Metadata &other) const
Returns true if both Metadata objects contain the same entries.
Definition metadata.h:173
void remove(ID id)
Removes the entry for the given ID.
Definition metadata.h:133
bool isEmpty() const
Returns true if no metadata entries are stored.
Definition metadata.h:148
void set(ID id, const T &value)
Sets a metadata value for the given ID.
Definition metadata.h:110
static Metadata fromJson(const JsonObject &json, Error *err=nullptr)
Deserializes a Metadata object from a JSON object.
ID
Definition metadata.h:76
size_t size() const
Returns the number of metadata entries.
Definition metadata.h:142
static ID stringToID(const String &val)
Converts a string name to a metadata ID.
void forEach(Func &&func) const
Iterates over all metadata entries, invoking a callback for each.
Definition metadata.h:155
const Variant & get(ID id) const
Returns the Variant value for the given ID.
Definition metadata.h:120
bool contains(ID id) const
Returns true if the given ID has been set.
Definition metadata.h:127
static const String & idToString(ID id)
Converts a metadata ID to its string name.
Metadata()=default
Constructs an empty Metadata object.
void clear()
Removes all metadata entries.
Definition metadata.h:136
Manages a list of strings.
Definition stringlist.h:21
Encoding-aware string class with copy-on-write semantics.
Definition string.h:35
#define PROMEKI_ENUM_METADATA_ID
Signals end-of-stream to downstream nodes.
Definition metadata.h:17
#define PROMEKI_NAMESPACE_BEGIN
Starts a promeki namespace block.
Definition namespace.h:14
#define PROMEKI_NAMESPACE_END
Ends a promeki namespace block.
Definition namespace.h:19
const T & value(const Result< T > &r)
Returns the value from a Result.
Definition result.h:56
#define PROMEKI_SHARED_FINAL(TYPE)
Macro for non-polymorphic native shared objects.
Definition sharedptr.h:88
VariantImpl< std::monostate, bool, uint8_t, int8_t, uint16_t, int16_t, uint32_t, int32_t, uint64_t, int64_t, float, double, String, DateTime, TimeStamp, Size2Du32, UUID, Timecode, Rational< int >, detail::VariantEnd > Variant
Concrete variant type instantiated with every type from PROMEKI_VARIANT_TYPES.
Definition variant.h:362