{-# LANGUAGE TypeApplications #-}


-- | Copyright  : Will Thompson and Iñaki García Etxebarria
-- License    : LGPL-2.1
-- Maintainer : Iñaki García Etxebarria
-- 
-- @GStrvBuilder@ is a helper object to build a 'P.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/

#if !defined(__HADDOCK_VERSION__)
#define ENABLE_OVERLOADING
#endif

module GI.GLib.Structs.StrvBuilder
    ( 

-- * Exported types
    StrvBuilder(..)                         ,


 -- * Methods
-- | 
-- 
--  === __Click to display all available methods, including inherited ones__
-- ==== Methods
-- [add]("GI.GLib.Structs.StrvBuilder#g:method:add"), [addv]("GI.GLib.Structs.StrvBuilder#g:method:addv"), [end]("GI.GLib.Structs.StrvBuilder#g:method:end"), [ref]("GI.GLib.Structs.StrvBuilder#g:method:ref"), [take]("GI.GLib.Structs.StrvBuilder#g:method:take"), [unref]("GI.GLib.Structs.StrvBuilder#g:method:unref"), [unrefToStrv]("GI.GLib.Structs.StrvBuilder#g:method:unrefToStrv").
-- 
-- ==== Getters
-- /None/.
-- 
-- ==== Setters
-- /None/.

#if defined(ENABLE_OVERLOADING)
    ResolveStrvBuilderMethod                ,
#endif

-- ** add #method:add#

#if defined(ENABLE_OVERLOADING)
    StrvBuilderAddMethodInfo                ,
#endif
    strvBuilderAdd                          ,


-- ** addv #method:addv#

#if defined(ENABLE_OVERLOADING)
    StrvBuilderAddvMethodInfo               ,
#endif
    strvBuilderAddv                         ,


-- ** end #method:end#

#if defined(ENABLE_OVERLOADING)
    StrvBuilderEndMethodInfo                ,
#endif
    strvBuilderEnd                          ,


-- ** new #method:new#

    strvBuilderNew                          ,


-- ** ref #method:ref#

#if defined(ENABLE_OVERLOADING)
    StrvBuilderRefMethodInfo                ,
#endif
    strvBuilderRef                          ,


-- ** take #method:take#

#if defined(ENABLE_OVERLOADING)
    StrvBuilderTakeMethodInfo               ,
#endif
    strvBuilderTake                         ,


-- ** unref #method:unref#

#if defined(ENABLE_OVERLOADING)
    StrvBuilderUnrefMethodInfo              ,
#endif
    strvBuilderUnref                        ,


-- ** unrefToStrv #method:unrefToStrv#

#if defined(ENABLE_OVERLOADING)
    StrvBuilderUnrefToStrvMethodInfo        ,
#endif
    strvBuilderUnrefToStrv                  ,




    ) where

import Data.GI.Base.ShortPrelude
import qualified Data.GI.Base.ShortPrelude as SP
import qualified Data.GI.Base.Overloading as O
import qualified Prelude as P

import qualified Data.GI.Base.Attributes as GI.Attributes
import qualified Data.GI.Base.BasicTypes as B.Types
import qualified Data.GI.Base.ManagedPtr as B.ManagedPtr
import qualified Data.GI.Base.GArray as B.GArray
import qualified Data.GI.Base.GClosure as B.GClosure
import qualified Data.GI.Base.GError as B.GError
import qualified Data.GI.Base.GHashTable as B.GHT
import qualified Data.GI.Base.GVariant as B.GVariant
import qualified Data.GI.Base.GValue as B.GValue
import qualified Data.GI.Base.GParamSpec as B.GParamSpec
import qualified Data.GI.Base.CallStack as B.CallStack
import qualified Data.GI.Base.Properties as B.Properties
import qualified Data.GI.Base.Signals as B.Signals
import qualified Control.Monad.IO.Class as MIO
import qualified Data.Coerce as Coerce
import qualified Data.Text as T
import qualified Data.Kind as DK
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map
import qualified Foreign.Ptr as FP
import qualified GHC.OverloadedLabels as OL
import qualified GHC.Records as R
import qualified Data.Word as DW
import qualified Data.Int as DI
import qualified System.Posix.Types as SPT
import qualified Foreign.C.Types as FCT

-- Workaround for https://gitlab.haskell.org/ghc/ghc/-/issues/23392
#if MIN_VERSION_base(4,18,0)

#else

#endif

-- | Memory-managed wrapper type.
newtype StrvBuilder = StrvBuilder (SP.ManagedPtr StrvBuilder)
    deriving (StrvBuilder -> StrvBuilder -> Bool
(StrvBuilder -> StrvBuilder -> Bool)
-> (StrvBuilder -> StrvBuilder -> Bool) -> Eq StrvBuilder
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: StrvBuilder -> StrvBuilder -> Bool
== :: StrvBuilder -> StrvBuilder -> Bool
$c/= :: StrvBuilder -> StrvBuilder -> Bool
/= :: StrvBuilder -> StrvBuilder -> Bool
Eq)

instance SP.ManagedPtrNewtype StrvBuilder where
    toManagedPtr :: StrvBuilder -> ManagedPtr StrvBuilder
toManagedPtr (StrvBuilder ManagedPtr StrvBuilder
p) = ManagedPtr StrvBuilder
p

foreign import ccall "g_strv_builder_get_type" c_g_strv_builder_get_type :: 
    IO GType

type instance O.ParentTypes StrvBuilder = '[]
instance O.HasParentTypes StrvBuilder

instance B.Types.TypedObject StrvBuilder where
    glibType :: IO GType
glibType = IO GType
c_g_strv_builder_get_type

instance B.Types.GBoxed StrvBuilder

-- | Convert t'StrvBuilder' to and from 'Data.GI.Base.GValue.GValue'. See 'Data.GI.Base.GValue.toGValue' and 'Data.GI.Base.GValue.fromGValue'.
instance B.GValue.IsGValue (Maybe StrvBuilder) where
    gvalueGType_ :: IO GType
gvalueGType_ = IO GType
c_g_strv_builder_get_type
    gvalueSet_ :: Ptr GValue -> Maybe StrvBuilder -> IO ()
gvalueSet_ Ptr GValue
gv Maybe StrvBuilder
P.Nothing = Ptr GValue -> Ptr StrvBuilder -> IO ()
forall a. Ptr GValue -> Ptr a -> IO ()
B.GValue.set_boxed Ptr GValue
gv (Ptr StrvBuilder
forall a. Ptr a
FP.nullPtr :: FP.Ptr StrvBuilder)
    gvalueSet_ Ptr GValue
gv (P.Just StrvBuilder
obj) = StrvBuilder -> (Ptr StrvBuilder -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
B.ManagedPtr.withManagedPtr StrvBuilder
obj (Ptr GValue -> Ptr StrvBuilder -> IO ()
forall a. Ptr GValue -> Ptr a -> IO ()
B.GValue.set_boxed Ptr GValue
gv)
    gvalueGet_ :: Ptr GValue -> IO (Maybe StrvBuilder)
gvalueGet_ Ptr GValue
gv = do
        ptr <- Ptr GValue -> IO (Ptr StrvBuilder)
forall b. Ptr GValue -> IO (Ptr b)
B.GValue.get_boxed Ptr GValue
gv :: IO (Ptr StrvBuilder)
        if ptr /= FP.nullPtr
        then P.Just <$> B.ManagedPtr.newBoxed StrvBuilder ptr
        else return P.Nothing
        
    


#if defined(ENABLE_OVERLOADING)
instance O.HasAttributeList StrvBuilder
type instance O.AttributeList StrvBuilder = StrvBuilderAttributeList
type StrvBuilderAttributeList = ('[ ] :: [(Symbol, DK.Type)])
#endif

-- method StrvBuilder::new
-- method type : Constructor
-- Args: []
-- Lengths: []
-- returnType: Just
--               (TInterface Name { namespace = "GLib" , name = "StrvBuilder" })
-- throws : False
-- Skip return : False

foreign import ccall "g_strv_builder_new" g_strv_builder_new :: 
    IO (Ptr StrvBuilder)

-- | Creates a new t'GI.GLib.Structs.StrvBuilder.StrvBuilder' with a reference count of 1.
-- Use 'GI.GLib.Structs.StrvBuilder.strvBuilderUnref' on the returned value when no longer needed.
-- 
-- /Since: 2.68/
strvBuilderNew ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    m StrvBuilder
    -- ^ __Returns:__ the new t'GI.GLib.Structs.StrvBuilder.StrvBuilder'
strvBuilderNew :: forall (m :: * -> *). (HasCallStack, MonadIO m) => m StrvBuilder
strvBuilderNew  = IO StrvBuilder -> m StrvBuilder
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO StrvBuilder -> m StrvBuilder)
-> IO StrvBuilder -> m StrvBuilder
forall a b. (a -> b) -> a -> b
$ do
    result <- IO (Ptr StrvBuilder)
g_strv_builder_new
    checkUnexpectedReturnNULL "strvBuilderNew" result
    result' <- (wrapBoxed StrvBuilder) result
    return result'

#if defined(ENABLE_OVERLOADING)
#endif

-- method StrvBuilder::add
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "builder"
--           , argType =
--               TInterface Name { namespace = "GLib" , name = "StrvBuilder" }
--           , argCType = Just "GStrvBuilder*"
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GStrvBuilder" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "value"
--           , argType = TBasicType TUTF8
--           , argCType = Just "const char*"
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a string." , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Nothing
-- throws : False
-- Skip return : False

foreign import ccall "g_strv_builder_add" g_strv_builder_add :: 
    Ptr StrvBuilder ->                      -- builder : TInterface (Name {namespace = "GLib", name = "StrvBuilder"})
    CString ->                              -- value : TBasicType TUTF8
    IO ()

-- | Add a string to the end of the array.
-- 
-- Since 2.68
strvBuilderAdd ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    StrvBuilder
    -- ^ /@builder@/: a t'GI.GLib.Structs.StrvBuilder.StrvBuilder'
    -> T.Text
    -- ^ /@value@/: a string.
    -> m ()
strvBuilderAdd :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
StrvBuilder -> Text -> m ()
strvBuilderAdd StrvBuilder
builder Text
value = IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    builder' <- StrvBuilder -> IO (Ptr StrvBuilder)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr StrvBuilder
builder
    value' <- textToCString value
    g_strv_builder_add builder' value'
    touchManagedPtr builder
    freeMem value'
    return ()

#if defined(ENABLE_OVERLOADING)
data StrvBuilderAddMethodInfo
instance (signature ~ (T.Text -> m ()), MonadIO m) => O.OverloadedMethod StrvBuilderAddMethodInfo StrvBuilder signature where
    overloadedMethod = strvBuilderAdd

instance O.OverloadedMethodInfo StrvBuilderAddMethodInfo StrvBuilder where
    overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
        O.resolvedSymbolName = "GI.GLib.Structs.StrvBuilder.strvBuilderAdd",
        O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-glib-2.0.30/docs/GI-GLib-Structs-StrvBuilder.html#v:strvBuilderAdd"
        })


#endif

-- method StrvBuilder::addv
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "builder"
--           , argType =
--               TInterface Name { namespace = "GLib" , name = "StrvBuilder" }
--           , argCType = Just "GStrvBuilder*"
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GStrvBuilder" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "value"
--           , argType = TCArray True (-1) (-1) (TBasicType TUTF8)
--           , argCType = Just "const char**"
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the vector of strings to add"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Nothing
-- throws : False
-- Skip return : False

foreign import ccall "g_strv_builder_addv" g_strv_builder_addv :: 
    Ptr StrvBuilder ->                      -- builder : TInterface (Name {namespace = "GLib", name = "StrvBuilder"})
    Ptr CString ->                          -- value : TCArray True (-1) (-1) (TBasicType TUTF8)
    IO ()

-- | Appends all the strings in the given vector to the builder.
-- 
-- Since 2.70
strvBuilderAddv ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    StrvBuilder
    -- ^ /@builder@/: a t'GI.GLib.Structs.StrvBuilder.StrvBuilder'
    -> [T.Text]
    -- ^ /@value@/: the vector of strings to add
    -> m ()
strvBuilderAddv :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
StrvBuilder -> [Text] -> m ()
strvBuilderAddv StrvBuilder
builder [Text]
value = IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    builder' <- StrvBuilder -> IO (Ptr StrvBuilder)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr StrvBuilder
builder
    value' <- packZeroTerminatedUTF8CArray value
    g_strv_builder_addv builder' value'
    touchManagedPtr builder
    mapZeroTerminatedCArray freeMem value'
    freeMem value'
    return ()

#if defined(ENABLE_OVERLOADING)
data StrvBuilderAddvMethodInfo
instance (signature ~ ([T.Text] -> m ()), MonadIO m) => O.OverloadedMethod StrvBuilderAddvMethodInfo StrvBuilder signature where
    overloadedMethod = strvBuilderAddv

instance O.OverloadedMethodInfo StrvBuilderAddvMethodInfo StrvBuilder where
    overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
        O.resolvedSymbolName = "GI.GLib.Structs.StrvBuilder.strvBuilderAddv",
        O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-glib-2.0.30/docs/GI-GLib-Structs-StrvBuilder.html#v:strvBuilderAddv"
        })


#endif

-- method StrvBuilder::end
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "builder"
--           , argType =
--               TInterface Name { namespace = "GLib" , name = "StrvBuilder" }
--           , argCType = Just "GStrvBuilder*"
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GStrvBuilder" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TCArray True (-1) (-1) (TBasicType TUTF8))
-- throws : False
-- Skip return : False

foreign import ccall "g_strv_builder_end" g_strv_builder_end :: 
    Ptr StrvBuilder ->                      -- builder : TInterface (Name {namespace = "GLib", name = "StrvBuilder"})
    IO (Ptr CString)

-- | Ends the builder process and returns the constructed NULL-terminated string
-- array. The returned value should be freed with 'GI.GLib.Functions.strfreev' when no longer
-- needed.
strvBuilderEnd ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    StrvBuilder
    -- ^ /@builder@/: a t'GI.GLib.Structs.StrvBuilder.StrvBuilder'
    -> m [T.Text]
    -- ^ __Returns:__ the constructed string array.
    -- 
    -- Since 2.68
strvBuilderEnd :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
StrvBuilder -> m [Text]
strvBuilderEnd StrvBuilder
builder = IO [Text] -> m [Text]
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO [Text] -> m [Text]) -> IO [Text] -> m [Text]
forall a b. (a -> b) -> a -> b
$ do
    builder' <- StrvBuilder -> IO (Ptr StrvBuilder)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr StrvBuilder
builder
    result <- g_strv_builder_end builder'
    checkUnexpectedReturnNULL "strvBuilderEnd" result
    result' <- unpackZeroTerminatedUTF8CArray result
    mapZeroTerminatedCArray freeMem result
    freeMem result
    touchManagedPtr builder
    return result'

#if defined(ENABLE_OVERLOADING)
data StrvBuilderEndMethodInfo
instance (signature ~ (m [T.Text]), MonadIO m) => O.OverloadedMethod StrvBuilderEndMethodInfo StrvBuilder signature where
    overloadedMethod = strvBuilderEnd

instance O.OverloadedMethodInfo StrvBuilderEndMethodInfo StrvBuilder where
    overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
        O.resolvedSymbolName = "GI.GLib.Structs.StrvBuilder.strvBuilderEnd",
        O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-glib-2.0.30/docs/GI-GLib-Structs-StrvBuilder.html#v:strvBuilderEnd"
        })


#endif

-- method StrvBuilder::ref
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "builder"
--           , argType =
--               TInterface Name { namespace = "GLib" , name = "StrvBuilder" }
--           , argCType = Just "GStrvBuilder*"
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GStrvBuilder" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just
--               (TInterface Name { namespace = "GLib" , name = "StrvBuilder" })
-- throws : False
-- Skip return : False

foreign import ccall "g_strv_builder_ref" g_strv_builder_ref :: 
    Ptr StrvBuilder ->                      -- builder : TInterface (Name {namespace = "GLib", name = "StrvBuilder"})
    IO (Ptr 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/
strvBuilderRef ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    StrvBuilder
    -- ^ /@builder@/: a t'GI.GLib.Structs.StrvBuilder.StrvBuilder'
    -> m StrvBuilder
    -- ^ __Returns:__ The passed in t'GI.GLib.Structs.StrvBuilder.StrvBuilder'
strvBuilderRef :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
StrvBuilder -> m StrvBuilder
strvBuilderRef StrvBuilder
builder = IO StrvBuilder -> m StrvBuilder
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO StrvBuilder -> m StrvBuilder)
-> IO StrvBuilder -> m StrvBuilder
forall a b. (a -> b) -> a -> b
$ do
    builder' <- StrvBuilder -> IO (Ptr StrvBuilder)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr StrvBuilder
builder
    result <- g_strv_builder_ref builder'
    checkUnexpectedReturnNULL "strvBuilderRef" result
    result' <- (wrapBoxed StrvBuilder) result
    touchManagedPtr builder
    return result'

#if defined(ENABLE_OVERLOADING)
data StrvBuilderRefMethodInfo
instance (signature ~ (m StrvBuilder), MonadIO m) => O.OverloadedMethod StrvBuilderRefMethodInfo StrvBuilder signature where
    overloadedMethod = strvBuilderRef

instance O.OverloadedMethodInfo StrvBuilderRefMethodInfo StrvBuilder where
    overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
        O.resolvedSymbolName = "GI.GLib.Structs.StrvBuilder.strvBuilderRef",
        O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-glib-2.0.30/docs/GI-GLib-Structs-StrvBuilder.html#v:strvBuilderRef"
        })


#endif

-- method StrvBuilder::take
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "builder"
--           , argType =
--               TInterface Name { namespace = "GLib" , name = "StrvBuilder" }
--           , argCType = Just "GStrvBuilder*"
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GStrvBuilder" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "value"
--           , argType = TBasicType TUTF8
--           , argCType = Just "char*"
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText =
--                     Just
--                       "a string.\n    Ownership of the string is transferred to the #GStrvBuilder"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferEverything
--           }
--       ]
-- Lengths: []
-- returnType: Nothing
-- throws : False
-- Skip return : False

foreign import ccall "g_strv_builder_take" g_strv_builder_take :: 
    Ptr StrvBuilder ->                      -- builder : TInterface (Name {namespace = "GLib", name = "StrvBuilder"})
    CString ->                              -- value : TBasicType TUTF8
    IO ()

-- | Add a string to the end of the array. After /@value@/ belongs to the
-- t'GI.GLib.Structs.StrvBuilder.StrvBuilder' and may no longer be modified by the caller.
-- 
-- Since 2.80
strvBuilderTake ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    StrvBuilder
    -- ^ /@builder@/: a t'GI.GLib.Structs.StrvBuilder.StrvBuilder'
    -> T.Text
    -- ^ /@value@/: a string.
    --     Ownership of the string is transferred to the t'GI.GLib.Structs.StrvBuilder.StrvBuilder'
    -> m ()
strvBuilderTake :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
StrvBuilder -> Text -> m ()
strvBuilderTake StrvBuilder
builder Text
value = IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    builder' <- StrvBuilder -> IO (Ptr StrvBuilder)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr StrvBuilder
builder
    value' <- textToCString value
    g_strv_builder_take builder' value'
    touchManagedPtr builder
    return ()

#if defined(ENABLE_OVERLOADING)
data StrvBuilderTakeMethodInfo
instance (signature ~ (T.Text -> m ()), MonadIO m) => O.OverloadedMethod StrvBuilderTakeMethodInfo StrvBuilder signature where
    overloadedMethod = strvBuilderTake

instance O.OverloadedMethodInfo StrvBuilderTakeMethodInfo StrvBuilder where
    overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
        O.resolvedSymbolName = "GI.GLib.Structs.StrvBuilder.strvBuilderTake",
        O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-glib-2.0.30/docs/GI-GLib-Structs-StrvBuilder.html#v:strvBuilderTake"
        })


#endif

-- method StrvBuilder::unref
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "builder"
--           , argType =
--               TInterface Name { namespace = "GLib" , name = "StrvBuilder" }
--           , argCType = Just "GStrvBuilder*"
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText =
--                     Just "a #GStrvBuilder allocated by g_strv_builder_new()"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferEverything
--           }
--       ]
-- Lengths: []
-- returnType: Nothing
-- throws : False
-- Skip return : False

foreign import ccall "g_strv_builder_unref" g_strv_builder_unref :: 
    Ptr StrvBuilder ->                      -- builder : TInterface (Name {namespace = "GLib", name = "StrvBuilder"})
    IO ()

-- | Decreases the reference count on /@builder@/.
-- 
-- In the event that there are no more references, releases all memory
-- associated with the t'GI.GLib.Structs.StrvBuilder.StrvBuilder'.
-- 
-- /Since: 2.68/
strvBuilderUnref ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    StrvBuilder
    -- ^ /@builder@/: a t'GI.GLib.Structs.StrvBuilder.StrvBuilder' allocated by 'GI.GLib.Structs.StrvBuilder.strvBuilderNew'
    -> m ()
strvBuilderUnref :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
StrvBuilder -> m ()
strvBuilderUnref StrvBuilder
builder = IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    builder' <- StrvBuilder -> IO (Ptr StrvBuilder)
forall a. (HasCallStack, GBoxed a) => a -> IO (Ptr a)
B.ManagedPtr.disownBoxed StrvBuilder
builder
    g_strv_builder_unref builder'
    touchManagedPtr builder
    return ()

#if defined(ENABLE_OVERLOADING)
data StrvBuilderUnrefMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.OverloadedMethod StrvBuilderUnrefMethodInfo StrvBuilder signature where
    overloadedMethod = strvBuilderUnref

instance O.OverloadedMethodInfo StrvBuilderUnrefMethodInfo StrvBuilder where
    overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
        O.resolvedSymbolName = "GI.GLib.Structs.StrvBuilder.strvBuilderUnref",
        O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-glib-2.0.30/docs/GI-GLib-Structs-StrvBuilder.html#v:strvBuilderUnref"
        })


#endif

-- method StrvBuilder::unref_to_strv
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "builder"
--           , argType =
--               TInterface Name { namespace = "GLib" , name = "StrvBuilder" }
--           , argCType = Just "GStrvBuilder*"
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GStrvBuilder" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferEverything
--           }
--       ]
-- Lengths: []
-- returnType: Just (TCArray True (-1) (-1) (TBasicType TUTF8))
-- throws : False
-- Skip return : False

foreign import ccall "g_strv_builder_unref_to_strv" g_strv_builder_unref_to_strv :: 
    Ptr StrvBuilder ->                      -- builder : TInterface (Name {namespace = "GLib", name = "StrvBuilder"})
    IO (Ptr CString)

-- | 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/
strvBuilderUnrefToStrv ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    StrvBuilder
    -- ^ /@builder@/: a t'GI.GLib.Structs.StrvBuilder.StrvBuilder'
    -> m [T.Text]
    -- ^ __Returns:__ the constructed string
    --   array
strvBuilderUnrefToStrv :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
StrvBuilder -> m [Text]
strvBuilderUnrefToStrv StrvBuilder
builder = IO [Text] -> m [Text]
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO [Text] -> m [Text]) -> IO [Text] -> m [Text]
forall a b. (a -> b) -> a -> b
$ do
    builder' <- StrvBuilder -> IO (Ptr StrvBuilder)
forall a. (HasCallStack, GBoxed a) => a -> IO (Ptr a)
B.ManagedPtr.disownBoxed StrvBuilder
builder
    result <- g_strv_builder_unref_to_strv builder'
    checkUnexpectedReturnNULL "strvBuilderUnrefToStrv" result
    result' <- unpackZeroTerminatedUTF8CArray result
    mapZeroTerminatedCArray freeMem result
    freeMem result
    touchManagedPtr builder
    return result'

#if defined(ENABLE_OVERLOADING)
data StrvBuilderUnrefToStrvMethodInfo
instance (signature ~ (m [T.Text]), MonadIO m) => O.OverloadedMethod StrvBuilderUnrefToStrvMethodInfo StrvBuilder signature where
    overloadedMethod = strvBuilderUnrefToStrv

instance O.OverloadedMethodInfo StrvBuilderUnrefToStrvMethodInfo StrvBuilder where
    overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
        O.resolvedSymbolName = "GI.GLib.Structs.StrvBuilder.strvBuilderUnrefToStrv",
        O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-glib-2.0.30/docs/GI-GLib-Structs-StrvBuilder.html#v:strvBuilderUnrefToStrv"
        })


#endif

#if defined(ENABLE_OVERLOADING)
type family ResolveStrvBuilderMethod (t :: Symbol) (o :: DK.Type) :: DK.Type where
    ResolveStrvBuilderMethod "add" o = StrvBuilderAddMethodInfo
    ResolveStrvBuilderMethod "addv" o = StrvBuilderAddvMethodInfo
    ResolveStrvBuilderMethod "end" o = StrvBuilderEndMethodInfo
    ResolveStrvBuilderMethod "ref" o = StrvBuilderRefMethodInfo
    ResolveStrvBuilderMethod "take" o = StrvBuilderTakeMethodInfo
    ResolveStrvBuilderMethod "unref" o = StrvBuilderUnrefMethodInfo
    ResolveStrvBuilderMethod "unrefToStrv" o = StrvBuilderUnrefToStrvMethodInfo
    ResolveStrvBuilderMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveStrvBuilderMethod t StrvBuilder, O.OverloadedMethod info StrvBuilder p) => OL.IsLabel t (StrvBuilder -> p) where
#if MIN_VERSION_base(4,10,0)
    fromLabel = O.overloadedMethod @info
#else
    fromLabel _ = O.overloadedMethod @info
#endif

#if MIN_VERSION_base(4,13,0)
instance (info ~ ResolveStrvBuilderMethod t StrvBuilder, O.OverloadedMethod info StrvBuilder p, R.HasField t StrvBuilder p) => R.HasField t StrvBuilder p where
    getField = O.overloadedMethod @info

#endif

instance (info ~ ResolveStrvBuilderMethod t StrvBuilder, O.OverloadedMethodInfo info StrvBuilder) => OL.IsLabel t (O.MethodProxy info StrvBuilder) where
#if MIN_VERSION_base(4,10,0)
    fromLabel = O.MethodProxy
#else
    fromLabel _ = O.MethodProxy
#endif

#endif