annotate ffmpeg/libavutil/dict.h @ 13:844d341cf643 tip

Back up before ISMIR
author Yading Song <yading.song@eecs.qmul.ac.uk>
date Thu, 31 Oct 2013 13:17:06 +0000
parents f445c3017523
children
rev   line source
yading@11 1 /*
yading@11 2 *
yading@11 3 * This file is part of FFmpeg.
yading@11 4 *
yading@11 5 * FFmpeg is free software; you can redistribute it and/or
yading@11 6 * modify it under the terms of the GNU Lesser General Public
yading@11 7 * License as published by the Free Software Foundation; either
yading@11 8 * version 2.1 of the License, or (at your option) any later version.
yading@11 9 *
yading@11 10 * FFmpeg is distributed in the hope that it will be useful,
yading@11 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
yading@11 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
yading@11 13 * Lesser General Public License for more details.
yading@11 14 *
yading@11 15 * You should have received a copy of the GNU Lesser General Public
yading@11 16 * License along with FFmpeg; if not, write to the Free Software
yading@11 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
yading@11 18 */
yading@11 19
yading@11 20 /**
yading@11 21 * @file
yading@11 22 * Public dictionary API.
yading@11 23 * @deprecated
yading@11 24 * AVDictionary is provided for compatibility with libav. It is both in
yading@11 25 * implementation as well as API inefficient. It does not scale and is
yading@11 26 * extremely slow with large dictionaries.
yading@11 27 * It is recommended that new code uses our tree container from tree.c/h
yading@11 28 * where applicable, which uses AVL trees to achieve O(log n) performance.
yading@11 29 */
yading@11 30
yading@11 31 #ifndef AVUTIL_DICT_H
yading@11 32 #define AVUTIL_DICT_H
yading@11 33
yading@11 34 /**
yading@11 35 * @addtogroup lavu_dict AVDictionary
yading@11 36 * @ingroup lavu_data
yading@11 37 *
yading@11 38 * @brief Simple key:value store
yading@11 39 *
yading@11 40 * @{
yading@11 41 * Dictionaries are used for storing key:value pairs. To create
yading@11 42 * an AVDictionary, simply pass an address of a NULL pointer to
yading@11 43 * av_dict_set(). NULL can be used as an empty dictionary wherever
yading@11 44 * a pointer to an AVDictionary is required.
yading@11 45 * Use av_dict_get() to retrieve an entry or iterate over all
yading@11 46 * entries and finally av_dict_free() to free the dictionary
yading@11 47 * and all its contents.
yading@11 48 *
yading@11 49 * @code
yading@11 50 * AVDictionary *d = NULL; // "create" an empty dictionary
yading@11 51 * av_dict_set(&d, "foo", "bar", 0); // add an entry
yading@11 52 *
yading@11 53 * char *k = av_strdup("key"); // if your strings are already allocated,
yading@11 54 * char *v = av_strdup("value"); // you can avoid copying them like this
yading@11 55 * av_dict_set(&d, k, v, AV_DICT_DONT_STRDUP_KEY | AV_DICT_DONT_STRDUP_VAL);
yading@11 56 *
yading@11 57 * AVDictionaryEntry *t = NULL;
yading@11 58 * while (t = av_dict_get(d, "", t, AV_DICT_IGNORE_SUFFIX)) {
yading@11 59 * <....> // iterate over all entries in d
yading@11 60 * }
yading@11 61 *
yading@11 62 * av_dict_free(&d);
yading@11 63 * @endcode
yading@11 64 *
yading@11 65 */
yading@11 66
yading@11 67 #define AV_DICT_MATCH_CASE 1
yading@11 68 #define AV_DICT_IGNORE_SUFFIX 2
yading@11 69 #define AV_DICT_DONT_STRDUP_KEY 4 /**< Take ownership of a key that's been
yading@11 70 allocated with av_malloc() and children. */
yading@11 71 #define AV_DICT_DONT_STRDUP_VAL 8 /**< Take ownership of a value that's been
yading@11 72 allocated with av_malloc() and chilren. */
yading@11 73 #define AV_DICT_DONT_OVERWRITE 16 ///< Don't overwrite existing entries.
yading@11 74 #define AV_DICT_APPEND 32 /**< If the entry already exists, append to it. Note that no
yading@11 75 delimiter is added, the strings are simply concatenated. */
yading@11 76
yading@11 77 typedef struct AVDictionaryEntry {
yading@11 78 char *key;
yading@11 79 char *value;
yading@11 80 } AVDictionaryEntry;
yading@11 81
yading@11 82 typedef struct AVDictionary AVDictionary;
yading@11 83
yading@11 84 /**
yading@11 85 * Get a dictionary entry with matching key.
yading@11 86 *
yading@11 87 * @param prev Set to the previous matching element to find the next.
yading@11 88 * If set to NULL the first matching element is returned.
yading@11 89 * @param flags Allows case as well as suffix-insensitive comparisons.
yading@11 90 * @return Found entry or NULL, changing key or value leads to undefined behavior.
yading@11 91 */
yading@11 92 AVDictionaryEntry *
yading@11 93 av_dict_get(AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags);
yading@11 94
yading@11 95 /**
yading@11 96 * Get number of entries in dictionary.
yading@11 97 *
yading@11 98 * @param m dictionary
yading@11 99 * @return number of entries in dictionary
yading@11 100 */
yading@11 101 int av_dict_count(const AVDictionary *m);
yading@11 102
yading@11 103 /**
yading@11 104 * Set the given entry in *pm, overwriting an existing entry.
yading@11 105 *
yading@11 106 * @param pm pointer to a pointer to a dictionary struct. If *pm is NULL
yading@11 107 * a dictionary struct is allocated and put in *pm.
yading@11 108 * @param key entry key to add to *pm (will be av_strduped depending on flags)
yading@11 109 * @param value entry value to add to *pm (will be av_strduped depending on flags).
yading@11 110 * Passing a NULL value will cause an existing entry to be deleted.
yading@11 111 * @return >= 0 on success otherwise an error code <0
yading@11 112 */
yading@11 113 int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags);
yading@11 114
yading@11 115 /**
yading@11 116 * Parse the key/value pairs list and add to a dictionary.
yading@11 117 *
yading@11 118 * @param key_val_sep a 0-terminated list of characters used to separate
yading@11 119 * key from value
yading@11 120 * @param pairs_sep a 0-terminated list of characters used to separate
yading@11 121 * two pairs from each other
yading@11 122 * @param flags flags to use when adding to dictionary.
yading@11 123 * AV_DICT_DONT_STRDUP_KEY and AV_DICT_DONT_STRDUP_VAL
yading@11 124 * are ignored since the key/value tokens will always
yading@11 125 * be duplicated.
yading@11 126 * @return 0 on success, negative AVERROR code on failure
yading@11 127 */
yading@11 128 int av_dict_parse_string(AVDictionary **pm, const char *str,
yading@11 129 const char *key_val_sep, const char *pairs_sep,
yading@11 130 int flags);
yading@11 131
yading@11 132 /**
yading@11 133 * Copy entries from one AVDictionary struct into another.
yading@11 134 * @param dst pointer to a pointer to a AVDictionary struct. If *dst is NULL,
yading@11 135 * this function will allocate a struct for you and put it in *dst
yading@11 136 * @param src pointer to source AVDictionary struct
yading@11 137 * @param flags flags to use when setting entries in *dst
yading@11 138 * @note metadata is read using the AV_DICT_IGNORE_SUFFIX flag
yading@11 139 */
yading@11 140 void av_dict_copy(AVDictionary **dst, AVDictionary *src, int flags);
yading@11 141
yading@11 142 /**
yading@11 143 * Free all the memory allocated for an AVDictionary struct
yading@11 144 * and all keys and values.
yading@11 145 */
yading@11 146 void av_dict_free(AVDictionary **m);
yading@11 147
yading@11 148 /**
yading@11 149 * @}
yading@11 150 */
yading@11 151
yading@11 152 #endif /* AVUTIL_DICT_H */