packages feed

gi-glib-0.2.46.13: GI/GLib/Structs/HashTableIter.hs


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

A GHashTableIter structure represents an iterator that can be used
to iterate over the elements of a #GHashTable. GHashTableIter
structures are typically allocated on the stack and then initialized
with g_hash_table_iter_init().
-}

module GI.GLib.Structs.HashTableIter
    ( 

-- * Exported types
    HashTableIter(..)                       ,
    newZeroHashTableIter                    ,
    noHashTableIter                         ,


 -- * Methods
-- ** hashTableIterInit
    HashTableIterInitMethodInfo             ,
    hashTableIterInit                       ,


-- ** hashTableIterNext
    HashTableIterNextMethodInfo             ,
    hashTableIterNext                       ,


-- ** hashTableIterRemove
    HashTableIterRemoveMethodInfo           ,
    hashTableIterRemove                     ,


-- ** hashTableIterReplace
    HashTableIterReplaceMethodInfo          ,
    hashTableIterReplace                    ,


-- ** hashTableIterSteal
    HashTableIterStealMethodInfo            ,
    hashTableIterSteal                      ,




    ) where

import Prelude ()
import Data.GI.Base.ShortPrelude

import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map

import GI.GLib.Types
import GI.GLib.Callbacks

newtype HashTableIter = HashTableIter (ForeignPtr HashTableIter)
-- | Construct a `HashTableIter` struct initialized to zero.
newZeroHashTableIter :: MonadIO m => m HashTableIter
newZeroHashTableIter = liftIO $ callocBytes 40 >>= wrapPtr HashTableIter

noHashTableIter :: Maybe HashTableIter
noHashTableIter = Nothing

-- method HashTableIter::init
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "_obj", argType = TInterface "GLib" "HashTableIter", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "hash_table", argType = TGHash (TBasicType TVoid) (TBasicType TVoid), direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "g_hash_table_iter_init" g_hash_table_iter_init :: 
    Ptr HashTableIter ->                    -- _obj : TInterface "GLib" "HashTableIter"
    Ptr (GHashTable (Ptr ()) (Ptr ())) ->   -- hash_table : TGHash (TBasicType TVoid) (TBasicType TVoid)
    IO ()


hashTableIterInit ::
    (MonadIO m) =>
    HashTableIter                           -- _obj
    -> Map.Map (Ptr ()) (Ptr ())            -- hashTable
    -> m ()                                 -- result
hashTableIterInit _obj hashTable = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    let hashTable' = Map.toList hashTable
    let hashTable'' = mapFirst ptrPackPtr hashTable'
    let hashTable''' = mapSecond ptrPackPtr hashTable''
    hashTable'''' <- packGHashTable gDirectHash gDirectEqual Nothing Nothing hashTable'''
    g_hash_table_iter_init _obj' hashTable''''
    touchManagedPtr _obj
    unrefGHashTable hashTable''''
    return ()

data HashTableIterInitMethodInfo
instance (signature ~ (Map.Map (Ptr ()) (Ptr ()) -> m ()), MonadIO m) => MethodInfo HashTableIterInitMethodInfo HashTableIter signature where
    overloadedMethod _ = hashTableIterInit

-- method HashTableIter::next
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "_obj", argType = TInterface "GLib" "HashTableIter", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "key", argType = TBasicType TVoid, direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "value", argType = TBasicType TVoid, direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : TBasicType TBoolean
-- throws : False
-- Skip return : False

foreign import ccall "g_hash_table_iter_next" g_hash_table_iter_next :: 
    Ptr HashTableIter ->                    -- _obj : TInterface "GLib" "HashTableIter"
    Ptr () ->                               -- key : TBasicType TVoid
    Ptr () ->                               -- value : TBasicType TVoid
    IO CInt


hashTableIterNext ::
    (MonadIO m) =>
    HashTableIter                           -- _obj
    -> Maybe (Ptr ())                       -- key
    -> Maybe (Ptr ())                       -- value
    -> m Bool                               -- result
hashTableIterNext _obj key value = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    maybeKey <- case key of
        Nothing -> return nullPtr
        Just jKey -> do
            return jKey
    maybeValue <- case value of
        Nothing -> return nullPtr
        Just jValue -> do
            return jValue
    result <- g_hash_table_iter_next _obj' maybeKey maybeValue
    let result' = (/= 0) result
    touchManagedPtr _obj
    return result'

data HashTableIterNextMethodInfo
instance (signature ~ (Maybe (Ptr ()) -> Maybe (Ptr ()) -> m Bool), MonadIO m) => MethodInfo HashTableIterNextMethodInfo HashTableIter signature where
    overloadedMethod _ = hashTableIterNext

-- method HashTableIter::remove
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "_obj", argType = TInterface "GLib" "HashTableIter", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "g_hash_table_iter_remove" g_hash_table_iter_remove :: 
    Ptr HashTableIter ->                    -- _obj : TInterface "GLib" "HashTableIter"
    IO ()


hashTableIterRemove ::
    (MonadIO m) =>
    HashTableIter                           -- _obj
    -> m ()                                 -- result
hashTableIterRemove _obj = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    g_hash_table_iter_remove _obj'
    touchManagedPtr _obj
    return ()

data HashTableIterRemoveMethodInfo
instance (signature ~ (m ()), MonadIO m) => MethodInfo HashTableIterRemoveMethodInfo HashTableIter signature where
    overloadedMethod _ = hashTableIterRemove

-- method HashTableIter::replace
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "_obj", argType = TInterface "GLib" "HashTableIter", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "value", argType = TBasicType TVoid, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "g_hash_table_iter_replace" g_hash_table_iter_replace :: 
    Ptr HashTableIter ->                    -- _obj : TInterface "GLib" "HashTableIter"
    Ptr () ->                               -- value : TBasicType TVoid
    IO ()


hashTableIterReplace ::
    (MonadIO m) =>
    HashTableIter                           -- _obj
    -> Ptr ()                               -- value
    -> m ()                                 -- result
hashTableIterReplace _obj value = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    g_hash_table_iter_replace _obj' value
    touchManagedPtr _obj
    return ()

data HashTableIterReplaceMethodInfo
instance (signature ~ (Ptr () -> m ()), MonadIO m) => MethodInfo HashTableIterReplaceMethodInfo HashTableIter signature where
    overloadedMethod _ = hashTableIterReplace

-- method HashTableIter::steal
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "_obj", argType = TInterface "GLib" "HashTableIter", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "g_hash_table_iter_steal" g_hash_table_iter_steal :: 
    Ptr HashTableIter ->                    -- _obj : TInterface "GLib" "HashTableIter"
    IO ()


hashTableIterSteal ::
    (MonadIO m) =>
    HashTableIter                           -- _obj
    -> m ()                                 -- result
hashTableIterSteal _obj = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    g_hash_table_iter_steal _obj'
    touchManagedPtr _obj
    return ()

data HashTableIterStealMethodInfo
instance (signature ~ (m ()), MonadIO m) => MethodInfo HashTableIterStealMethodInfo HashTableIter signature where
    overloadedMethod _ = hashTableIterSteal

type family ResolveHashTableIterMethod (t :: Symbol) (o :: *) :: * where
    ResolveHashTableIterMethod "init" o = HashTableIterInitMethodInfo
    ResolveHashTableIterMethod "next" o = HashTableIterNextMethodInfo
    ResolveHashTableIterMethod "remove" o = HashTableIterRemoveMethodInfo
    ResolveHashTableIterMethod "replace" o = HashTableIterReplaceMethodInfo
    ResolveHashTableIterMethod "steal" o = HashTableIterStealMethodInfo
    ResolveHashTableIterMethod l o = MethodResolutionFailed l o

instance (info ~ ResolveHashTableIterMethod t HashTableIter, MethodInfo info HashTableIter p) => IsLabelProxy t (HashTableIter -> p) where
    fromLabelProxy _ = overloadedMethod (MethodProxy :: MethodProxy info)

#if MIN_VERSION_base(4,9,0)
instance (info ~ ResolveHashTableIterMethod t HashTableIter, MethodInfo info HashTableIter p) => IsLabel t (HashTableIter -> p) where
    fromLabel _ = overloadedMethod (MethodProxy :: MethodProxy info)
#endif