    {- |
    Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
    License    : LGPL-2.1
    Maintainer : Iñaki García Etxebarria (garetxe@gmail.com)

    The GTree struct is an opaque data structure representing a
    [balanced binary tree][glib-Balanced-Binary-Trees]. It should be
    accessed only by using the following functions.
    -}

    #define ENABLE_OVERLOADING \
           (!defined(__HADDOCK_VERSION__))

    module GI.GLib.Structs.Tree
        (

    -- * Exported types
        Tree(..)                                ,
        noTree                                  ,

     -- * Methods
    -- ** destroy #method:destroy#

    #if ENABLE_OVERLOADING
        TreeDestroyMethodInfo                   ,
    #endif
        treeDestroy                             ,

    -- ** height #method:height#

    #if ENABLE_OVERLOADING
        TreeHeightMethodInfo                    ,
    #endif
        treeHeight                              ,

    -- ** insert #method:insert#

    #if ENABLE_OVERLOADING
        TreeInsertMethodInfo                    ,
    #endif
        treeInsert                              ,

    -- ** lookup #method:lookup#

    #if ENABLE_OVERLOADING
        TreeLookupMethodInfo                    ,
    #endif
        treeLookup                              ,

    -- ** lookupExtended #method:lookupExtended#

    #if ENABLE_OVERLOADING
        TreeLookupExtendedMethodInfo            ,
    #endif
        treeLookupExtended                      ,

    -- ** nnodes #method:nnodes#

    #if ENABLE_OVERLOADING
        TreeNnodesMethodInfo                    ,
    #endif
        treeNnodes                              ,

    -- ** remove #method:remove#

    #if ENABLE_OVERLOADING
        TreeRemoveMethodInfo                    ,
    #endif
        treeRemove                              ,

    -- ** replace #method:replace#

    #if ENABLE_OVERLOADING
        TreeReplaceMethodInfo                   ,
    #endif
        treeReplace                             ,

    -- ** steal #method:steal#

    #if ENABLE_OVERLOADING
        TreeStealMethodInfo                     ,
    #endif
        treeSteal                               ,

    -- ** unref #method:unref#

    #if ENABLE_OVERLOADING
        TreeUnrefMethodInfo                     ,
    #endif
        treeUnref                               ,

        ) 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.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.Text as T
    import qualified Data.ByteString.Char8 as B
    import qualified Data.Map as Map
    import qualified Foreign.Ptr as FP

    -- | Memory-managed wrapper type.
    newtype Tree = Tree (ManagedPtr Tree)
    -- XXX Wrapping a foreign struct/union with no known destructor or size, leak?
    instance WrappedPtr Tree where
        wrappedPtrCalloc = return nullPtr
        wrappedPtrCopy = return
        wrappedPtrFree = Nothing

    -- | A convenience alias for `Nothing` :: `Maybe` `Tree`.
    noTree :: Maybe Tree
    noTree = Nothing

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

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

    foreign import ccall "g_tree_destroy" g_tree_destroy ::
        Ptr Tree ->                             -- tree : TInterface (Name {namespace = "GLib", name = "Tree"})
        IO ()

    {- |
    Removes all keys and values from the 'GI.GLib.Structs.Tree.Tree' and decreases its
    reference count by one. If keys and\/or values are dynamically
    allocated, you should either free them first or create the 'GI.GLib.Structs.Tree.Tree'
    using @/g_tree_new_full()/@. In the latter case the destroy functions
    you supplied will be called on all keys and values before destroying
    the 'GI.GLib.Structs.Tree.Tree'.
    -}
    treeDestroy ::
        (B.CallStack.HasCallStack, MonadIO m) =>
        Tree
        {- ^ /@tree@/: a 'GI.GLib.Structs.Tree.Tree' -}
        -> m ()
    treeDestroy tree = liftIO $ do
        tree' <- unsafeManagedPtrGetPtr tree
        g_tree_destroy tree'
        touchManagedPtr tree
        return ()

    #if ENABLE_OVERLOADING
    data TreeDestroyMethodInfo
    instance (signature ~ (m ()), MonadIO m) => O.MethodInfo TreeDestroyMethodInfo Tree signature where
        overloadedMethod _ = treeDestroy

    #endif

    -- method Tree::height
    -- method type : OrdinaryMethod
    -- Args : [Arg {argCName = "tree", argType = TInterface (Name {namespace = "GLib", name = "Tree"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GTree", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
    -- Lengths : []
    -- returnType : Just (TBasicType TInt)
    -- throws : False
    -- Skip return : False

    foreign import ccall "g_tree_height" g_tree_height ::
        Ptr Tree ->                             -- tree : TInterface (Name {namespace = "GLib", name = "Tree"})
        IO Int32

    {- |
    Gets the height of a 'GI.GLib.Structs.Tree.Tree'.

    If the 'GI.GLib.Structs.Tree.Tree' contains no nodes, the height is 0.
    If the 'GI.GLib.Structs.Tree.Tree' contains only one root node the height is 1.
    If the root node has children the height is 2, etc.
    -}
    treeHeight ::
        (B.CallStack.HasCallStack, MonadIO m) =>
        Tree
        {- ^ /@tree@/: a 'GI.GLib.Structs.Tree.Tree' -}
        -> m Int32
        {- ^ __Returns:__ the height of /@tree@/ -}
    treeHeight tree = liftIO $ do
        tree' <- unsafeManagedPtrGetPtr tree
        result <- g_tree_height tree'
        touchManagedPtr tree
        return result

    #if ENABLE_OVERLOADING
    data TreeHeightMethodInfo
    instance (signature ~ (m Int32), MonadIO m) => O.MethodInfo TreeHeightMethodInfo Tree signature where
        overloadedMethod _ = treeHeight

    #endif

    -- method Tree::insert
    -- method type : OrdinaryMethod
    -- Args : [Arg {argCName = "tree", argType = TInterface (Name {namespace = "GLib", name = "Tree"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GTree", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "key", argType = TBasicType TPtr, direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "the key to insert", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "value", argType = TBasicType TPtr, direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "the value corresponding to the key", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
    -- Lengths : []
    -- returnType : Nothing
    -- throws : False
    -- Skip return : False

    foreign import ccall "g_tree_insert" g_tree_insert ::
        Ptr Tree ->                             -- tree : TInterface (Name {namespace = "GLib", name = "Tree"})
        Ptr () ->                               -- key : TBasicType TPtr
        Ptr () ->                               -- value : TBasicType TPtr
        IO ()

    {- |
    Inserts a key\/value pair into a 'GI.GLib.Structs.Tree.Tree'.

    If the given key already exists in the 'GI.GLib.Structs.Tree.Tree' its corresponding value
    is set to the new value. If you supplied a /@valueDestroyFunc@/ when
    creating the 'GI.GLib.Structs.Tree.Tree', the old value is freed using that function. If
    you supplied a /@keyDestroyFunc@/ when creating the 'GI.GLib.Structs.Tree.Tree', the passed
    key is freed using that function.

    The tree is automatically \'balanced\' as new key\/value pairs are added,
    so that the distance from the root to every leaf is as small as possible.
    -}
    treeInsert ::
        (B.CallStack.HasCallStack, MonadIO m) =>
        Tree
        {- ^ /@tree@/: a 'GI.GLib.Structs.Tree.Tree' -}
        -> Ptr ()
        {- ^ /@key@/: the key to insert -}
        -> Ptr ()
        {- ^ /@value@/: the value corresponding to the key -}
        -> m ()
    treeInsert tree key value = liftIO $ do
        tree' <- unsafeManagedPtrGetPtr tree
        g_tree_insert tree' key value
        touchManagedPtr tree
        return ()

    #if ENABLE_OVERLOADING
    data TreeInsertMethodInfo
    instance (signature ~ (Ptr () -> Ptr () -> m ()), MonadIO m) => O.MethodInfo TreeInsertMethodInfo Tree signature where
        overloadedMethod _ = treeInsert

    #endif

    -- method Tree::lookup
    -- method type : OrdinaryMethod
    -- Args : [Arg {argCName = "tree", argType = TInterface (Name {namespace = "GLib", name = "Tree"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GTree", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "key", argType = TBasicType TPtr, direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "the key to look up", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
    -- Lengths : []
    -- returnType : Just (TBasicType TPtr)
    -- throws : False
    -- Skip return : False

    foreign import ccall "g_tree_lookup" g_tree_lookup ::
        Ptr Tree ->                             -- tree : TInterface (Name {namespace = "GLib", name = "Tree"})
        Ptr () ->                               -- key : TBasicType TPtr
        IO (Ptr ())

    {- |
    Gets the value corresponding to the given key. Since a 'GI.GLib.Structs.Tree.Tree' is
    automatically balanced as key\/value pairs are added, key lookup
    is O(log n) (where n is the number of key\/value pairs in the tree).
    -}
    treeLookup ::
        (B.CallStack.HasCallStack, MonadIO m) =>
        Tree
        {- ^ /@tree@/: a 'GI.GLib.Structs.Tree.Tree' -}
        -> Ptr ()
        {- ^ /@key@/: the key to look up -}
        -> m (Ptr ())
        {- ^ __Returns:__ the value corresponding to the key, or 'Nothing'
        if the key was not found -}
    treeLookup tree key = liftIO $ do
        tree' <- unsafeManagedPtrGetPtr tree
        result <- g_tree_lookup tree' key
        touchManagedPtr tree
        return result

    #if ENABLE_OVERLOADING
    data TreeLookupMethodInfo
    instance (signature ~ (Ptr () -> m (Ptr ())), MonadIO m) => O.MethodInfo TreeLookupMethodInfo Tree signature where
        overloadedMethod _ = treeLookup

    #endif

    -- method Tree::lookup_extended
    -- method type : OrdinaryMethod
    -- Args : [Arg {argCName = "tree", argType = TInterface (Name {namespace = "GLib", name = "Tree"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GTree", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "lookup_key", argType = TBasicType TPtr, direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "the key to look up", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "orig_key", argType = TBasicType TPtr, direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "returns the original key", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "value", argType = TBasicType TPtr, direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "returns the value associated with the key", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
    -- Lengths : []
    -- returnType : Just (TBasicType TBoolean)
    -- throws : False
    -- Skip return : False

    foreign import ccall "g_tree_lookup_extended" g_tree_lookup_extended ::
        Ptr Tree ->                             -- tree : TInterface (Name {namespace = "GLib", name = "Tree"})
        Ptr () ->                               -- lookup_key : TBasicType TPtr
        Ptr () ->                               -- orig_key : TBasicType TPtr
        Ptr () ->                               -- value : TBasicType TPtr
        IO CInt

    {- |
    Looks up a key in the 'GI.GLib.Structs.Tree.Tree', returning the original key and the
    associated value. This is useful if you need to free the memory
    allocated for the original key, for example before calling
    'GI.GLib.Structs.Tree.treeRemove'.
    -}
    treeLookupExtended ::
        (B.CallStack.HasCallStack, MonadIO m) =>
        Tree
        {- ^ /@tree@/: a 'GI.GLib.Structs.Tree.Tree' -}
        -> Ptr ()
        {- ^ /@lookupKey@/: the key to look up -}
        -> Ptr ()
        {- ^ /@origKey@/: returns the original key -}
        -> Ptr ()
        {- ^ /@value@/: returns the value associated with the key -}
        -> m Bool
        {- ^ __Returns:__ 'True' if the key was found in the 'GI.GLib.Structs.Tree.Tree' -}
    treeLookupExtended tree lookupKey origKey value = liftIO $ do
        tree' <- unsafeManagedPtrGetPtr tree
        result <- g_tree_lookup_extended tree' lookupKey origKey value
        let result' = (/= 0) result
        touchManagedPtr tree
        return result'

    #if ENABLE_OVERLOADING
    data TreeLookupExtendedMethodInfo
    instance (signature ~ (Ptr () -> Ptr () -> Ptr () -> m Bool), MonadIO m) => O.MethodInfo TreeLookupExtendedMethodInfo Tree signature where
        overloadedMethod _ = treeLookupExtended

    #endif

    -- method Tree::nnodes
    -- method type : OrdinaryMethod
    -- Args : [Arg {argCName = "tree", argType = TInterface (Name {namespace = "GLib", name = "Tree"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GTree", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
    -- Lengths : []
    -- returnType : Just (TBasicType TInt)
    -- throws : False
    -- Skip return : False

    foreign import ccall "g_tree_nnodes" g_tree_nnodes ::
        Ptr Tree ->                             -- tree : TInterface (Name {namespace = "GLib", name = "Tree"})
        IO Int32

    {- |
    Gets the number of nodes in a 'GI.GLib.Structs.Tree.Tree'.
    -}
    treeNnodes ::
        (B.CallStack.HasCallStack, MonadIO m) =>
        Tree
        {- ^ /@tree@/: a 'GI.GLib.Structs.Tree.Tree' -}
        -> m Int32
        {- ^ __Returns:__ the number of nodes in /@tree@/ -}
    treeNnodes tree = liftIO $ do
        tree' <- unsafeManagedPtrGetPtr tree
        result <- g_tree_nnodes tree'
        touchManagedPtr tree
        return result

    #if ENABLE_OVERLOADING
    data TreeNnodesMethodInfo
    instance (signature ~ (m Int32), MonadIO m) => O.MethodInfo TreeNnodesMethodInfo Tree signature where
        overloadedMethod _ = treeNnodes

    #endif

    -- method Tree::remove
    -- method type : OrdinaryMethod
    -- Args : [Arg {argCName = "tree", argType = TInterface (Name {namespace = "GLib", name = "Tree"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GTree", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "key", argType = TBasicType TPtr, direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "the key to remove", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
    -- Lengths : []
    -- returnType : Just (TBasicType TBoolean)
    -- throws : False
    -- Skip return : False

    foreign import ccall "g_tree_remove" g_tree_remove ::
        Ptr Tree ->                             -- tree : TInterface (Name {namespace = "GLib", name = "Tree"})
        Ptr () ->                               -- key : TBasicType TPtr
        IO CInt

    {- |
    Removes a key\/value pair from a 'GI.GLib.Structs.Tree.Tree'.

    If the 'GI.GLib.Structs.Tree.Tree' was created using @/g_tree_new_full()/@, the key and value
    are freed using the supplied destroy functions, otherwise you have to
    make sure that any dynamically allocated values are freed yourself.
    If the key does not exist in the 'GI.GLib.Structs.Tree.Tree', the function does nothing.
    -}
    treeRemove ::
        (B.CallStack.HasCallStack, MonadIO m) =>
        Tree
        {- ^ /@tree@/: a 'GI.GLib.Structs.Tree.Tree' -}
        -> Ptr ()
        {- ^ /@key@/: the key to remove -}
        -> m Bool
        {- ^ __Returns:__ 'True' if the key was found (prior to 2.8, this function
        returned nothing) -}
    treeRemove tree key = liftIO $ do
        tree' <- unsafeManagedPtrGetPtr tree
        result <- g_tree_remove tree' key
        let result' = (/= 0) result
        touchManagedPtr tree
        return result'

    #if ENABLE_OVERLOADING
    data TreeRemoveMethodInfo
    instance (signature ~ (Ptr () -> m Bool), MonadIO m) => O.MethodInfo TreeRemoveMethodInfo Tree signature where
        overloadedMethod _ = treeRemove

    #endif

    -- method Tree::replace
    -- method type : OrdinaryMethod
    -- Args : [Arg {argCName = "tree", argType = TInterface (Name {namespace = "GLib", name = "Tree"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GTree", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "key", argType = TBasicType TPtr, direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "the key to insert", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "value", argType = TBasicType TPtr, direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "the value corresponding to the key", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
    -- Lengths : []
    -- returnType : Nothing
    -- throws : False
    -- Skip return : False

    foreign import ccall "g_tree_replace" g_tree_replace ::
        Ptr Tree ->                             -- tree : TInterface (Name {namespace = "GLib", name = "Tree"})
        Ptr () ->                               -- key : TBasicType TPtr
        Ptr () ->                               -- value : TBasicType TPtr
        IO ()

    {- |
    Inserts a new key and value into a 'GI.GLib.Structs.Tree.Tree' similar to 'GI.GLib.Structs.Tree.treeInsert'.
    The difference is that if the key already exists in the 'GI.GLib.Structs.Tree.Tree', it gets
    replaced by the new key. If you supplied a /@valueDestroyFunc@/ when
    creating the 'GI.GLib.Structs.Tree.Tree', the old value is freed using that function. If you
    supplied a /@keyDestroyFunc@/ when creating the 'GI.GLib.Structs.Tree.Tree', the old key is
    freed using that function.

    The tree is automatically \'balanced\' as new key\/value pairs are added,
    so that the distance from the root to every leaf is as small as possible.
    -}
    treeReplace ::
        (B.CallStack.HasCallStack, MonadIO m) =>
        Tree
        {- ^ /@tree@/: a 'GI.GLib.Structs.Tree.Tree' -}
        -> Ptr ()
        {- ^ /@key@/: the key to insert -}
        -> Ptr ()
        {- ^ /@value@/: the value corresponding to the key -}
        -> m ()
    treeReplace tree key value = liftIO $ do
        tree' <- unsafeManagedPtrGetPtr tree
        g_tree_replace tree' key value
        touchManagedPtr tree
        return ()

    #if ENABLE_OVERLOADING
    data TreeReplaceMethodInfo
    instance (signature ~ (Ptr () -> Ptr () -> m ()), MonadIO m) => O.MethodInfo TreeReplaceMethodInfo Tree signature where
        overloadedMethod _ = treeReplace

    #endif

    -- method Tree::steal
    -- method type : OrdinaryMethod
    -- Args : [Arg {argCName = "tree", argType = TInterface (Name {namespace = "GLib", name = "Tree"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GTree", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "key", argType = TBasicType TPtr, direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "the key to remove", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
    -- Lengths : []
    -- returnType : Just (TBasicType TBoolean)
    -- throws : False
    -- Skip return : False

    foreign import ccall "g_tree_steal" g_tree_steal ::
        Ptr Tree ->                             -- tree : TInterface (Name {namespace = "GLib", name = "Tree"})
        Ptr () ->                               -- key : TBasicType TPtr
        IO CInt

    {- |
    Removes a key and its associated value from a 'GI.GLib.Structs.Tree.Tree' without calling
    the key and value destroy functions.

    If the key does not exist in the 'GI.GLib.Structs.Tree.Tree', the function does nothing.
    -}
    treeSteal ::
        (B.CallStack.HasCallStack, MonadIO m) =>
        Tree
        {- ^ /@tree@/: a 'GI.GLib.Structs.Tree.Tree' -}
        -> Ptr ()
        {- ^ /@key@/: the key to remove -}
        -> m Bool
        {- ^ __Returns:__ 'True' if the key was found (prior to 2.8, this function
        returned nothing) -}
    treeSteal tree key = liftIO $ do
        tree' <- unsafeManagedPtrGetPtr tree
        result <- g_tree_steal tree' key
        let result' = (/= 0) result
        touchManagedPtr tree
        return result'

    #if ENABLE_OVERLOADING
    data TreeStealMethodInfo
    instance (signature ~ (Ptr () -> m Bool), MonadIO m) => O.MethodInfo TreeStealMethodInfo Tree signature where
        overloadedMethod _ = treeSteal

    #endif

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

    foreign import ccall "g_tree_unref" g_tree_unref ::
        Ptr Tree ->                             -- tree : TInterface (Name {namespace = "GLib", name = "Tree"})
        IO ()

    {- |
    Decrements the reference count of /@tree@/ by one.
    If the reference count drops to 0, all keys and values will
    be destroyed (if destroy functions were specified) and all
    memory allocated by /@tree@/ will be released.

    It is safe to call this function from any thread.

    /Since: 2.22/
    -}
    treeUnref ::
        (B.CallStack.HasCallStack, MonadIO m) =>
        Tree
        {- ^ /@tree@/: a 'GI.GLib.Structs.Tree.Tree' -}
        -> m ()
    treeUnref tree = liftIO $ do
        tree' <- unsafeManagedPtrGetPtr tree
        g_tree_unref tree'
        touchManagedPtr tree
        return ()

    #if ENABLE_OVERLOADING
    data TreeUnrefMethodInfo
    instance (signature ~ (m ()), MonadIO m) => O.MethodInfo TreeUnrefMethodInfo Tree signature where
        overloadedMethod _ = treeUnref

    #endif

    #if ENABLE_OVERLOADING
    type family ResolveTreeMethod (t :: Symbol) (o :: *) :: * where
        ResolveTreeMethod "destroy" o = TreeDestroyMethodInfo
        ResolveTreeMethod "height" o = TreeHeightMethodInfo
        ResolveTreeMethod "insert" o = TreeInsertMethodInfo
        ResolveTreeMethod "lookup" o = TreeLookupMethodInfo
        ResolveTreeMethod "lookupExtended" o = TreeLookupExtendedMethodInfo
        ResolveTreeMethod "nnodes" o = TreeNnodesMethodInfo
        ResolveTreeMethod "remove" o = TreeRemoveMethodInfo
        ResolveTreeMethod "replace" o = TreeReplaceMethodInfo
        ResolveTreeMethod "steal" o = TreeStealMethodInfo
        ResolveTreeMethod "unref" o = TreeUnrefMethodInfo
        ResolveTreeMethod l o = O.MethodResolutionFailed l o

    instance (info ~ ResolveTreeMethod t Tree, O.MethodInfo info Tree p) => O.IsLabelProxy t (Tree -> p) where
        fromLabelProxy _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)

    #if MIN_VERSION_base(4,9,0)
    instance (info ~ ResolveTreeMethod t Tree, O.MethodInfo info Tree p) => O.IsLabel t (Tree -> p) where
    #if MIN_VERSION_base(4,10,0)
        fromLabel = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
    #else
        fromLabel _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
    #endif
    #endif

    #endif