Basics

Guides

API Reference

Menu

Basics

Guides

API Reference

class: GStrvBuilder

[17:7] extends: object

GStrvBuilder is a helper object to build a %NULL-terminated string arrays. The following example shows how to build a two element array: c g_autoptr(GStrvBuilder) builder = g_strv_builder_new (); g_strv_builder_add (builder, "hello"); g_strv_builder_add (builder, "world"); g_auto(GStrv) array = g_strv_builder_end (builder); g_assert_true (g_strv_equal (array, (const char *[]) { "hello", "world", NULL }));

Members

  • handleObj
  • lib
  • retainedCallbacks
  • signalHandlerNames
  • signalSetterHandlers

Methods

  • GStrvBuilder (Handle = null)

    Creates a new #GStrvBuilder with a reference count of 1. Use g_strv_builder_unref() on the returned value when no longer needed.

    • @p Handle is an optional native handle or wrapper whose handle to adopt; when the native constructor is called.
  • toNativeHandle (Source)

    Normalizes a constructor argument into a raw pointer carrier. Accepts a raw NativeHandle, a raw NativeBuffer returned from fn.call(...), another generated wrapper exposing handle(), or null. Returns null when the argument carries no pointer.

    • @p Source is the raw handle, raw buffer, wrapper, or null.
    • @r A raw pointer carrier or null when no pointer is present.
  • getLib ()

    Returns the opened native library for this generated wrapper.

    • @r The opened native library.
  • handle ()

    Returns the wrapped NativeHandle.

    • @r The wrapped NativeHandle.
  • isNull ()

    Returns true when the wrapped handle is null.

    • @r A bool.
  • describe ()

    Returns a small string for debugging generated wrappers.

    • @r A string.
  • add (string value)

    Add a string to the end of the array. Since 2.68

    • @p value is a string..
    • @r None.
  • add_many (list varargs)

    Appends all the given strings to the builder. Since 2.70

    • @p ... is one or more strings followed by %NULL.
    • @r None.
  • addv (list value)

    Appends all the strings in the given vector to the builder. Since 2.70

    • @p value is the vector of strings to add.
    • @r None.
  • end ()

    Ends the builder process and returns the constructed NULL-terminated string array. The returned value should be freed with g_strfreev() when no longer needed.

    • @r the constructed string array. Since 2.68.
  • ref ()

    Atomically increments the reference count of @builder by one. This function is thread-safe and may be called from any thread.

    • @r The passed in #GStrvBuilder.
  • take (string value)

    Add a string to the end of the array. After @value belongs to the #GStrvBuilder and may no longer be modified by the caller. Since 2.80

    • @p value is a string. Ownership of the string is transferred to the #GStrvBuilder.
    • @r None.
  • unref ()

    Decreases the reference count on @builder. In the event that there are no more references, releases all memory associated with the #GStrvBuilder.

    • @r None.
  • unref_to_strv ()

    Decreases the reference count on the string vector builder, and returns its contents as a NULL-terminated string array. This function is especially useful for cases where it's not possible to use g_autoptr(). c GStrvBuilder *builder = g_strv_builder_new (); g_strv_builder_add (builder, "hello"); g_strv_builder_add (builder, "world"); GStrv array = g_strv_builder_unref_to_strv (builder); g_assert_true (g_strv_equal (array, (const char *[]) { "hello", "world", NULL })); g_strfreev (array);

    • @r the constructed string array.