|
avcpp 3.1.0
Wrapper for the FFmpeg that simplify usage from C++ projects.
|
Implements interface to access to the AVDictionary entity. More...
#include <dictionary.h>
Classes | |
| struct | AvStringDeleter |
| Deleter for raw string. More... | |
| struct | AvStringPtr |
| RAII holder for strings allocated by FFmpeg internals. More... | |
| class | DictionaryIterator |
| Base dictionary iterator implementation. More... | |
| class | Entry |
| Dictionary key and value holder and accessor. More... | |
Public Types | |
| enum | Flags { FlagMatchCase = AV_DICT_MATCH_CASE , FlagIgnoreSuffix = AV_DICT_IGNORE_SUFFIX , FlagDontStrdupKey = AV_DICT_DONT_STRDUP_KEY , FlagDontStrdupVal = AV_DICT_DONT_STRDUP_VAL , FlagDontOverwrite = AV_DICT_DONT_OVERWRITE , FlagAppend = AV_DICT_APPEND } |
| AVDictionary flags mapping. More... | |
| using | Iterator = DictionaryIterator<false> |
| Non-const iterator. | |
| using | ConstIterator = DictionaryIterator<true> |
| Const iterator. | |
Public Member Functions | |||||
| Dictionary () | |||||
| Default ctor do nothig, null dictionary creates. | |||||
| Dictionary (AVDictionary *dict, bool takeOwning=true) | |||||
| Assign ctor Wrap around raw dictionary. | |||||
| ~Dictionary () | |||||
| Dtor If Dictionary takes ownershipping on AVDictionary, it free allocated resources. | |||||
| Dictionary (const Dictionary &other) | |||||
| Copy ctor Make deep copy of dictionary. | |||||
| Dictionary & | operator= (const Dictionary &rhs) | ||||
| Copy assign operator Make deep copy of dictionary. | |||||
| Dictionary (Dictionary &&other) | |||||
| Move ctor Takes resources. | |||||
| Dictionary & | operator= (Dictionary &&rhs) | ||||
| Move assign operator Takes resources. | |||||
| Dictionary (std::initializer_list< std::pair< const char *, const char * > > list, int flags=0) | |||||
| Initializer ctor Allows create dictionaries in array manier: | |||||
| Dictionary & | operator= (std::initializer_list< std::pair< const char *, const char * > > list) | ||||
| Initializer assign operator Allows assign dictionaries in array manier: | |||||
| bool | isOwning () const noexcept | ||||
| isOwning - checks resources owning status | |||||
| void | assign (AVDictionary *dict, bool takeOwning=true) noexcept | ||||
| assign - assign new resouces Old dictionary destroyes (if owning). | |||||
| template<typename Key, typename Value = Key> | |||||
| auto | set (const Key &key, const Value &value, OptionalErrorCode ec=throws(), int flags=0) -> typename std::enable_if<(std::is_same< Key, std::string >::value||std::is_same< typename std::remove_cv< typename std::decay< Key >::type >::type, char * >::value) &&(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), void >::type | ||||
| set - set new value for key or add new dictionary item (or create dictionary) If dictionary empty (null), it takes ownershipping too. | |||||
| template<typename Str, typename Sep1, typename Sep2> | |||||
| 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: | |||||
| std::string | toString (const char keyValSep, const char pairsSep, OptionalErrorCode ec=throws()) const | ||||
| toString - converts dictionary to the string representation (serialize) | |||||
| 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::unique_ptr). | |||||
| void | copyFrom (const Dictionary &other, int flags=0) noexcept | ||||
| copyFrom - copy data from other dictionary. | |||||
| void | swap (Dictionary &other) noexcept | ||||
| swap - swaps resouces between objects | |||||
| AVDictionary * | release () | ||||
| release - drops ownershipping | |||||
| AVDictionary ** | rawPtr () noexcept | ||||
| Address of the internal pointer, for FFmpeg calls that take AVDictionary**. | |||||
Iterator interface | |||||
| Iterator | begin () | ||||
| First entry. | |||||
| Iterator | end () | ||||
| End of the iteration. | |||||
| ConstIterator | begin () const | ||||
| First entry, read-only. | |||||
| ConstIterator | end () const | ||||
| End of the read-only iteration. | |||||
| ConstIterator | cbegin () const | ||||
| First entry, read-only, for explicit const traversal. | |||||
| ConstIterator | cend () const | ||||
| End of the read-only traversal. | |||||
Index based access operator | |||||
operator [] - access to the entry via index O(1) complexity.
| |||||
| const char * | operator[] (size_t index) const | ||||
| Entry value by position. | |||||
| Entry | operator[] (size_t index) | ||||
| Entry holder by position, for assignment. | |||||
Key based access operator | |||||
operator [] - access to the entry via key O(n) complexity.
| |||||
| const char * | operator[] (const char *key) const | ||||
| Entry value by key. | |||||
| Entry | operator[] (const char *key) noexcept | ||||
| Entry holder by key, for assignment. | |||||
Entries counting | |||||
count/size - returns count of dictionary entries. O(1) complexity.
| |||||
| size_t | count () const noexcept | ||||
| Number of entries. | |||||
| size_t | size () const noexcept | ||||
| Number of entries. | |||||
Key based getter interface | |||||
get - gets value by key O(n) complexity.
| |||||
| const char * | get (const char *key, int flags=0) const noexcept | ||||
| Value for a key. | |||||
| const char * | get (const std::string &key, int flags=0) const noexcept | ||||
| Value for a key. | |||||
| Public Member Functions inherited from FFWrapperPtr< AVDictionary > | |||||
| FFWrapperPtr ()=default | |||||
| Create an empty wrapper; isNull() is true. | |||||
| const AVDictionary * | raw () const | ||||
| Read access to the wrapped object. | |||||
| void | reset (AVDictionary *raw=nullptr) | ||||
| Replace the stored pointer. | |||||
| bool | isNull () const | ||||
| Whether the wrapper is empty. | |||||
| void | _log (int level, const char *fmt) const | ||||
| Log through the FFmpeg log system, using this wrapper as the context. | |||||
Additional Inherited Members | |
| Protected Attributes inherited from FFWrapperPtr< AVDictionary > | |
| AVDictionary * | m_raw |
| The wrapped pointer; owned by the derived class, not by this template. | |
It also add useful extensions, like:
This class also provide way to controll owning: you can create entity that does not owning data but provide access to them. You can drop owning by release() call.
|
explicit |
Useful to iterate with low-level FFmpeg API
| dict | dictionary to hold |
| takeOwning | ownershipping flag. If false, Dictionary only wraps access to the AVDictionary and do not free resources on destroy. |
| av::Dictionary::Dictionary | ( | const Dictionary & | other | ) |
Takes ownershipping on newly created dict.
| other |
| av::Dictionary::Dictionary | ( | Dictionary && | other | ) |
Other dictionary moves to uninited state. Ownershpping same to other.
| other |
| av::Dictionary::Dictionary | ( | std::initializer_list< std::pair< const char *, const char * > > | list, |
| int | flags = 0 ) |
New dictionary owning resources.
| list | init list |
| flags | see Flags |
|
noexcept |
If dict same to the olready holding one, but takeOwning is true and isOwning() false - takes owning. Otherwise do nothing.
| dict | dictionary to hold |
| takeOwning | owning flag |
| Iterator av::Dictionary::begin | ( | ) |
| ConstIterator av::Dictionary::begin | ( | ) | const |
| ConstIterator av::Dictionary::cbegin | ( | ) | const |
| ConstIterator av::Dictionary::cend | ( | ) | const |
|
noexcept |
If dictionary already exists, new fields will be addred. Entries with same keys will be overrided according to flags.
| other | dict to copy from |
| flags | see Flags |
|
noexcept |
| Iterator av::Dictionary::end | ( | ) |
| ConstIterator av::Dictionary::end | ( | ) | const |
|
noexcept |
| key | the key to look up |
| flags | a combination of AV_DICT_* lookup flags |
|
noexcept |
| key | the key to look up |
| flags | a combination of AV_DICT_* lookup flags |
|
noexcept |
| Dictionary & av::Dictionary::operator= | ( | const Dictionary & | rhs | ) |
Takes ownershipping on newly created dict. Old dict destroyed (resouces freed if there is ownershipping)
| rhs | the dictionary to copy |
| Dictionary & av::Dictionary::operator= | ( | Dictionary && | rhs | ) |
Rhs dictionary moves to uninited state. Ownershpping same to rhs. Old dict destroyed (resouces freed if there is ownershipping)
| rhs | the dictionary to move from |
| Dictionary & av::Dictionary::operator= | ( | std::initializer_list< std::pair< const char *, const char * > > | list | ) |
New dictionary owning resources. Old dictionary destroes (resource freed if owning)
| list | init list |
| const char * av::Dictionary::operator[] | ( | const char * | key | ) | const |
| key | the key to look up |
|
noexcept |
| key | the key to look up |
| Entry av::Dictionary::operator[] | ( | size_t | index | ) |
| index | zero-based position |
| const char * av::Dictionary::operator[] | ( | size_t | index | ) | const |
| index | zero-based position; the order is the dictionary order |
|
inline |
| str | string to process | |
| keyValSep | null-terminated string with chars that interprets as key and value separators '=' and ':' in most cases. | |
| pairsSep | null-terminates string with chars that interprets as pairs (key and value) separators. ';' and ',' in most cases. | |
| flags | See Flags. All flags that omit strdups ignores. | |
| [in,out] | ec | this represents the error status on exit, if this is pre-initialized to av::throws the function will throw on error instead |
|
noexcept |
| AVDictionary * av::Dictionary::release | ( | ) |
|
inline |
| [in] | key | key to change (can be std::string or char*) |
| [in] | value | key value (can be std::string, char* or integer) |
| [in,out] | ec | this represents the error status on exit, if this is pre-initialized to av::throws the function will throw on error instead |
| [in] | flags | see Flags |
|
noexcept |
|
noexcept |
| other |
| AvStringPtr av::Dictionary::toRawStringPtr | ( | const char | keyValSep, |
| const char | pairsSep, | ||
| OptionalErrorCode | ec = throws() ) const |
This method omit data copy and returns raw pointer that allocated by av_dict_get_string(). For more safety this block wrapped with no-overhead smart pointer (std::unique_ptr).
| [in] | keyValSep | char to separate key and value |
| [in] | pairsSep | chat to separate key-value pairs. |
| [in,out] | ec | this represents the error status on exit, if this is pre-initialized to av::throws the function will throw on error instead |
| std::string av::Dictionary::toString | ( | const char | keyValSep, |
| const char | pairsSep, | ||
| OptionalErrorCode | ec = throws() ) const |
This line can be processed via parseString() later.
FFmpeg internaly allocated buffer copies to the string and freed.
| [in] | keyValSep | char to separate key and value |
| [in] | pairsSep | chat to separate key-value pairs. |
| [in,out] | ec | this represents the error status on exit, if this is pre-initialized to av::throws the function will throw on error instead |