avcpp
2.0
Wrapper for the FFmpeg that simplify usage from C++ projects.
|
Go to the documentation of this file.
11 #include <libavutil/dict.h>
70 using RawStringDeleter = AvStringDeleter;
76 struct AvStringPtr :
public std::unique_ptr<char, AvStringDeleter>
78 using base_class = std::unique_ptr<char, AvStringDeleter>;
79 using base_class::unique_ptr;
104 return strlen(
c_str());
117 return c_str()[index];
121 static_assert (
sizeof(AvStringPtr) ==
sizeof(
char*),
"Size must be same. Check and try again");
123 using RawStringPtr = AvStringPtr;
127 template<
bool constIterator>
145 const char*
key() const noexcept;
150 const
char*
value() const noexcept;
157 void set(const
char *
value,
int flags = 0) noexcept;
159 void set(const
std::
string&
value,
int flags = 0) noexcept;
177 operator
bool() const;
184 friend
bool operator==(const
Entry& lhs, const
Entry& rhs);
185 friend
bool operator!=(const
Entry& lhs, const
Entry& rhs);
188 AVDictionaryEntry *m_entry =
nullptr;
195 template<
bool constIterator = false>
201 using value_type =
typename std::conditional<constIterator, const Entry, Entry>::type;
207 using DictType =
typename std::conditional<constIterator, const Dictionary, Dictionary>::type;
208 using EntryType =
typename std::conditional<constIterator, const Entry, Entry>::type;
228 m_entry.m_entry = av_dict_get(m_dict.raw(),
"", m_entry.m_entry,
FlagIgnoreSuffix);
241 return lhs.m_entry == rhs.m_entry;
246 return lhs.m_entry != rhs.m_entry;
283 explicit Dictionary(AVDictionary *dict,
bool takeOwning =
true);
338 Dictionary(std::initializer_list<std::pair<const char*, const char*>> list,
int flags = 0);
384 void assign(AVDictionary *dict,
bool takeOwning = true) noexcept;
393 const
char* operator[](
size_t index) const;
395 Entry operator[](
size_t index);
405 const
char* operator[](const
char*
key) const;
407 Entry operator[](const
char*
key) noexcept;
416 size_t count() const noexcept;
418 size_t size() const noexcept;
429 const
char *
get(const
char*
key,
int flags = 0) const noexcept;
431 const
char *
get(const
std::
string&
key,
int flags = 0) const noexcept;
446 template<typename Key, typename Value = Key>
448 typename
std::enable_if
450 (
std::is_same<Key,
std::
string>::
value ||
std::is_same<typename
std::remove_cv<typename
std::decay<Key>::type>::type,
char*>::
value) &&
451 (
std::is_same<Value,
std::
string>::
value ||
std::is_same<typename
std::remove_cv<typename
std::decay<Value>::type>::type,
char*>::
value ||
std::is_integral<Value>::
value)
457 if ((sts = set_priv(
key,
value, flags)) < 0) {
480 template<
typename Str,
typename Sep1,
typename Sep2>
484 _to_const_char_ptr(str),
485 _to_const_char_ptr(keyValSep),
486 _to_const_char_ptr(pairsSep),
550 AVDictionary **
rawPtr() noexcept;
556 int set_priv(const
char*
key, const
char *
value,
int flags = 0) noexcept;
557 int set_priv(const
std::
string&
key, const
std::
string&
value,
int flags = 0) noexcept;
558 int set_priv(const
char*
key, int64_t
value,
int flags = 0) noexcept;
559 int set_priv(const
std::
string&
key, int64_t
value,
int flags = 0) noexcept;
561 const
char* _to_const_char_ptr(const
char *str)
566 const char* _to_const_char_ptr(
const std::string &str)
571 int parseString_priv(
const char* str,
const char* keyvalSep,
const char* pairsSep,
int flags);
572 void parseString_priv(OptionalErrorCode ec,
const char* str,
const char* keyvalSep,
const char* pairsSep,
int flags);
576 bool m_owning =
true;
602 void assign(AVDictionary **dicts,
size_t count,
bool takeOwning =
true);
603 void reserve(
size_t size);
604 void resize(
size_t size);
616 const AVDictionary*
const* raws()
const;
617 AVDictionary** raws();
622 std::vector<AVDictionary*> m_raws;
623 std::vector<Dictionary> m_dicts;
void set(const char *value, int flags=0) noexcept
Definition: dictionary.cpp:338
EntryType & operator*() noexcept
Definition: dictionary.h:249
std::unique_ptr< char, AvStringDeleter > base_class
Definition: dictionary.h:78
FfmpegCategory & ffmpeg_category()
Definition: averror.h:121
Deleter for raw string.
Definition: dictionary.h:60
Array of Dictinaries wrapper.
Definition: dictionary.h:588
Implements interface to access to the AVDictionary entity.
Definition: dictionary.h:30
friend class Dictionary
Definition: dictionary.h:139
ptrdiff_t difference_type
Definition: dictionary.h:202
@ FlagDontStrdupVal
Do not duplicate string value.
Definition: dictionary.h:48
value_type * pointer
Definition: dictionary.h:203
void assign(AVDictionary *dict, bool takeOwning=true) noexcept
assign - assign new resouces Old dictionary destroyes (if owning).
Definition: dictionary.cpp:109
ConstIterator cend() const
Definition: dictionary.cpp:99
std::forward_iterator_tag iterator_category
Definition: dictionary.h:200
Entry & operator=(const char *value) noexcept
Definition: dictionary.cpp:371
bool isOwning() const noexcept
isOwning - checks resources owning status
Definition: dictionary.cpp:104
void swap(Dictionary &other) noexcept
swap - swaps resouces between objects
Definition: dictionary.cpp:308
void clear_if(OptionalErrorCode ec)
clear_if - clear error code if it is not av::throws()
Definition: averror.h:211
std::string toString(const char keyValSep, const char pairsSep, OptionalErrorCode ec=throws()) const
toString - converts dictionary to the string representation (serialize)
Definition: dictionary.cpp:206
size_t size() const noexcept
Definition: dictionary.cpp:186
friend bool operator==(const DictionaryIterator &lhs, const DictionaryIterator &rhs) noexcept
Definition: dictionary.h:239
size_t count() const noexcept
Definition: dictionary.cpp:181
const char * key() const noexcept
key - item key accessor
Definition: dictionary.cpp:328
void copyFrom(const Dictionary &other, int flags=0) noexcept
copyFrom - copy data from other dictionary.
Definition: dictionary.cpp:303
const char * operator[](size_t index) const
Definition: dictionary.cpp:121
AvStringPtr toRawStringPtr(const char keyValSep, const char pairsSep, OptionalErrorCode ec=throws()) const
toRawStringPtr - converts dictionary to the raw string (char*) and protect it with smart pointer (std...
Definition: dictionary.cpp:227
bool isNull() const
isNull - checks that entry invalid (null)
Definition: dictionary.cpp:360
void throws_if(OptionalErrorCode ec, int errcode, const Category &cat)
Throws exception if ec is av::throws() or fill error code.
Definition: averror.h:188
EntryType * operator->() noexcept
Definition: dictionary.h:254
void operator()(char *ptr)
Definition: dictionary.h:62
Iterator begin()
Definition: dictionary.cpp:74
friend bool operator!=(const DictionaryIterator &lhs, const DictionaryIterator &rhs) noexcept
Definition: dictionary.h:244
Iterator end()
Definition: dictionary.cpp:79
void parseString(const Str &str, const Sep1 &keyValSep, const Sep2 &pairsSep, int flags=0, OptionalErrorCode ec=throws())
parseString - process string with options and fill dictionary String examples:
Definition: dictionary.h:481
typename std::conditional< constIterator, const Entry, Entry >::type value_type
Definition: dictionary.h:201
@ FlagIgnoreSuffix
Special case: Iterate via dictionary.
Definition: dictionary.h:41
ConstIterator cbegin() const
Definition: dictionary.cpp:94
Flags
AVDictionary flags mapping.
Definition: dictionary.h:36
DictionaryIterator operator++(int) noexcept
Definition: dictionary.h:232
Dictionary & operator=(const Dictionary &rhs)
Copy assign operator Make deep copy of dictionary.
Definition: dictionary.cpp:35
Definition: audioresampler.cpp:8
Definition: averror.h:228
DictionaryIterator & operator++() noexcept
Definition: dictionary.h:226
@ FlagDontOverwrite
Keep existing value if key already exists.
Definition: dictionary.h:50
~Dictionary()
Dtor If Dictionary takes ownershipping on AVDictionary, it free allocated resources.
Definition: dictionary.cpp:21
DictionaryIterator(DictType &dict, const Entry &entry) noexcept
Definition: dictionary.h:214
@ FlagAppend
Append value to the existing one (string concat)
Definition: dictionary.h:52
char * c_str() const noexcept
Access to the holded string with std::string interface.
Definition: dictionary.h:85
@ FlagMatchCase
Do not ignore case.
Definition: dictionary.h:39
const char * value() const noexcept
value - item value accessor
Definition: dictionary.cpp:333
void reset(AVDictionary *raw=nullptr)
Definition: ffmpeg.h:76
OptionalErrorCode throws()
Helper to construct null OptionalErrorCode object.
Definition: averror.h:179
const char * get(const char *key, int flags=0) const noexcept
Definition: dictionary.cpp:191
value_type & reference
Definition: dictionary.h:204
Base dictionary iterator implementation.
Definition: dictionary.h:128
AVDictionary ** rawPtr() noexcept
Definition: dictionary.cpp:323
@ FlagDontStrdupKey
Do not duplicate string key.
Definition: dictionary.h:44
char & operator[](size_t index) const noexcept
Array-like char access.
Definition: dictionary.h:115
AVDictionary * release()
release - drops ownershipping
Definition: dictionary.cpp:315
DictionaryIterator(DictType &dict) noexcept
Definition: dictionary.h:220
RAII holder for strings allocated by FFmpeg internals.
Definition: dictionary.h:76
Dictionary key and value holder and accessor.
Definition: dictionary.h:133
size_t length() const noexcept
RAW string length in bytes.
Definition: dictionary.h:102