1
0

reference-settings.rst 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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_last_json(obs_data_t *data)
  50. Returns the last json string generated for this data object. Does not
  51. generate a new string. Use :c:func:`obs_data_get_json()` to generate
  52. a json string first.
  53. :return: Json string for this object
  54. ---------------------
  55. .. function:: bool obs_data_save_json(obs_data_t *data, const char *file)
  56. Saves the data to a file as Json text.
  57. :param file: The file to save to
  58. :return: *true* if successful, *false* otherwise
  59. ---------------------
  60. .. function:: bool obs_data_save_json_safe(obs_data_t *data, const char *file, const char *temp_ext, const char *backup_ext)
  61. Saves the data to a file as Json text, and if overwriting an old
  62. file, backs up that old file to help prevent potential file
  63. corruption.
  64. :param file: The file to save to
  65. :param backup_ext: The backup extension to use for the overwritten
  66. file if it exists
  67. :return: *true* if successful, *false* otherwise
  68. ---------------------
  69. .. function:: void obs_data_apply(obs_data_t *target, obs_data_t *apply_data)
  70. Merges the data of *apply_data* in to *target*.
  71. ---------------------
  72. .. function:: void obs_data_erase(obs_data_t *data, const char *name)
  73. Erases the user data for item *name* within the data object.
  74. ---------------------
  75. .. function:: void obs_data_clear(obs_data_t *data)
  76. Clears all user data in the data object.
  77. ---------------------
  78. Set Functions
  79. -------------
  80. .. function:: void obs_data_set_string(obs_data_t *data, const char *name, const char *val)
  81. ---------------------
  82. .. function:: void obs_data_set_int(obs_data_t *data, const char *name, long long val)
  83. ---------------------
  84. .. function:: void obs_data_set_double(obs_data_t *data, const char *name, double val)
  85. ---------------------
  86. .. function:: void obs_data_set_bool(obs_data_t *data, const char *name, bool val)
  87. ---------------------
  88. .. function:: void obs_data_set_obj(obs_data_t *data, const char *name, obs_data_t *obj)
  89. ---------------------
  90. .. function:: void obs_data_set_array(obs_data_t *data, const char *name, obs_data_array_t *array)
  91. ---------------------
  92. .. _obs_data_get_funcs:
  93. Get Functions
  94. -------------
  95. .. function:: const char *obs_data_get_string(obs_data_t *data, const char *name)
  96. ---------------------
  97. .. function:: long long obs_data_get_int(obs_data_t *data, const char *name)
  98. ---------------------
  99. .. function:: double obs_data_get_double(obs_data_t *data, const char *name)
  100. ---------------------
  101. .. function:: bool obs_data_get_bool(obs_data_t *data, const char *name)
  102. ---------------------
  103. .. function:: obs_data_t *obs_data_get_obj(obs_data_t *data, const char *name)
  104. :return: An incremented reference to a data object. Release with
  105. :c:func:`obs_data_release()`.
  106. ---------------------
  107. .. function:: obs_data_array_t *obs_data_get_array(obs_data_t *data, const char *name)
  108. :return: An incremented reference to a data array object. Release
  109. with :c:func:`obs_data_array_release()`.
  110. ---------------------
  111. .. _obs_data_default_funcs:
  112. Default Value Functions
  113. -----------------------
  114. Default values are used to determine what value will be given if a value
  115. is not set.
  116. .. function:: obs_data_t *obs_data_get_defaults(obs_data_t *data);
  117. :return: obs_data_t * with all default values (recursively for all objects as well).
  118. -----------------------
  119. .. function:: void obs_data_set_default_string(obs_data_t *data, const char *name, const char *val)
  120. const char *obs_data_get_default_string(obs_data_t *data, const char *name)
  121. ---------------------
  122. .. function:: void obs_data_set_default_int(obs_data_t *data, const char *name, long long val)
  123. long long obs_data_get_default_int(obs_data_t *data, const char *name)
  124. ---------------------
  125. .. function:: void obs_data_set_default_double(obs_data_t *data, const char *name, double val)
  126. double obs_data_get_default_double(obs_data_t *data, const char *name)
  127. ---------------------
  128. .. function:: void obs_data_set_default_bool(obs_data_t *data, const char *name, bool val)
  129. bool obs_data_get_default_bool(obs_data_t *data, const char *name)
  130. ---------------------
  131. .. function:: void obs_data_set_default_obj(obs_data_t *data, const char *name, obs_data_t *obj)
  132. obs_data_t *obs_data_get_default_obj(obs_data_t *data, const char *name)
  133. :return: An incremented reference to a data object. Release with
  134. :c:func:`obs_data_release()`.
  135. ----------------------
  136. .. function:: void obs_data_set_default_array(obs_data_t *data, const char *name, obs_data_array_t *arr)
  137. obs_data_array_t *obs_data_get_default_array(obs_data_t *data, const char *name)
  138. Autoselect Functions
  139. --------------------
  140. Autoselect values are optionally used to determine what values should be
  141. used to ensure functionality if the currently set values are
  142. inappropriate or invalid.
  143. .. function:: void obs_data_set_autoselect_string(obs_data_t *data, const char *name, const char *val)
  144. const char *obs_data_get_autoselect_string(obs_data_t *data, const char *name)
  145. ---------------------
  146. .. function:: void obs_data_set_autoselect_int(obs_data_t *data, const char *name, long long val)
  147. long long obs_data_get_autoselect_int(obs_data_t *data, const char *name)
  148. ---------------------
  149. .. function:: void obs_data_set_autoselect_double(obs_data_t *data, const char *name, double val)
  150. double obs_data_get_autoselect_double(obs_data_t *data, const char *name)
  151. ---------------------
  152. .. function:: void obs_data_set_autoselect_bool(obs_data_t *data, const char *name, bool val)
  153. bool obs_data_get_autoselect_bool(obs_data_t *data, const char *name)
  154. ---------------------
  155. .. function:: void obs_data_set_autoselect_obj(obs_data_t *data, const char *name, obs_data_t *obj)
  156. obs_data_t *obs_data_get_autoselect_obj(obs_data_t *data, const char *name)
  157. :return: An incremented reference to a data object. Release with
  158. :c:func:`obs_data_release()`.
  159. ---------------------
  160. Array Functions
  161. ---------------
  162. .. function:: obs_data_array_t *obs_data_array_create()
  163. :return: A new reference to a data array object. Release
  164. with :c:func:`obs_data_array_release()`.
  165. ---------------------
  166. .. function:: void obs_data_array_addref(obs_data_array_t *array)
  167. ---------------------
  168. .. function:: void obs_data_array_release(obs_data_array_t *array)
  169. ---------------------
  170. .. function:: size_t obs_data_array_count(obs_data_array_t *array)
  171. ---------------------
  172. .. function:: obs_data_t *obs_data_array_item(obs_data_array_t *array, size_t idx)
  173. :return: An incremented reference to the data object associated with
  174. this array entry. Release with :c:func:`obs_data_release()`.
  175. ---------------------
  176. .. function:: size_t obs_data_array_push_back(obs_data_array_t *array, obs_data_t *obj)
  177. ---------------------
  178. .. function:: void obs_data_array_insert(obs_data_array_t *array, size_t idx, obs_data_t *obj)
  179. ---------------------
  180. .. function:: void obs_data_array_erase(obs_data_array_t *array, size_t idx)