Class StrvBuilder

All Implemented Interfaces:
Proxy

@Generated("org.javagi.JavaGI") public class StrvBuilder extends ProxyInstance

GStrvBuilder is a helper object to build a null-terminated string arrays.

The following example shows how to build a two element array:

  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 }));
Since:
2.68
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new GStrvBuilder with a reference count of 1.
    Create a StrvBuilder proxy instance for the provided memory address.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(String value)
    Add a string to the end of the array.
    void
    addMany(Object... varargs)
    Appends all the given strings to the builder.
    void
    addv(@Nullable String @Nullable [] value)
    Appends all the strings in the given vector to the builder.
    end()
    Ends the builder process and returns the constructed NULL-terminated string array.
    The memory layout of the native struct.
    static @Nullable Type
    Get the GType of the StrvBuilder class.
    ref()
    Atomically increments the reference count of this StrvBuilder by one.
    void
    take(String value)
    Add a string to the end of the array.
    void
    Decreases the reference count on builder.
    Decreases the reference count on the string vector builder, and returns its contents as a NULL-terminated string array.

    Methods inherited from class ProxyInstance

    equals, handle, hashCode

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • StrvBuilder

      public StrvBuilder(MemorySegment address)
      Create a StrvBuilder proxy instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • StrvBuilder

      public StrvBuilder()
      Creates a new GStrvBuilder with a reference count of 1. Use g_strv_builder_unref() on the returned value when no longer needed.
      Since:
      2.68
  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the StrvBuilder class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • add

      public void add(String value)

      Add a string to the end of the array.

      Since 2.68

      Parameters:
      value - a string.
    • addMany

      public void addMany(Object... varargs)

      Appends all the given strings to the builder.

      Since 2.70

      Parameters:
      varargs - one or more strings followed by null
    • addv

      public void addv(@Nullable String @Nullable [] value)

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

      Since 2.70

      Parameters:
      value - the vector of strings to add
    • end

      public String[] 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.
      Returns:

      the constructed string array.

      Since 2.68

    • ref

      public StrvBuilder ref()
      Atomically increments the reference count of this StrvBuilder by one. This function is thread-safe and may be called from any thread.
      Returns:
      The passed in GStrvBuilder
      Since:
      2.68
    • take

      public void 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

      Parameters:
      value - a string. Ownership of the string is transferred to the GStrvBuilder
    • unref

      public void unref()

      Decreases the reference count on builder.

      In the event that there are no more references, releases all memory associated with the GStrvBuilder.

      Since:
      2.68
    • unrefToStrv

      public String[] unrefToStrv()

      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().

      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);
      
      Returns:
      the constructed string array
      Since:
      2.82