{- | 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(..) , noHashTableIter , -- * Methods -- ** hashTableIterInit hashTableIterInit , -- ** hashTableIterNext hashTableIterNext , -- ** hashTableIterRemove hashTableIterRemove , -- ** hashTableIterReplace hashTableIterReplace , -- ** hashTableIterSteal 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) noHashTableIter :: Maybe HashTableIter noHashTableIter = Nothing -- method HashTableIter::init -- method type : OrdinaryMethod -- Args : [Arg {argName = "_obj", argType = TInterface "GLib" "HashTableIter", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "hash_table", argType = TGHash (TBasicType TVoid) (TBasicType TVoid), direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}] -- Lengths : [] -- hInArgs : [Arg {argName = "_obj", argType = TInterface "GLib" "HashTableIter", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "hash_table", argType = TGHash (TBasicType TVoid) (TBasicType TVoid), direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}] -- 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 ()) -> -- hash_table m () hashTableIterInit _obj hash_table = liftIO $ do let _obj' = unsafeManagedPtrGetPtr _obj let hash_table' = Map.toList hash_table let hash_table'' = mapFirst ptrPackPtr hash_table' let hash_table''' = mapSecond ptrPackPtr hash_table'' hash_table'''' <- packGHashTable gDirectHash gDirectEqual Nothing Nothing hash_table''' g_hash_table_iter_init _obj' hash_table'''' touchManagedPtr _obj unrefGHashTable hash_table'''' return () -- method HashTableIter::next -- method type : OrdinaryMethod -- Args : [Arg {argName = "_obj", argType = TInterface "GLib" "HashTableIter", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "key", argType = TBasicType TVoid, direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "value", argType = TBasicType TVoid, direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}] -- Lengths : [] -- hInArgs : [Arg {argName = "_obj", argType = TInterface "GLib" "HashTableIter", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "key", argType = TBasicType TVoid, direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "value", argType = TBasicType TVoid, direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}] -- 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 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' -- method HashTableIter::remove -- method type : OrdinaryMethod -- Args : [Arg {argName = "_obj", argType = TInterface "GLib" "HashTableIter", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}] -- Lengths : [] -- hInArgs : [Arg {argName = "_obj", argType = TInterface "GLib" "HashTableIter", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}] -- 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 () hashTableIterRemove _obj = liftIO $ do let _obj' = unsafeManagedPtrGetPtr _obj g_hash_table_iter_remove _obj' touchManagedPtr _obj return () -- method HashTableIter::replace -- method type : OrdinaryMethod -- Args : [Arg {argName = "_obj", argType = TInterface "GLib" "HashTableIter", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "value", argType = TBasicType TVoid, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}] -- Lengths : [] -- hInArgs : [Arg {argName = "_obj", argType = TInterface "GLib" "HashTableIter", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "value", argType = TBasicType TVoid, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}] -- 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 () hashTableIterReplace _obj value = liftIO $ do let _obj' = unsafeManagedPtrGetPtr _obj g_hash_table_iter_replace _obj' value touchManagedPtr _obj return () -- method HashTableIter::steal -- method type : OrdinaryMethod -- Args : [Arg {argName = "_obj", argType = TInterface "GLib" "HashTableIter", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}] -- Lengths : [] -- hInArgs : [Arg {argName = "_obj", argType = TInterface "GLib" "HashTableIter", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}] -- 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 () hashTableIterSteal _obj = liftIO $ do let _obj' = unsafeManagedPtrGetPtr _obj g_hash_table_iter_steal _obj' touchManagedPtr _obj return ()