{-# LANGUAGE TypeApplications #-}


-- | Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
-- License    : LGPL-2.1
-- Maintainer : Iñaki García Etxebarria
-- 
-- A utility type for constructing container-type t'GVariant' instances.
-- 
-- This is an opaque structure and may only be accessed using the
-- following functions.
-- 
-- t'GI.GLib.Structs.VariantBuilder.VariantBuilder' is not threadsafe in any way.  Do not attempt to
-- access it from more than one thread.

#if (MIN_VERSION_haskell_gi_overloading(1,0,0) && !defined(__HADDOCK_VERSION__))
#define ENABLE_OVERLOADING
#endif

module GI.GLib.Structs.VariantBuilder
    ( 

-- * Exported types
    VariantBuilder(..)                      ,
    noVariantBuilder                        ,


 -- * Methods
-- ** Overloaded methods #method:Overloaded methods#

#if defined(ENABLE_OVERLOADING)
    ResolveVariantBuilderMethod             ,
#endif


-- ** addValue #method:addValue#

#if defined(ENABLE_OVERLOADING)
    VariantBuilderAddValueMethodInfo        ,
#endif
    variantBuilderAddValue                  ,


-- ** close #method:close#

#if defined(ENABLE_OVERLOADING)
    VariantBuilderCloseMethodInfo           ,
#endif
    variantBuilderClose                     ,


-- ** end #method:end#

#if defined(ENABLE_OVERLOADING)
    VariantBuilderEndMethodInfo             ,
#endif
    variantBuilderEnd                       ,


-- ** new #method:new#

    variantBuilderNew                       ,


-- ** open #method:open#

#if defined(ENABLE_OVERLOADING)
    VariantBuilderOpenMethodInfo            ,
#endif
    variantBuilderOpen                      ,


-- ** ref #method:ref#

#if defined(ENABLE_OVERLOADING)
    VariantBuilderRefMethodInfo             ,
#endif
    variantBuilderRef                       ,


-- ** unref #method:unref#

#if defined(ENABLE_OVERLOADING)
    VariantBuilderUnrefMethodInfo           ,
#endif
    variantBuilderUnref                     ,




    ) 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.ManagedPtr as B.ManagedPtr
import qualified Data.GI.Base.GClosure as B.GClosure
import qualified Data.GI.Base.GError as B.GError
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 Data.Text as T
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 {-# SOURCE #-} qualified GI.GLib.Structs.VariantType as GLib.VariantType

-- | Memory-managed wrapper type.
newtype VariantBuilder = VariantBuilder (ManagedPtr VariantBuilder)
    deriving (VariantBuilder -> VariantBuilder -> Bool
(VariantBuilder -> VariantBuilder -> Bool)
-> (VariantBuilder -> VariantBuilder -> Bool) -> Eq VariantBuilder
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: VariantBuilder -> VariantBuilder -> Bool
$c/= :: VariantBuilder -> VariantBuilder -> Bool
== :: VariantBuilder -> VariantBuilder -> Bool
$c== :: VariantBuilder -> VariantBuilder -> Bool
Eq)
foreign import ccall "g_variant_builder_get_type" c_g_variant_builder_get_type :: 
    IO GType

instance BoxedObject VariantBuilder where
    boxedType :: VariantBuilder -> IO GType
boxedType _ = IO GType
c_g_variant_builder_get_type

-- | Convert 'VariantBuilder' to and from 'Data.GI.Base.GValue.GValue' with 'Data.GI.Base.GValue.toGValue' and 'Data.GI.Base.GValue.fromGValue'.
instance B.GValue.IsGValue VariantBuilder where
    toGValue :: VariantBuilder -> IO GValue
toGValue o :: VariantBuilder
o = do
        GType
gtype <- IO GType
c_g_variant_builder_get_type
        VariantBuilder -> (Ptr VariantBuilder -> IO GValue) -> IO GValue
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
B.ManagedPtr.withManagedPtr VariantBuilder
o (GType
-> (GValue -> Ptr VariantBuilder -> IO ())
-> Ptr VariantBuilder
-> IO GValue
forall a. GType -> (GValue -> a -> IO ()) -> a -> IO GValue
B.GValue.buildGValue GType
gtype GValue -> Ptr VariantBuilder -> IO ()
forall a. GValue -> Ptr a -> IO ()
B.GValue.set_boxed)
        
    fromGValue :: GValue -> IO VariantBuilder
fromGValue gv :: GValue
gv = do
        Ptr VariantBuilder
ptr <- GValue -> IO (Ptr VariantBuilder)
forall b. GValue -> IO (Ptr b)
B.GValue.get_boxed GValue
gv :: IO (Ptr VariantBuilder)
        (ManagedPtr VariantBuilder -> VariantBuilder)
-> Ptr VariantBuilder -> IO VariantBuilder
forall a.
(HasCallStack, BoxedObject a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
B.ManagedPtr.newBoxed ManagedPtr VariantBuilder -> VariantBuilder
VariantBuilder Ptr VariantBuilder
ptr
        
    

-- | A convenience alias for `Nothing` :: `Maybe` `VariantBuilder`.
noVariantBuilder :: Maybe VariantBuilder
noVariantBuilder :: Maybe VariantBuilder
noVariantBuilder = Maybe VariantBuilder
forall a. Maybe a
Nothing


#if defined(ENABLE_OVERLOADING)
instance O.HasAttributeList VariantBuilder
type instance O.AttributeList VariantBuilder = VariantBuilderAttributeList
type VariantBuilderAttributeList = ('[ ] :: [(Symbol, *)])
#endif

-- method VariantBuilder::new
-- method type : Constructor
-- Args: [ Arg
--           { argCName = "type"
--           , argType =
--               TInterface Name { namespace = "GLib" , name = "VariantType" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a container type" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just
--               (TInterface Name { namespace = "GLib" , name = "VariantBuilder" })
-- throws : False
-- Skip return : False

foreign import ccall "g_variant_builder_new" g_variant_builder_new :: 
    Ptr GLib.VariantType.VariantType ->     -- type : TInterface (Name {namespace = "GLib", name = "VariantType"})
    IO (Ptr VariantBuilder)

-- | Allocates and initialises a new t'GI.GLib.Structs.VariantBuilder.VariantBuilder'.
-- 
-- You should call 'GI.GLib.Structs.VariantBuilder.variantBuilderUnref' on the return value when it
-- is no longer needed.  The memory will not be automatically freed by
-- any other call.
-- 
-- In most cases it is easier to place a t'GI.GLib.Structs.VariantBuilder.VariantBuilder' directly on
-- the stack of the calling function and initialise it with
-- @/g_variant_builder_init()/@.
-- 
-- /Since: 2.24/
variantBuilderNew ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    GLib.VariantType.VariantType
    -- ^ /@type@/: a container type
    -> m VariantBuilder
    -- ^ __Returns:__ a t'GI.GLib.Structs.VariantBuilder.VariantBuilder'
variantBuilderNew :: VariantType -> m VariantBuilder
variantBuilderNew type_ :: VariantType
type_ = IO VariantBuilder -> m VariantBuilder
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO VariantBuilder -> m VariantBuilder)
-> IO VariantBuilder -> m VariantBuilder
forall a b. (a -> b) -> a -> b
$ do
    Ptr VariantType
type_' <- VariantType -> IO (Ptr VariantType)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr VariantType
type_
    Ptr VariantBuilder
result <- Ptr VariantType -> IO (Ptr VariantBuilder)
g_variant_builder_new Ptr VariantType
type_'
    Text -> Ptr VariantBuilder -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL "variantBuilderNew" Ptr VariantBuilder
result
    VariantBuilder
result' <- ((ManagedPtr VariantBuilder -> VariantBuilder)
-> Ptr VariantBuilder -> IO VariantBuilder
forall a.
(HasCallStack, BoxedObject a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
wrapBoxed ManagedPtr VariantBuilder -> VariantBuilder
VariantBuilder) Ptr VariantBuilder
result
    VariantType -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr VariantType
type_
    VariantBuilder -> IO VariantBuilder
forall (m :: * -> *) a. Monad m => a -> m a
return VariantBuilder
result'

#if defined(ENABLE_OVERLOADING)
#endif

-- method VariantBuilder::add_value
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "builder"
--           , argType =
--               TInterface Name { namespace = "GLib" , name = "VariantBuilder" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GVariantBuilder" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "value"
--           , argType = TVariant
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GVariant" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Nothing
-- throws : False
-- Skip return : False

foreign import ccall "g_variant_builder_add_value" g_variant_builder_add_value :: 
    Ptr VariantBuilder ->                   -- builder : TInterface (Name {namespace = "GLib", name = "VariantBuilder"})
    Ptr GVariant ->                         -- value : TVariant
    IO ()

-- | Adds /@value@/ to /@builder@/.
-- 
-- It is an error to call this function in any way that would create an
-- inconsistent value to be constructed.  Some examples of this are
-- putting different types of items into an array, putting the wrong
-- types or number of items in a tuple, putting more than one value into
-- a variant, etc.
-- 
-- If /@value@/ is a floating reference (see 'GI.GLib.Structs.Variant.variantRefSink'),
-- the /@builder@/ instance takes ownership of /@value@/.
-- 
-- /Since: 2.24/
variantBuilderAddValue ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    VariantBuilder
    -- ^ /@builder@/: a t'GI.GLib.Structs.VariantBuilder.VariantBuilder'
    -> GVariant
    -- ^ /@value@/: a t'GVariant'
    -> m ()
variantBuilderAddValue :: VariantBuilder -> GVariant -> m ()
variantBuilderAddValue builder :: VariantBuilder
builder value :: GVariant
value = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    Ptr VariantBuilder
builder' <- VariantBuilder -> IO (Ptr VariantBuilder)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr VariantBuilder
builder
    Ptr GVariant
value' <- GVariant -> IO (Ptr GVariant)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr GVariant
value
    Ptr VariantBuilder -> Ptr GVariant -> IO ()
g_variant_builder_add_value Ptr VariantBuilder
builder' Ptr GVariant
value'
    VariantBuilder -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr VariantBuilder
builder
    GVariant -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr GVariant
value
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

#if defined(ENABLE_OVERLOADING)
data VariantBuilderAddValueMethodInfo
instance (signature ~ (GVariant -> m ()), MonadIO m) => O.MethodInfo VariantBuilderAddValueMethodInfo VariantBuilder signature where
    overloadedMethod = variantBuilderAddValue

#endif

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

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

-- | Closes the subcontainer inside the given /@builder@/ that was opened by
-- the most recent call to 'GI.GLib.Structs.VariantBuilder.variantBuilderOpen'.
-- 
-- It is an error to call this function in any way that would create an
-- inconsistent value to be constructed (ie: too few values added to the
-- subcontainer).
-- 
-- /Since: 2.24/
variantBuilderClose ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    VariantBuilder
    -- ^ /@builder@/: a t'GI.GLib.Structs.VariantBuilder.VariantBuilder'
    -> m ()
variantBuilderClose :: VariantBuilder -> m ()
variantBuilderClose builder :: VariantBuilder
builder = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    Ptr VariantBuilder
builder' <- VariantBuilder -> IO (Ptr VariantBuilder)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr VariantBuilder
builder
    Ptr VariantBuilder -> IO ()
g_variant_builder_close Ptr VariantBuilder
builder'
    VariantBuilder -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr VariantBuilder
builder
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

#if defined(ENABLE_OVERLOADING)
data VariantBuilderCloseMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.MethodInfo VariantBuilderCloseMethodInfo VariantBuilder signature where
    overloadedMethod = variantBuilderClose

#endif

-- method VariantBuilder::end
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "builder"
--           , argType =
--               TInterface Name { namespace = "GLib" , name = "VariantBuilder" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GVariantBuilder" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just TVariant
-- throws : False
-- Skip return : False

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

-- | Ends the builder process and returns the constructed value.
-- 
-- It is not permissible to use /@builder@/ in any way after this call
-- except for reference counting operations (in the case of a
-- heap-allocated t'GI.GLib.Structs.VariantBuilder.VariantBuilder') or by reinitialising it with
-- @/g_variant_builder_init()/@ (in the case of stack-allocated). This
-- means that for the stack-allocated builders there is no need to
-- call @/g_variant_builder_clear()/@ after the call to
-- 'GI.GLib.Structs.VariantBuilder.variantBuilderEnd'.
-- 
-- It is an error to call this function in any way that would create an
-- inconsistent value to be constructed (ie: insufficient number of
-- items added to a container with a specific number of children
-- required).  It is also an error to call this function if the builder
-- was created with an indefinite array or maybe type and no children
-- have been added; in this case it is impossible to infer the type of
-- the empty array.
-- 
-- /Since: 2.24/
variantBuilderEnd ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    VariantBuilder
    -- ^ /@builder@/: a t'GI.GLib.Structs.VariantBuilder.VariantBuilder'
    -> m GVariant
    -- ^ __Returns:__ a new, floating, t'GVariant'
variantBuilderEnd :: VariantBuilder -> m GVariant
variantBuilderEnd builder :: VariantBuilder
builder = IO GVariant -> m GVariant
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO GVariant -> m GVariant) -> IO GVariant -> m GVariant
forall a b. (a -> b) -> a -> b
$ do
    Ptr VariantBuilder
builder' <- VariantBuilder -> IO (Ptr VariantBuilder)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr VariantBuilder
builder
    Ptr GVariant
result <- Ptr VariantBuilder -> IO (Ptr GVariant)
g_variant_builder_end Ptr VariantBuilder
builder'
    Text -> Ptr GVariant -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL "variantBuilderEnd" Ptr GVariant
result
    GVariant
result' <- Ptr GVariant -> IO GVariant
B.GVariant.newGVariantFromPtr Ptr GVariant
result
    VariantBuilder -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr VariantBuilder
builder
    GVariant -> IO GVariant
forall (m :: * -> *) a. Monad m => a -> m a
return GVariant
result'

#if defined(ENABLE_OVERLOADING)
data VariantBuilderEndMethodInfo
instance (signature ~ (m GVariant), MonadIO m) => O.MethodInfo VariantBuilderEndMethodInfo VariantBuilder signature where
    overloadedMethod = variantBuilderEnd

#endif

-- method VariantBuilder::open
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "builder"
--           , argType =
--               TInterface Name { namespace = "GLib" , name = "VariantBuilder" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GVariantBuilder" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "type"
--           , argType =
--               TInterface Name { namespace = "GLib" , name = "VariantType" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the #GVariantType of the container"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Nothing
-- throws : False
-- Skip return : False

foreign import ccall "g_variant_builder_open" g_variant_builder_open :: 
    Ptr VariantBuilder ->                   -- builder : TInterface (Name {namespace = "GLib", name = "VariantBuilder"})
    Ptr GLib.VariantType.VariantType ->     -- type : TInterface (Name {namespace = "GLib", name = "VariantType"})
    IO ()

-- | Opens a subcontainer inside the given /@builder@/.  When done adding
-- items to the subcontainer, 'GI.GLib.Structs.VariantBuilder.variantBuilderClose' must be called. /@type@/
-- is the type of the container: so to build a tuple of several values, /@type@/
-- must include the tuple itself.
-- 
-- It is an error to call this function in any way that would cause an
-- inconsistent value to be constructed (ie: adding too many values or
-- a value of an incorrect type).
-- 
-- Example of building a nested variant:
-- 
-- === /C code/
-- >
-- >GVariantBuilder builder;
-- >guint32 some_number = get_number ();
-- >g_autoptr (GHashTable) some_dict = get_dict ();
-- >GHashTableIter iter;
-- >const gchar *key;
-- >const GVariant *value;
-- >g_autoptr (GVariant) output = NULL;
-- >
-- >g_variant_builder_init (&builder, G_VARIANT_TYPE ("(ua{sv})"));
-- >g_variant_builder_add (&builder, "u", some_number);
-- >g_variant_builder_open (&builder, G_VARIANT_TYPE ("a{sv}"));
-- >
-- >g_hash_table_iter_init (&iter, some_dict);
-- >while (g_hash_table_iter_next (&iter, (gpointer *) &key, (gpointer *) &value))
-- >  {
-- >    g_variant_builder_open (&builder, G_VARIANT_TYPE ("{sv}"));
-- >    g_variant_builder_add (&builder, "s", key);
-- >    g_variant_builder_add (&builder, "v", value);
-- >    g_variant_builder_close (&builder);
-- >  }
-- >
-- >g_variant_builder_close (&builder);
-- >
-- >output = g_variant_builder_end (&builder);
-- 
-- 
-- /Since: 2.24/
variantBuilderOpen ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    VariantBuilder
    -- ^ /@builder@/: a t'GI.GLib.Structs.VariantBuilder.VariantBuilder'
    -> GLib.VariantType.VariantType
    -- ^ /@type@/: the t'GI.GLib.Structs.VariantType.VariantType' of the container
    -> m ()
variantBuilderOpen :: VariantBuilder -> VariantType -> m ()
variantBuilderOpen builder :: VariantBuilder
builder type_ :: VariantType
type_ = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    Ptr VariantBuilder
builder' <- VariantBuilder -> IO (Ptr VariantBuilder)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr VariantBuilder
builder
    Ptr VariantType
type_' <- VariantType -> IO (Ptr VariantType)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr VariantType
type_
    Ptr VariantBuilder -> Ptr VariantType -> IO ()
g_variant_builder_open Ptr VariantBuilder
builder' Ptr VariantType
type_'
    VariantBuilder -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr VariantBuilder
builder
    VariantType -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr VariantType
type_
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

#if defined(ENABLE_OVERLOADING)
data VariantBuilderOpenMethodInfo
instance (signature ~ (GLib.VariantType.VariantType -> m ()), MonadIO m) => O.MethodInfo VariantBuilderOpenMethodInfo VariantBuilder signature where
    overloadedMethod = variantBuilderOpen

#endif

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

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

-- | Increases the reference count on /@builder@/.
-- 
-- Don\'t call this on stack-allocated t'GI.GLib.Structs.VariantBuilder.VariantBuilder' instances or bad
-- things will happen.
-- 
-- /Since: 2.24/
variantBuilderRef ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    VariantBuilder
    -- ^ /@builder@/: a t'GI.GLib.Structs.VariantBuilder.VariantBuilder' allocated by 'GI.GLib.Structs.VariantBuilder.variantBuilderNew'
    -> m VariantBuilder
    -- ^ __Returns:__ a new reference to /@builder@/
variantBuilderRef :: VariantBuilder -> m VariantBuilder
variantBuilderRef builder :: VariantBuilder
builder = IO VariantBuilder -> m VariantBuilder
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO VariantBuilder -> m VariantBuilder)
-> IO VariantBuilder -> m VariantBuilder
forall a b. (a -> b) -> a -> b
$ do
    Ptr VariantBuilder
builder' <- VariantBuilder -> IO (Ptr VariantBuilder)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr VariantBuilder
builder
    Ptr VariantBuilder
result <- Ptr VariantBuilder -> IO (Ptr VariantBuilder)
g_variant_builder_ref Ptr VariantBuilder
builder'
    Text -> Ptr VariantBuilder -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL "variantBuilderRef" Ptr VariantBuilder
result
    VariantBuilder
result' <- ((ManagedPtr VariantBuilder -> VariantBuilder)
-> Ptr VariantBuilder -> IO VariantBuilder
forall a.
(HasCallStack, BoxedObject a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
wrapBoxed ManagedPtr VariantBuilder -> VariantBuilder
VariantBuilder) Ptr VariantBuilder
result
    VariantBuilder -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr VariantBuilder
builder
    VariantBuilder -> IO VariantBuilder
forall (m :: * -> *) a. Monad m => a -> m a
return VariantBuilder
result'

#if defined(ENABLE_OVERLOADING)
data VariantBuilderRefMethodInfo
instance (signature ~ (m VariantBuilder), MonadIO m) => O.MethodInfo VariantBuilderRefMethodInfo VariantBuilder signature where
    overloadedMethod = variantBuilderRef

#endif

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

foreign import ccall "g_variant_builder_unref" g_variant_builder_unref :: 
    Ptr VariantBuilder ->                   -- builder : TInterface (Name {namespace = "GLib", name = "VariantBuilder"})
    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.VariantBuilder.VariantBuilder'.
-- 
-- Don\'t call this on stack-allocated t'GI.GLib.Structs.VariantBuilder.VariantBuilder' instances or bad
-- things will happen.
-- 
-- /Since: 2.24/
variantBuilderUnref ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    VariantBuilder
    -- ^ /@builder@/: a t'GI.GLib.Structs.VariantBuilder.VariantBuilder' allocated by 'GI.GLib.Structs.VariantBuilder.variantBuilderNew'
    -> m ()
variantBuilderUnref :: VariantBuilder -> m ()
variantBuilderUnref builder :: VariantBuilder
builder = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    Ptr VariantBuilder
builder' <- VariantBuilder -> IO (Ptr VariantBuilder)
forall a. (HasCallStack, BoxedObject a) => a -> IO (Ptr a)
B.ManagedPtr.disownBoxed VariantBuilder
builder
    Ptr VariantBuilder -> IO ()
g_variant_builder_unref Ptr VariantBuilder
builder'
    VariantBuilder -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr VariantBuilder
builder
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

#if defined(ENABLE_OVERLOADING)
data VariantBuilderUnrefMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.MethodInfo VariantBuilderUnrefMethodInfo VariantBuilder signature where
    overloadedMethod = variantBuilderUnref

#endif

#if defined(ENABLE_OVERLOADING)
type family ResolveVariantBuilderMethod (t :: Symbol) (o :: *) :: * where
    ResolveVariantBuilderMethod "addValue" o = VariantBuilderAddValueMethodInfo
    ResolveVariantBuilderMethod "close" o = VariantBuilderCloseMethodInfo
    ResolveVariantBuilderMethod "end" o = VariantBuilderEndMethodInfo
    ResolveVariantBuilderMethod "open" o = VariantBuilderOpenMethodInfo
    ResolveVariantBuilderMethod "ref" o = VariantBuilderRefMethodInfo
    ResolveVariantBuilderMethod "unref" o = VariantBuilderUnrefMethodInfo
    ResolveVariantBuilderMethod l o = O.MethodResolutionFailed l o

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

#endif