reference-settings.rst 8.7 KB

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