aarch64: Add assembly support for -fsanitize=hwaddress tagged globals.
[libav.git] / libavutil / dict.h
blob3593e3abee9f96a7c30dff54130d22753dbcaed0
1 /*
2 * This file is part of Libav.
4 * Libav is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * Libav is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with Libav; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 /**
20 * @file
21 * Public dictionary API.
24 #ifndef AVUTIL_DICT_H
25 #define AVUTIL_DICT_H
27 /**
28 * @addtogroup lavu_dict AVDictionary
29 * @ingroup lavu_data
31 * @brief Simple key:value store
33 * @{
34 * Dictionaries are used for storing key:value pairs. To create
35 * an AVDictionary, simply pass an address of a NULL pointer to
36 * av_dict_set(). NULL can be used as an empty dictionary wherever
37 * a pointer to an AVDictionary is required.
38 * Use av_dict_get() to retrieve an entry or iterate over all
39 * entries and finally av_dict_free() to free the dictionary
40 * and all its contents.
42 @code
43 AVDictionary *d = NULL; // "create" an empty dictionary
44 AVDictionaryEntry *t = NULL;
46 av_dict_set(&d, "foo", "bar", 0); // add an entry
48 char *k = av_strdup("key"); // if your strings are already allocated,
49 char *v = av_strdup("value"); // you can avoid copying them like this
50 av_dict_set(&d, k, v, AV_DICT_DONT_STRDUP_KEY | AV_DICT_DONT_STRDUP_VAL);
52 while (t = av_dict_get(d, "", t, AV_DICT_IGNORE_SUFFIX)) {
53 <....> // iterate over all entries in d
55 av_dict_free(&d);
56 @endcode
59 #define AV_DICT_MATCH_CASE 1
60 #define AV_DICT_IGNORE_SUFFIX 2
61 #define AV_DICT_DONT_STRDUP_KEY 4 /**< Take ownership of a key that's been
62 allocated with av_malloc() and children. */
63 #define AV_DICT_DONT_STRDUP_VAL 8 /**< Take ownership of a value that's been
64 allocated with av_malloc() and children. */
65 #define AV_DICT_DONT_OVERWRITE 16 ///< Don't overwrite existing entries.
66 #define AV_DICT_APPEND 32 /**< If the entry already exists, append to it. Note that no
67 delimiter is added, the strings are simply concatenated. */
69 typedef struct AVDictionaryEntry {
70 char *key;
71 char *value;
72 } AVDictionaryEntry;
74 typedef struct AVDictionary AVDictionary;
76 /**
77 * Get a dictionary entry with matching key.
79 * @param prev Set to the previous matching element to find the next.
80 * If set to NULL the first matching element is returned.
81 * @param flags Allows case as well as suffix-insensitive comparisons.
82 * @return Found entry or NULL, changing key or value leads to undefined behavior.
84 AVDictionaryEntry *av_dict_get(const AVDictionary *m, const char *key,
85 const AVDictionaryEntry *prev, int flags);
87 /**
88 * Get number of entries in dictionary.
90 * @param m dictionary
91 * @return number of entries in dictionary
93 int av_dict_count(const AVDictionary *m);
95 /**
96 * Set the given entry in *pm, overwriting an existing entry.
98 * @param pm pointer to a pointer to a dictionary struct. If *pm is NULL
99 * a dictionary struct is allocated and put in *pm.
100 * @param key entry key to add to *pm (will be av_strduped depending on flags)
101 * @param value entry value to add to *pm (will be av_strduped depending on flags).
102 * Passing a NULL value will cause an existing entry to be deleted.
103 * @return >= 0 on success otherwise an error code <0
105 int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags);
108 * Parse the key/value pairs list and add to a dictionary.
110 * @param key_val_sep a 0-terminated list of characters used to separate
111 * key from value
112 * @param pairs_sep a 0-terminated list of characters used to separate
113 * two pairs from each other
114 * @param flags flags to use when adding to dictionary.
115 * AV_DICT_DONT_STRDUP_KEY and AV_DICT_DONT_STRDUP_VAL
116 * are ignored since the key/value tokens will always
117 * be duplicated.
118 * @return 0 on success, negative AVERROR code on failure
120 int av_dict_parse_string(AVDictionary **pm, const char *str,
121 const char *key_val_sep, const char *pairs_sep,
122 int flags);
125 * Copy entries from one AVDictionary struct into another.
126 * @param dst pointer to a pointer to a AVDictionary struct. If *dst is NULL,
127 * this function will allocate a struct for you and put it in *dst
128 * @param src pointer to source AVDictionary struct
129 * @param flags flags to use when setting entries in *dst
130 * @note metadata is read using the AV_DICT_IGNORE_SUFFIX flag
131 * @return 0 on success, negative AVERROR code on failure. If dst was allocated
132 * by this function, callers should free the associated memory.
134 int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags);
137 * Free all the memory allocated for an AVDictionary struct
138 * and all keys and values.
140 void av_dict_free(AVDictionary **m);
143 * @}
146 #endif /* AVUTIL_DICT_H */