reference-settings.rst 7.9 KB

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