re84.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  5. <title>&lt;GVariantBuilder&gt;: </title>
  6. <meta name="generator" content="DocBook XSL Stylesheets V1.79.2">
  7. <link rel="home" href="index.html" title="">
  8. <link rel="up" href="ch01.html" title="GLib">
  9. <link rel="prev" href="re83.html" title="&lt;GVariant&gt;">
  10. <link rel="next" href="re85.html" title="&lt;%GLibVariantClass&gt;">
  11. <meta name="generator" content="GTK-Doc V1.33.1 (XML mode)">
  12. <link rel="stylesheet" href="style.css" type="text/css">
  13. </head>
  14. <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
  15. <table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="5"><tr valign="middle">
  16. <td width="100%" align="left" class="shortcuts"></td>
  17. <td><a accesskey="h" href="index.html"><img src="home.png" width="16" height="16" border="0" alt="Home"></a></td>
  18. <td><img src="up-insensitive.png" width="16" height="16" border="0"></td>
  19. <td><a accesskey="p" href="re83.html"><img src="left.png" width="16" height="16" border="0" alt="Prev"></a></td>
  20. <td><a accesskey="n" href="re85.html"><img src="right.png" width="16" height="16" border="0" alt="Next"></a></td>
  21. </tr></table>
  22. <div class="refentry">
  23. <a name="id-1.1.85"></a><div class="titlepage"></div>
  24. <div class="refnamediv">
  25. <h2>&lt;GVariantBuilder&gt;</h2>
  26. <p>&lt;GVariantBuilder&gt;</p>
  27. </div>
  28. <div class="refsect1">
  29. <a name="id-1.1.85.2"></a><h2>Description</h2>
  30. <p>A utility type for constructing container-type <span class="type">GVariant</span> instances.
  31. </p>
  32. <p>This is an opaque structure and may only be accessed using the
  33. following functions.
  34. </p>
  35. <p><span class="type">GVariantBuilder</span> is not threadsafe in any way. Do not attempt to
  36. access it from more than one thread.</p>
  37. </div>
  38. <div class="refsect1">
  39. <a name="id-1.1.85.3"></a><h2>Functions</h2>
  40. <div class="refsect2">
  41. <a name="id-1.1.85.3.2"></a><h3>add-value</h3>
  42. <div class="informalexample"><pre class="programlisting">(define-values () (variant-builder:add-value self value))
  43. </pre></div>
  44. <p>Adds <em class="parameter"><code>value</code></em> to <em class="parameter"><code>builder</code></em>.
  45. </p>
  46. <p>It is an error to call this function in any way that would create an
  47. inconsistent value to be constructed. Some examples of this are
  48. putting different types of items into an array, putting the wrong
  49. types or number of items in a tuple, putting more than one value into
  50. a variant, etc.
  51. </p>
  52. <p>If <em class="parameter"><code>value</code></em> is a floating reference (see <code class="function">g_variant_ref_sink()</code>),
  53. the <em class="parameter"><code>builder</code></em> instance takes ownership of <em class="parameter"><code>value</code></em>.</p>
  54. <div class="refsect3">
  55. <a name="id-1.1.85.3.2.6"></a><h4>Parameters</h4>
  56. <div class="informaltable"><table>
  57. <tr>
  58. <td class="parameter_name"><p>builder</p></td>
  59. <td class="parameter_description">
  60. <p>a <span class="type">GVariantBuilder</span></p>
  61. <p>Passed as <code class="code">self</code></p>
  62. </td>
  63. </tr>
  64. <tr>
  65. <td class="parameter_name"><p>value</p></td>
  66. <td class="parameter_description">
  67. <p>a <span class="type">GVariant</span></p>
  68. <p>Passed as <code class="code">value</code></p>
  69. </td>
  70. </tr>
  71. </table></div>
  72. </div>
  73. </div>
  74. <div class="refsect2">
  75. <a name="id-1.1.85.3.3"></a><h3>close</h3>
  76. <div class="informalexample"><pre class="programlisting">(define-values () (variant-builder:close self))
  77. </pre></div>
  78. <p>Closes the subcontainer inside the given <em class="parameter"><code>builder</code></em> that was opened by
  79. the most recent call to <code class="function">g_variant_builder_open()</code>.
  80. </p>
  81. <p>It is an error to call this function in any way that would create an
  82. inconsistent value to be constructed (ie: too few values added to the
  83. subcontainer).</p>
  84. <div class="refsect3">
  85. <a name="id-1.1.85.3.3.5"></a><h4>Parameters</h4>
  86. <div class="informaltable"><table><tr>
  87. <td class="parameter_name"><p>builder</p></td>
  88. <td class="parameter_description">
  89. <p>a <span class="type">GVariantBuilder</span></p>
  90. <p>Passed as <code class="code">self</code></p>
  91. </td>
  92. </tr></table></div>
  93. </div>
  94. </div>
  95. <div class="refsect2">
  96. <a name="id-1.1.85.3.4"></a><h3>end</h3>
  97. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant-builder:end self))
  98. </pre></div>
  99. <p>Ends the builder process and returns the constructed value.
  100. </p>
  101. <p>It is not permissible to use <em class="parameter"><code>builder</code></em> in any way after this call
  102. except for reference counting operations (in the case of a
  103. heap-allocated <span class="type">GVariantBuilder</span>) or by reinitialising it with
  104. <code class="function">g_variant_builder_init()</code> (in the case of stack-allocated). This
  105. means that for the stack-allocated builders there is no need to
  106. call <code class="function">g_variant_builder_clear()</code> after the call to
  107. <code class="function">g_variant_builder_end()</code>.
  108. </p>
  109. <p>It is an error to call this function in any way that would create an
  110. inconsistent value to be constructed (ie: insufficient number of
  111. items added to a container with a specific number of children
  112. required). It is also an error to call this function if the builder
  113. was created with an indefinite array or maybe type and no children
  114. have been added; in this case it is impossible to infer the type of
  115. the empty array.</p>
  116. <div class="refsect3">
  117. <a name="id-1.1.85.3.4.6"></a><h4>Parameters</h4>
  118. <div class="informaltable"><table><tr>
  119. <td class="parameter_name"><p>builder</p></td>
  120. <td class="parameter_description">
  121. <p>a <span class="type">GVariantBuilder</span></p>
  122. <p>Passed as <code class="code">self</code></p>
  123. </td>
  124. </tr></table></div>
  125. </div>
  126. </div>
  127. <div class="refsect2">
  128. <a name="id-1.1.85.3.5"></a><h3>open</h3>
  129. <div class="informalexample"><pre class="programlisting">(define-values () (variant-builder:open self type))
  130. </pre></div>
  131. <p>Opens a subcontainer inside the given <em class="parameter"><code>builder</code></em>. When done adding
  132. items to the subcontainer, <code class="function">g_variant_builder_close()</code> must be called. <em class="parameter"><code>type</code></em>
  133. is the type of the container: so to build a tuple of several values, <em class="parameter"><code>type</code></em>
  134. must include the tuple itself.
  135. </p>
  136. <p>It is an error to call this function in any way that would cause an
  137. inconsistent value to be constructed (ie: adding too many values or
  138. a value of an incorrect type).
  139. </p>
  140. <p>Example of building a nested variant:
  141. </p>
  142. <div class="informalexample"><pre class="programlisting">
  143. GVariantBuilder builder;
  144. guint32 some_number = get_number ();
  145. g_autoptr (GHashTable) some_dict = get_dict ();
  146. GHashTableIter iter;
  147. const gchar *key;
  148. const GVariant *value;
  149. g_autoptr (GVariant) output = NULL;
  150. g_variant_builder_init (&amp;builder, G_VARIANT_TYPE ("(ua{sv})"));
  151. g_variant_builder_add (&amp;builder, "u", some_number);
  152. g_variant_builder_open (&amp;builder, G_VARIANT_TYPE ("a{sv}"));
  153. g_hash_table_iter_init (&amp;iter, some_dict);
  154. while (g_hash_table_iter_next (&amp;iter, (gpointer *) &amp;key, (gpointer *) &amp;value))
  155. {
  156. g_variant_builder_open (&amp;builder, G_VARIANT_TYPE ("{sv}"));
  157. g_variant_builder_add (&amp;builder, "s", key);
  158. g_variant_builder_add (&amp;builder, "v", value);
  159. g_variant_builder_close (&amp;builder);
  160. }
  161. g_variant_builder_close (&amp;builder);
  162. output = g_variant_builder_end (&amp;builder);
  163. </pre></div>
  164. <div class="refsect3">
  165. <a name="id-1.1.85.3.5.6"></a><h4>Parameters</h4>
  166. <div class="informaltable"><table>
  167. <tr>
  168. <td class="parameter_name"><p>builder</p></td>
  169. <td class="parameter_description">
  170. <p>a <span class="type">GVariantBuilder</span></p>
  171. <p>Passed as <code class="code">self</code></p>
  172. </td>
  173. </tr>
  174. <tr>
  175. <td class="parameter_name"><p>type</p></td>
  176. <td class="parameter_description">
  177. <p>the <span class="type">GVariantType</span> of the container</p>
  178. <p>Passed as <code class="code">type</code></p>
  179. </td>
  180. </tr>
  181. </table></div>
  182. </div>
  183. </div>
  184. <div class="refsect2">
  185. <a name="id-1.1.85.3.6"></a><h3>ref</h3>
  186. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant-builder:ref self))
  187. </pre></div>
  188. <p>Increases the reference count on <em class="parameter"><code>builder</code></em>.
  189. </p>
  190. <p>Don't call this on stack-allocated <span class="type">GVariantBuilder</span> instances or bad
  191. things will happen.</p>
  192. <div class="refsect3">
  193. <a name="id-1.1.85.3.6.5"></a><h4>Parameters</h4>
  194. <div class="informaltable"><table><tr>
  195. <td class="parameter_name"><p>builder</p></td>
  196. <td class="parameter_description">
  197. <p>a <span class="type">GVariantBuilder</span> allocated by <code class="function">g_variant_builder_new()</code></p>
  198. <p>Passed as <code class="code">self</code></p>
  199. </td>
  200. </tr></table></div>
  201. </div>
  202. </div>
  203. <div class="refsect2">
  204. <a name="id-1.1.85.3.7"></a><h3>unref</h3>
  205. <div class="informalexample"><pre class="programlisting">(define-values () (variant-builder:unref self))
  206. </pre></div>
  207. <p>Decreases the reference count on <em class="parameter"><code>builder</code></em>.
  208. </p>
  209. <p>In the event that there are no more references, releases all memory
  210. associated with the <span class="type">GVariantBuilder</span>.
  211. </p>
  212. <p>Don't call this on stack-allocated <span class="type">GVariantBuilder</span> instances or bad
  213. things will happen.</p>
  214. <div class="refsect3">
  215. <a name="id-1.1.85.3.7.6"></a><h4>Parameters</h4>
  216. <div class="informaltable"><table><tr>
  217. <td class="parameter_name"><p>builder</p></td>
  218. <td class="parameter_description">
  219. <p>a <span class="type">GVariantBuilder</span> allocated by <code class="function">g_variant_builder_new()</code></p>
  220. <p>Passed as <code class="code">self</code></p>
  221. </td>
  222. </tr></table></div>
  223. </div>
  224. </div>
  225. <div class="refsect2">
  226. <a name="id-1.1.85.3.8"></a><h3>variant-builder:new</h3>
  227. <div class="informalexample"><pre class="programlisting">(define-values (%return) (variant-builder:new type))
  228. </pre></div>
  229. <p>Undocumented</p>
  230. <div class="refsect3">
  231. <a name="id-1.1.85.3.8.4"></a><h4>Parameters</h4>
  232. <div class="informaltable"><table><tr>
  233. <td class="parameter_name"><p>type</p></td>
  234. <td class="parameter_description">
  235. <p></p>
  236. <p>Passed as <code class="code">type</code></p>
  237. </td>
  238. </tr></table></div>
  239. </div>
  240. </div>
  241. </div>
  242. </div>
  243. <div class="footer">
  244. <hr>Generated by GTK-Doc V1.33.1</div>
  245. </body>
  246. </html>