You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

147 lines
5.4KB

  1. /*
  2. * This file is part of Libav.
  3. *
  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.
  8. *
  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.
  13. *
  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
  17. */
  18. /**
  19. * @file
  20. * Public dictionary API.
  21. */
  22. #ifndef AVUTIL_DICT_H
  23. #define AVUTIL_DICT_H
  24. /**
  25. * @addtogroup lavu_dict AVDictionary
  26. * @ingroup lavu_data
  27. *
  28. * @brief Simple key:value store
  29. *
  30. * @{
  31. * Dictionaries are used for storing key:value pairs. To create
  32. * an AVDictionary, simply pass an address of a NULL pointer to
  33. * av_dict_set(). NULL can be used as an empty dictionary wherever
  34. * a pointer to an AVDictionary is required.
  35. * Use av_dict_get() to retrieve an entry or iterate over all
  36. * entries and finally av_dict_free() to free the dictionary
  37. * and all its contents.
  38. *
  39. @code
  40. AVDictionary *d = NULL; // "create" an empty dictionary
  41. AVDictionaryEntry *t = NULL;
  42. av_dict_set(&d, "foo", "bar", 0); // add an entry
  43. char *k = av_strdup("key"); // if your strings are already allocated,
  44. char *v = av_strdup("value"); // you can avoid copying them like this
  45. av_dict_set(&d, k, v, AV_DICT_DONT_STRDUP_KEY | AV_DICT_DONT_STRDUP_VAL);
  46. while (t = av_dict_get(d, "", t, AV_DICT_IGNORE_SUFFIX)) {
  47. <....> // iterate over all entries in d
  48. }
  49. av_dict_free(&d);
  50. @endcode
  51. */
  52. #define AV_DICT_MATCH_CASE 1
  53. #define AV_DICT_IGNORE_SUFFIX 2
  54. #define AV_DICT_DONT_STRDUP_KEY 4 /**< Take ownership of a key that's been
  55. allocated with av_malloc() and children. */
  56. #define AV_DICT_DONT_STRDUP_VAL 8 /**< Take ownership of a value that's been
  57. allocated with av_malloc() and children. */
  58. #define AV_DICT_DONT_OVERWRITE 16 ///< Don't overwrite existing entries.
  59. #define AV_DICT_APPEND 32 /**< If the entry already exists, append to it. Note that no
  60. delimiter is added, the strings are simply concatenated. */
  61. typedef struct AVDictionaryEntry {
  62. char *key;
  63. char *value;
  64. } AVDictionaryEntry;
  65. typedef struct AVDictionary AVDictionary;
  66. /**
  67. * Get a dictionary entry with matching key.
  68. *
  69. * @param prev Set to the previous matching element to find the next.
  70. * If set to NULL the first matching element is returned.
  71. * @param flags Allows case as well as suffix-insensitive comparisons.
  72. * @return Found entry or NULL, changing key or value leads to undefined behavior.
  73. */
  74. AVDictionaryEntry *av_dict_get(const AVDictionary *m, const char *key,
  75. const AVDictionaryEntry *prev, int flags);
  76. /**
  77. * Get number of entries in dictionary.
  78. *
  79. * @param m dictionary
  80. * @return number of entries in dictionary
  81. */
  82. int av_dict_count(const AVDictionary *m);
  83. /**
  84. * Set the given entry in *pm, overwriting an existing entry.
  85. *
  86. * @param pm pointer to a pointer to a dictionary struct. If *pm is NULL
  87. * a dictionary struct is allocated and put in *pm.
  88. * @param key entry key to add to *pm (will be av_strduped depending on flags)
  89. * @param value entry value to add to *pm (will be av_strduped depending on flags).
  90. * Passing a NULL value will cause an existing entry to be deleted.
  91. * @return >= 0 on success otherwise an error code <0
  92. */
  93. int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags);
  94. /**
  95. * Parse the key/value pairs list and add to a dictionary.
  96. *
  97. * @param key_val_sep a 0-terminated list of characters used to separate
  98. * key from value
  99. * @param pairs_sep a 0-terminated list of characters used to separate
  100. * two pairs from each other
  101. * @param flags flags to use when adding to dictionary.
  102. * AV_DICT_DONT_STRDUP_KEY and AV_DICT_DONT_STRDUP_VAL
  103. * are ignored since the key/value tokens will always
  104. * be duplicated.
  105. * @return 0 on success, negative AVERROR code on failure
  106. */
  107. int av_dict_parse_string(AVDictionary **pm, const char *str,
  108. const char *key_val_sep, const char *pairs_sep,
  109. int flags);
  110. /**
  111. * Copy entries from one AVDictionary struct into another.
  112. * @param dst pointer to a pointer to a AVDictionary struct. If *dst is NULL,
  113. * this function will allocate a struct for you and put it in *dst
  114. * @param src pointer to source AVDictionary struct
  115. * @param flags flags to use when setting entries in *dst
  116. * @note metadata is read using the AV_DICT_IGNORE_SUFFIX flag
  117. * @return 0 on success, negative AVERROR code on failure. If dst was allocated
  118. * by this function, callers should free the associated memory.
  119. */
  120. int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags);
  121. /**
  122. * Free all the memory allocated for an AVDictionary struct
  123. * and all keys and values.
  124. */
  125. void av_dict_free(AVDictionary **m);
  126. /**
  127. * @}
  128. */
  129. #endif /* AVUTIL_DICT_H */