reference-settings.rst 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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. Get Functions
  81. -------------
  82. .. function:: const char *obs_data_get_string(obs_data_t *data, const char *name)
  83. ---------------------
  84. .. function:: long long obs_data_get_int(obs_data_t *data, const char *name)
  85. ---------------------
  86. .. function:: double obs_data_get_double(obs_data_t *data, const char *name)
  87. ---------------------
  88. .. function:: bool obs_data_get_bool(obs_data_t *data, const char *name)
  89. ---------------------
  90. .. function:: obs_data_t *obs_data_get_obj(obs_data_t *data, const char *name)
  91. :return: An incremented reference to a data object.
  92. ---------------------
  93. .. function:: obs_data_array_t *obs_data_get_array(obs_data_t *data, const char *name)
  94. :return: An incremented reference to a data array object.
  95. ---------------------
  96. Default Value Functions
  97. -----------------------
  98. Default values are used to determine what value will be given if a value
  99. is not set.
  100. .. function:: void obs_data_set_default_string(obs_data_t *data, const char *name, const char *val)
  101. const char *obs_data_get_default_string(obs_data_t *data, const char *name)
  102. ---------------------
  103. .. function:: void obs_data_set_default_int(obs_data_t *data, const char *name, long long val)
  104. long long obs_data_get_default_int(obs_data_t *data, const char *name)
  105. ---------------------
  106. .. function:: void obs_data_set_default_double(obs_data_t *data, const char *name, double val)
  107. double obs_data_get_default_double(obs_data_t *data, const char *name)
  108. ---------------------
  109. .. function:: void obs_data_set_default_bool(obs_data_t *data, const char *name, bool val)
  110. bool obs_data_get_default_bool(obs_data_t *data, const char *name)
  111. ---------------------
  112. .. function:: void obs_data_set_default_obj(obs_data_t *data, const char *name, obs_data_t *obj)
  113. obs_data_t *obs_data_get_default_obj(obs_data_t *data, const char *name)
  114. :return: An incremented reference to a data object.
  115. ---------------------
  116. Autoselect Functions
  117. --------------------
  118. Autoselect values are optionally used to determine what values should be
  119. used to ensure functionality if the currently set values are
  120. inappropriate or invalid.
  121. .. function:: void obs_data_set_autoselect_string(obs_data_t *data, const char *name, const char *val)
  122. const char *obs_data_get_autoselect_string(obs_data_t *data, const char *name)
  123. ---------------------
  124. .. function:: void obs_data_set_autoselect_int(obs_data_t *data, const char *name, long long val)
  125. long long obs_data_get_autoselect_int(obs_data_t *data, const char *name)
  126. ---------------------
  127. .. function:: void obs_data_set_autoselect_double(obs_data_t *data, const char *name, double val)
  128. double obs_data_get_autoselect_double(obs_data_t *data, const char *name)
  129. ---------------------
  130. .. function:: void obs_data_set_autoselect_bool(obs_data_t *data, const char *name, bool val)
  131. bool obs_data_get_autoselect_bool(obs_data_t *data, const char *name)
  132. ---------------------
  133. .. function:: void obs_data_set_autoselect_obj(obs_data_t *data, const char *name, obs_data_t *obj)
  134. obs_data_t *obs_data_get_autoselect_obj(obs_data_t *data, const char *name)
  135. :return: An incremented reference to a data object.
  136. ---------------------
  137. Array Functions
  138. ---------------
  139. .. function:: obs_data_array_t *obs_data_array_create()
  140. :return: A new reference to a data array object.
  141. ---------------------
  142. .. function:: void obs_data_array_addref(obs_data_array_t *array)
  143. ---------------------
  144. .. function:: void obs_data_array_release(obs_data_array_t *array)
  145. ---------------------
  146. .. function:: size_t obs_data_array_count(obs_data_array_t *array)
  147. ---------------------
  148. .. function:: obs_data_t *obs_data_array_item(obs_data_array_t *array, size_t idx)
  149. :return: An incremented reference to the data object associated with
  150. this array entry.
  151. ---------------------
  152. .. function:: size_t obs_data_array_push_back(obs_data_array_t *array, obs_data_t *obj)
  153. ---------------------
  154. .. function:: void obs_data_array_insert(obs_data_array_t *array, size_t idx, obs_data_t *obj)
  155. ---------------------
  156. .. function:: void obs_data_array_erase(obs_data_array_t *array, size_t idx)