gi-glib-2.0.30: GLib bindings

Copyright | Will Thompson and Iñaki García Etxebarria
License | LGPL-2.1
Maintainer | Iñaki García Etxebarria
Safe Haskell | Safe-Inferred
Language | Haskell2010

GI.GLib.Structs.StrvBuilder

Contents

- Exported types
- Methods
  - add
  - addv
  - end
  - new
  - ref
  - take
  - unref
  - unrefToStrv

Description

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

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

### c code

     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

Synopsis

- newtype StrvBuilder = StrvBuilder (ManagedPtr StrvBuilder)
- strvBuilderAdd :: (HasCallStack, MonadIO m) => StrvBuilder -> Text -> m ()
- strvBuilderAddv :: (HasCallStack, MonadIO m) => StrvBuilder -> [Text] -> m ()
- strvBuilderEnd :: (HasCallStack, MonadIO m) => StrvBuilder -> m [Text]
- strvBuilderNew :: (HasCallStack, MonadIO m) => m StrvBuilder
- strvBuilderRef :: (HasCallStack, MonadIO m) => StrvBuilder -> m StrvBuilder
- strvBuilderTake :: (HasCallStack, MonadIO m) => StrvBuilder -> Text -> m ()
- strvBuilderUnref :: (HasCallStack, MonadIO m) => StrvBuilder -> m ()
- strvBuilderUnrefToStrv :: (HasCallStack, MonadIO m) => StrvBuilder -> m [Text]

# Exported types

newtype StrvBuilder Source #

Memory-managed wrapper type.

Constructors

StrvBuilder (ManagedPtr StrvBuilder) |

#### Instances

Instances details

Eq StrvBuilder Source # |
Instance details Defined in GI.GLib.Structs.StrvBuilder Methods (==) :: StrvBuilder -> StrvBuilder -> Bool Source # (/=) :: StrvBuilder -> StrvBuilder -> Bool Source #
GBoxed StrvBuilder Source # |
Instance details Defined in GI.GLib.Structs.StrvBuilder
ManagedPtrNewtype StrvBuilder Source # |
Instance details Defined in GI.GLib.Structs.StrvBuilder Methods toManagedPtr :: StrvBuilder -> ManagedPtr StrvBuilder Source #
TypedObject StrvBuilder Source # |
Instance details Defined in GI.GLib.Structs.StrvBuilder Methods glibType :: IO GType Source #
HasParentTypes StrvBuilder Source # |
Instance details Defined in GI.GLib.Structs.StrvBuilder
IsGValue (Maybe StrvBuilder) Source # | Convert `StrvBuilder` to and from `GValue`. See `toGValue` and `fromGValue`.
Instance details Defined in GI.GLib.Structs.StrvBuilder Methods gvalueGType_ :: IO GType Source # gvalueSet_ :: Ptr GValue -> Maybe StrvBuilder -> IO () Source # gvalueGet_ :: Ptr GValue -> IO (Maybe StrvBuilder) Source #
type ParentTypes StrvBuilder Source # |
Instance details Defined in GI.GLib.Structs.StrvBuilder type ParentTypes StrvBuilder = '[] :: [Type]

# Methods

### Click to display all available methods, including inherited ones

Expand

#### Methods

add, addv, end, ref, take, unref, unrefToStrv.

#### Getters

None.

#### Setters

None.

## add

strvBuilderAdd Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> StrvBuilder | `builder`: a `StrvBuilder`
-> Text | `value`: a string.
-> m () |

Add a string to the end of the array.

Since 2.68

## addv

strvBuilderAddv Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> StrvBuilder | `builder`: a `StrvBuilder`
-> [Text] | `value`: the vector of strings to add
-> m () |

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

Since 2.70

## end

strvBuilderEnd Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> StrvBuilder | `builder`: a `StrvBuilder`
-> m [Text] | Returns: the constructed string array. Since 2.68

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

## new

strvBuilderNew Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> m StrvBuilder | Returns: the new `StrvBuilder`

Creates a new `StrvBuilder` with a reference count of 1. Use `strvBuilderUnref` on the returned value when no longer needed.

Since: 2.68

## ref

strvBuilderRef Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> StrvBuilder | `builder`: a `StrvBuilder`
-> m StrvBuilder | Returns: The passed in `StrvBuilder`

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

Since: 2.68

## take

strvBuilderTake Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> StrvBuilder | `builder`: a `StrvBuilder`
-> Text | `value`: a string. Ownership of the string is transferred to the `StrvBuilder`
-> m () |

Add a string to the end of the array. After `value` belongs to the `StrvBuilder` and may no longer be modified by the caller.

Since 2.80

## unref

strvBuilderUnref Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> StrvBuilder | `builder`: a `StrvBuilder` allocated by `strvBuilderNew`
-> m () |

Decreases the reference count on `builder`.

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

Since: 2.68

## unrefToStrv

strvBuilderUnrefToStrv Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> StrvBuilder | `builder`: a `StrvBuilder`
-> m [Text] | Returns: the constructed string array

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 code

    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);

Since: 2.82