reference-settings.rst 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. Data Settings API Reference (obs_data_t)
  2. ========================================
  3. Data settings objects are reference-counted objects that store values in
  4. a string-table or array. They're similar to Json objects, but
  5. additionally allow additional functionality such as default or
  6. auto-selection values. Data is saved/loaded to/from Json text and Json
  7. text files.
  8. .. type:: obs_data_t
  9. A reference-counted data object.
  10. .. type:: obs_data_array_t
  11. A reference-counted data array object.
  12. .. code:: cpp
  13. #include <obs.h>
  14. General Functions
  15. -----------------
  16. .. function:: obs_data_t *obs_data_create()
  17. :return: A new reference to a data object. Release with
  18. :c:func:`obs_data_release()`.
  19. ---------------------
  20. .. function:: obs_data_t *obs_data_create_from_json(const char *json_string)
  21. Creates a data object from a Json string.
  22. :param json_string: Json string
  23. :return: A new reference to a data object. Release with
  24. :c:func:`obs_data_release()`.
  25. ---------------------
  26. .. function:: obs_data_t *obs_data_create_from_json_file(const char *json_file)
  27. Creates a data object from a Json file.
  28. :param json_file: Json file path
  29. :return: A new reference to a data object. Release with
  30. :c:func:`obs_data_release()`.
  31. ---------------------
  32. .. function:: obs_data_t *obs_data_create_from_json_file_safe(const char *json_file, const char *backup_ext)
  33. Creates a data object from a Json file, with a backup file in case
  34. the original is corrupted or fails to load.
  35. :param json_file: Json file path
  36. :param backup_ext: Backup file extension
  37. :return: A new reference to a data object. Release with
  38. :c:func:`obs_data_release()`.
  39. ---------------------
  40. .. function:: void obs_data_addref(obs_data_t *data)
  41. void obs_data_release(obs_data_t *data)
  42. Adds/releases a reference to a data object.
  43. ---------------------
  44. .. function:: const char *obs_data_get_json(obs_data_t *data)
  45. Generates a new json string. The string allocation is stored within
  46. the data object itself, and does not need to be manually freed.
  47. :return: Json string for this object
  48. ---------------------
  49. .. function:: const char *obs_data_get_json_with_defaults(obs_data_t *data)
  50. Same as :c:func:`obs_data_get_json()` but default values are also serialized.
  51. :return: Json string for this object
  52. ---------------------
  53. .. function:: const char *obs_data_get_json_pretty(obs_data_t *data)
  54. Same as :c:func:`obs_data_get_json()` but the JSON data is pretty-printed.
  55. :return: Json string for this object
  56. ---------------------
  57. .. function:: const char *obs_data_get_json_pretty_with_defaults(obs_data_t *data)
  58. Same as :c:func:`obs_data_get_json_pretty()` but default values are also serialized.
  59. :return: Json string for this object
  60. ---------------------
  61. .. function:: const char *obs_data_get_last_json(obs_data_t *data)
  62. Returns the last json string generated for this data object. Does not
  63. generate a new string. Use :c:func:`obs_data_get_json()` to generate
  64. a json string first.
  65. :return: Json string for this object
  66. ---------------------
  67. .. function:: bool obs_data_save_json(obs_data_t *data, const char *file)
  68. Saves the data to a file as Json text.
  69. :param file: The file to save to
  70. :return: *true* if successful, *false* otherwise
  71. ---------------------
  72. .. function:: bool obs_data_save_json_safe(obs_data_t *data, const char *file, const char *temp_ext, const char *backup_ext)
  73. Saves the data to a file as Json text, and if overwriting an old
  74. file, backs up that old file to help prevent potential file
  75. corruption.
  76. :param file: The file to save to
  77. :param backup_ext: The backup extension to use for the overwritten
  78. file if it exists
  79. :return: *true* if successful, *false* otherwise
  80. ---------------------
  81. .. function:: void obs_data_apply(obs_data_t *target, obs_data_t *apply_data)
  82. Merges the data of *apply_data* in to *target*.
  83. ---------------------
  84. .. function:: void obs_data_erase(obs_data_t *data, const char *name)
  85. Erases the user data for item *name* within the data object.
  86. ---------------------
  87. .. function:: void obs_data_clear(obs_data_t *data)
  88. Clears all user data in the data object.
  89. ---------------------
  90. Set Functions
  91. -------------
  92. .. function:: void obs_data_set_string(obs_data_t *data, const char *name, const char *val)
  93. ---------------------
  94. .. function:: void obs_data_set_int(obs_data_t *data, const char *name, long long val)
  95. ---------------------
  96. .. function:: void obs_data_set_double(obs_data_t *data, const char *name, double val)
  97. ---------------------
  98. .. function:: void obs_data_set_bool(obs_data_t *data, const char *name, bool val)
  99. ---------------------
  100. .. function:: void obs_data_set_obj(obs_data_t *data, const char *name, obs_data_t *obj)
  101. ---------------------
  102. .. function:: void obs_data_set_array(obs_data_t *data, const char *name, obs_data_array_t *array)
  103. ---------------------
  104. .. _obs_data_get_funcs:
  105. Get Functions
  106. -------------
  107. .. function:: const char *obs_data_get_string(obs_data_t *data, const char *name)
  108. ---------------------
  109. .. function:: long long obs_data_get_int(obs_data_t *data, const char *name)
  110. ---------------------
  111. .. function:: double obs_data_get_double(obs_data_t *data, const char *name)
  112. ---------------------
  113. .. function:: bool obs_data_get_bool(obs_data_t *data, const char *name)
  114. ---------------------
  115. .. function:: obs_data_t *obs_data_get_obj(obs_data_t *data, const char *name)
  116. :return: An incremented reference to a data object. Release with
  117. :c:func:`obs_data_release()`.
  118. ---------------------
  119. .. function:: obs_data_array_t *obs_data_get_array(obs_data_t *data, const char *name)
  120. :return: An incremented reference to a data array object. Release
  121. with :c:func:`obs_data_array_release()`.
  122. ---------------------
  123. .. _obs_data_default_funcs:
  124. Default Value Functions
  125. -----------------------
  126. Default values are used to determine what value will be given if a value
  127. is not set.
  128. .. function:: obs_data_t *obs_data_get_defaults(obs_data_t *data);
  129. :return: obs_data_t * with all default values (recursively for all objects as well).
  130. -----------------------
  131. .. function:: void obs_data_set_default_string(obs_data_t *data, const char *name, const char *val)
  132. const char *obs_data_get_default_string(obs_data_t *data, const char *name)
  133. ---------------------
  134. .. function:: void obs_data_set_default_int(obs_data_t *data, const char *name, long long val)
  135. long long obs_data_get_default_int(obs_data_t *data, const char *name)
  136. ---------------------
  137. .. function:: void obs_data_set_default_double(obs_data_t *data, const char *name, double val)
  138. double obs_data_get_default_double(obs_data_t *data, const char *name)
  139. ---------------------
  140. .. function:: void obs_data_set_default_bool(obs_data_t *data, const char *name, bool val)
  141. bool obs_data_get_default_bool(obs_data_t *data, const char *name)
  142. ---------------------
  143. .. function:: void obs_data_set_default_obj(obs_data_t *data, const char *name, obs_data_t *obj)
  144. obs_data_t *obs_data_get_default_obj(obs_data_t *data, const char *name)
  145. :return: An incremented reference to a data object. Release with
  146. :c:func:`obs_data_release()`.
  147. ----------------------
  148. .. function:: void obs_data_set_default_array(obs_data_t *data, const char *name, obs_data_array_t *arr)
  149. obs_data_array_t *obs_data_get_default_array(obs_data_t *data, const char *name)
  150. Autoselect Functions
  151. --------------------
  152. Autoselect values are optionally used to determine what values should be
  153. used to ensure functionality if the currently set values are
  154. inappropriate or invalid.
  155. .. function:: void obs_data_set_autoselect_string(obs_data_t *data, const char *name, const char *val)
  156. const char *obs_data_get_autoselect_string(obs_data_t *data, const char *name)
  157. ---------------------
  158. .. function:: void obs_data_set_autoselect_int(obs_data_t *data, const char *name, long long val)
  159. long long obs_data_get_autoselect_int(obs_data_t *data, const char *name)
  160. ---------------------
  161. .. function:: void obs_data_set_autoselect_double(obs_data_t *data, const char *name, double val)
  162. double obs_data_get_autoselect_double(obs_data_t *data, const char *name)
  163. ---------------------
  164. .. function:: void obs_data_set_autoselect_bool(obs_data_t *data, const char *name, bool val)
  165. bool obs_data_get_autoselect_bool(obs_data_t *data, const char *name)
  166. ---------------------
  167. .. function:: void obs_data_set_autoselect_obj(obs_data_t *data, const char *name, obs_data_t *obj)
  168. obs_data_t *obs_data_get_autoselect_obj(obs_data_t *data, const char *name)
  169. :return: An incremented reference to a data object. Release with
  170. :c:func:`obs_data_release()`.
  171. ---------------------
  172. .. function:: void obs_data_set_autoselect_array(obs_data_t *data, const char *name, obs_data_array_t *arr)
  173. obs_data_array_t *obs_data_get_autoselect_array(obs_data_t *data, const char *name)
  174. :return: An incremented reference to a data array object. Release
  175. with :c:func:`obs_data_array_release()`.
  176. .. versionadded:: 30.1
  177. ---------------------
  178. Array Functions
  179. ---------------
  180. .. function:: obs_data_array_t *obs_data_array_create()
  181. :return: A new reference to a data array object. Release
  182. with :c:func:`obs_data_array_release()`.
  183. ---------------------
  184. .. function:: void obs_data_array_addref(obs_data_array_t *array)
  185. ---------------------
  186. .. function:: void obs_data_array_release(obs_data_array_t *array)
  187. ---------------------
  188. .. function:: size_t obs_data_array_count(obs_data_array_t *array)
  189. ---------------------
  190. .. function:: obs_data_t *obs_data_array_item(obs_data_array_t *array, size_t idx)
  191. :return: An incremented reference to the data object associated with
  192. this array entry. Release with :c:func:`obs_data_release()`.
  193. ---------------------
  194. .. function:: size_t obs_data_array_push_back(obs_data_array_t *array, obs_data_t *obj)
  195. ---------------------
  196. .. function:: void obs_data_array_insert(obs_data_array_t *array, size_t idx, obs_data_t *obj)
  197. ---------------------
  198. .. function:: void obs_data_array_erase(obs_data_array_t *array, size_t idx)