{-# LANGUAGE TypeApplications #-}
#if (MIN_VERSION_haskell_gi_overloading(1,0,0) && !defined(__HADDOCK_VERSION__))
#define ENABLE_OVERLOADING
#endif
module GI.GLib.Structs.HashTableIter
(
HashTableIter(..) ,
newZeroHashTableIter ,
#if defined(ENABLE_OVERLOADING)
ResolveHashTableIterMethod ,
#endif
#if defined(ENABLE_OVERLOADING)
HashTableIterInitMethodInfo ,
#endif
hashTableIterInit ,
#if defined(ENABLE_OVERLOADING)
HashTableIterNextMethodInfo ,
#endif
hashTableIterNext ,
#if defined(ENABLE_OVERLOADING)
HashTableIterRemoveMethodInfo ,
#endif
hashTableIterRemove ,
#if defined(ENABLE_OVERLOADING)
HashTableIterReplaceMethodInfo ,
#endif
hashTableIterReplace ,
#if defined(ENABLE_OVERLOADING)
HashTableIterStealMethodInfo ,
#endif
hashTableIterSteal ,
) 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.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 Control.Monad.IO.Class as MIO
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
newtype HashTableIter = HashTableIter (SP.ManagedPtr HashTableIter)
deriving (HashTableIter -> HashTableIter -> Bool
(HashTableIter -> HashTableIter -> Bool)
-> (HashTableIter -> HashTableIter -> Bool) -> Eq HashTableIter
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: HashTableIter -> HashTableIter -> Bool
$c/= :: HashTableIter -> HashTableIter -> Bool
== :: HashTableIter -> HashTableIter -> Bool
$c== :: HashTableIter -> HashTableIter -> Bool
Eq)
instance SP.ManagedPtrNewtype HashTableIter where
toManagedPtr :: HashTableIter -> ManagedPtr HashTableIter
toManagedPtr (HashTableIter ManagedPtr HashTableIter
p) = ManagedPtr HashTableIter
p
instance BoxedPtr HashTableIter where
boxedPtrCopy :: HashTableIter -> IO HashTableIter
boxedPtrCopy = \HashTableIter
p -> HashTableIter
-> (Ptr HashTableIter -> IO HashTableIter) -> IO HashTableIter
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
B.ManagedPtr.withManagedPtr HashTableIter
p (Int -> Ptr HashTableIter -> IO (Ptr HashTableIter)
forall a. (HasCallStack, CallocPtr a) => Int -> Ptr a -> IO (Ptr a)
copyBytes Int
40 (Ptr HashTableIter -> IO (Ptr HashTableIter))
-> (Ptr HashTableIter -> IO HashTableIter)
-> Ptr HashTableIter
-> IO HashTableIter
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> (ManagedPtr HashTableIter -> HashTableIter)
-> Ptr HashTableIter -> IO HashTableIter
forall a.
(HasCallStack, BoxedPtr a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
B.ManagedPtr.wrapPtr ManagedPtr HashTableIter -> HashTableIter
HashTableIter)
boxedPtrFree :: HashTableIter -> IO ()
boxedPtrFree = \HashTableIter
x -> HashTableIter -> (Ptr HashTableIter -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
SP.withManagedPtr HashTableIter
x Ptr HashTableIter -> IO ()
forall a. Ptr a -> IO ()
SP.freeMem
instance CallocPtr HashTableIter where
boxedPtrCalloc :: IO (Ptr HashTableIter)
boxedPtrCalloc = Int -> IO (Ptr HashTableIter)
forall a. Int -> IO (Ptr a)
callocBytes Int
40
newZeroHashTableIter :: MonadIO m => m HashTableIter
newZeroHashTableIter :: m HashTableIter
newZeroHashTableIter = IO HashTableIter -> m HashTableIter
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO HashTableIter -> m HashTableIter)
-> IO HashTableIter -> m HashTableIter
forall a b. (a -> b) -> a -> b
$ IO (Ptr HashTableIter)
forall a. CallocPtr a => IO (Ptr a)
boxedPtrCalloc IO (Ptr HashTableIter)
-> (Ptr HashTableIter -> IO HashTableIter) -> IO HashTableIter
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (ManagedPtr HashTableIter -> HashTableIter)
-> Ptr HashTableIter -> IO HashTableIter
forall a.
(HasCallStack, BoxedPtr a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
wrapPtr ManagedPtr HashTableIter -> HashTableIter
HashTableIter
instance tag ~ 'AttrSet => Constructible HashTableIter tag where
new :: (ManagedPtr HashTableIter -> HashTableIter)
-> [AttrOp HashTableIter tag] -> m HashTableIter
new ManagedPtr HashTableIter -> HashTableIter
_ [AttrOp HashTableIter tag]
attrs = do
HashTableIter
o <- m HashTableIter
forall (m :: * -> *). MonadIO m => m HashTableIter
newZeroHashTableIter
HashTableIter -> [AttrOp HashTableIter 'AttrSet] -> m ()
forall o (m :: * -> *).
MonadIO m =>
o -> [AttrOp o 'AttrSet] -> m ()
GI.Attributes.set HashTableIter
o [AttrOp HashTableIter tag]
[AttrOp HashTableIter 'AttrSet]
attrs
HashTableIter -> m HashTableIter
forall (m :: * -> *) a. Monad m => a -> m a
return HashTableIter
o
#if defined(ENABLE_OVERLOADING)
instance O.HasAttributeList HashTableIter
type instance O.AttributeList HashTableIter = HashTableIterAttributeList
type HashTableIterAttributeList = ('[ ] :: [(Symbol, *)])
#endif
foreign import ccall "g_hash_table_iter_init" g_hash_table_iter_init ::
Ptr HashTableIter ->
Ptr (GHashTable (Ptr ()) (Ptr ())) ->
IO ()
hashTableIterInit ::
(B.CallStack.HasCallStack, MonadIO m) =>
HashTableIter
-> Map.Map (Ptr ()) (Ptr ())
-> m ()
hashTableIterInit :: HashTableIter -> Map (Ptr ()) (Ptr ()) -> m ()
hashTableIterInit HashTableIter
iter Map (Ptr ()) (Ptr ())
hashTable = 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 HashTableIter
iter' <- HashTableIter -> IO (Ptr HashTableIter)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr HashTableIter
iter
let hashTable' :: [(Ptr (), Ptr ())]
hashTable' = Map (Ptr ()) (Ptr ()) -> [(Ptr (), Ptr ())]
forall k a. Map k a -> [(k, a)]
Map.toList Map (Ptr ()) (Ptr ())
hashTable
let hashTable'' :: [(PtrWrapped (Ptr ()), Ptr ())]
hashTable'' = (Ptr () -> PtrWrapped (Ptr ()))
-> [(Ptr (), Ptr ())] -> [(PtrWrapped (Ptr ()), Ptr ())]
forall a c b. (a -> c) -> [(a, b)] -> [(c, b)]
mapFirst Ptr () -> PtrWrapped (Ptr ())
forall a. Ptr a -> PtrWrapped (Ptr a)
ptrPackPtr [(Ptr (), Ptr ())]
hashTable'
let hashTable''' :: [(PtrWrapped (Ptr ()), PtrWrapped (Ptr ()))]
hashTable''' = (Ptr () -> PtrWrapped (Ptr ()))
-> [(PtrWrapped (Ptr ()), Ptr ())]
-> [(PtrWrapped (Ptr ()), PtrWrapped (Ptr ()))]
forall b c a. (b -> c) -> [(a, b)] -> [(a, c)]
mapSecond Ptr () -> PtrWrapped (Ptr ())
forall a. Ptr a -> PtrWrapped (Ptr a)
ptrPackPtr [(PtrWrapped (Ptr ()), Ptr ())]
hashTable''
Ptr (GHashTable (Ptr ()) (Ptr ()))
hashTable'''' <- GHashFunc (Ptr ())
-> GEqualFunc (Ptr ())
-> Maybe (GDestroyNotify (Ptr ()))
-> Maybe (GDestroyNotify (Ptr ()))
-> [(PtrWrapped (Ptr ()), PtrWrapped (Ptr ()))]
-> IO (Ptr (GHashTable (Ptr ()) (Ptr ())))
forall a b.
GHashFunc a
-> GEqualFunc a
-> Maybe (GDestroyNotify a)
-> Maybe (GDestroyNotify b)
-> [(PtrWrapped a, PtrWrapped b)]
-> IO (Ptr (GHashTable a b))
packGHashTable GHashFunc (Ptr ())
forall a. GHashFunc (Ptr a)
gDirectHash GEqualFunc (Ptr ())
forall a. GEqualFunc (Ptr a)
gDirectEqual Maybe (GDestroyNotify (Ptr ()))
forall a. Maybe a
Nothing Maybe (GDestroyNotify (Ptr ()))
forall a. Maybe a
Nothing [(PtrWrapped (Ptr ()), PtrWrapped (Ptr ()))]
hashTable'''
Ptr HashTableIter -> Ptr (GHashTable (Ptr ()) (Ptr ())) -> IO ()
g_hash_table_iter_init Ptr HashTableIter
iter' Ptr (GHashTable (Ptr ()) (Ptr ()))
hashTable''''
HashTableIter -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr HashTableIter
iter
Ptr (GHashTable (Ptr ()) (Ptr ())) -> IO ()
forall a b. Ptr (GHashTable a b) -> IO ()
unrefGHashTable Ptr (GHashTable (Ptr ()) (Ptr ()))
hashTable''''
() -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
#if defined(ENABLE_OVERLOADING)
data HashTableIterInitMethodInfo
instance (signature ~ (Map.Map (Ptr ()) (Ptr ()) -> m ()), MonadIO m) => O.MethodInfo HashTableIterInitMethodInfo HashTableIter signature where
overloadedMethod = hashTableIterInit
#endif
foreign import ccall "g_hash_table_iter_next" g_hash_table_iter_next ::
Ptr HashTableIter ->
Ptr (Ptr ()) ->
Ptr (Ptr ()) ->
IO CInt
hashTableIterNext ::
(B.CallStack.HasCallStack, MonadIO m) =>
HashTableIter
-> m ((Bool, Ptr (), Ptr ()))
hashTableIterNext :: HashTableIter -> m (Bool, Ptr (), Ptr ())
hashTableIterNext HashTableIter
iter = IO (Bool, Ptr (), Ptr ()) -> m (Bool, Ptr (), Ptr ())
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Bool, Ptr (), Ptr ()) -> m (Bool, Ptr (), Ptr ()))
-> IO (Bool, Ptr (), Ptr ()) -> m (Bool, Ptr (), Ptr ())
forall a b. (a -> b) -> a -> b
$ do
Ptr HashTableIter
iter' <- HashTableIter -> IO (Ptr HashTableIter)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr HashTableIter
iter
Ptr (Ptr ())
key <- IO (Ptr (Ptr ()))
forall a. Storable a => IO (Ptr a)
callocMem :: IO (Ptr (Ptr ()))
Ptr (Ptr ())
value <- IO (Ptr (Ptr ()))
forall a. Storable a => IO (Ptr a)
callocMem :: IO (Ptr (Ptr ()))
CInt
result <- Ptr HashTableIter -> Ptr (Ptr ()) -> Ptr (Ptr ()) -> IO CInt
g_hash_table_iter_next Ptr HashTableIter
iter' Ptr (Ptr ())
key Ptr (Ptr ())
value
let result' :: Bool
result' = (CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
/= CInt
0) CInt
result
Ptr ()
key' <- Ptr (Ptr ()) -> IO (Ptr ())
forall a. Storable a => Ptr a -> IO a
peek Ptr (Ptr ())
key
Ptr ()
value' <- Ptr (Ptr ()) -> IO (Ptr ())
forall a. Storable a => Ptr a -> IO a
peek Ptr (Ptr ())
value
HashTableIter -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr HashTableIter
iter
Ptr (Ptr ()) -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr (Ptr ())
key
Ptr (Ptr ()) -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr (Ptr ())
value
(Bool, Ptr (), Ptr ()) -> IO (Bool, Ptr (), Ptr ())
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool
result', Ptr ()
key', Ptr ()
value')
#if defined(ENABLE_OVERLOADING)
data HashTableIterNextMethodInfo
instance (signature ~ (m ((Bool, Ptr (), Ptr ()))), MonadIO m) => O.MethodInfo HashTableIterNextMethodInfo HashTableIter signature where
overloadedMethod = hashTableIterNext
#endif
foreign import ccall "g_hash_table_iter_remove" g_hash_table_iter_remove ::
Ptr HashTableIter ->
IO ()
hashTableIterRemove ::
(B.CallStack.HasCallStack, MonadIO m) =>
HashTableIter
-> m ()
hashTableIterRemove :: HashTableIter -> m ()
hashTableIterRemove HashTableIter
iter = 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 HashTableIter
iter' <- HashTableIter -> IO (Ptr HashTableIter)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr HashTableIter
iter
Ptr HashTableIter -> IO ()
g_hash_table_iter_remove Ptr HashTableIter
iter'
HashTableIter -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr HashTableIter
iter
() -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
#if defined(ENABLE_OVERLOADING)
data HashTableIterRemoveMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.MethodInfo HashTableIterRemoveMethodInfo HashTableIter signature where
overloadedMethod = hashTableIterRemove
#endif
foreign import ccall "g_hash_table_iter_replace" g_hash_table_iter_replace ::
Ptr HashTableIter ->
Ptr () ->
IO ()
hashTableIterReplace ::
(B.CallStack.HasCallStack, MonadIO m) =>
HashTableIter
-> Ptr ()
-> m ()
hashTableIterReplace :: HashTableIter -> Ptr () -> m ()
hashTableIterReplace HashTableIter
iter Ptr ()
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 HashTableIter
iter' <- HashTableIter -> IO (Ptr HashTableIter)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr HashTableIter
iter
Ptr HashTableIter -> Ptr () -> IO ()
g_hash_table_iter_replace Ptr HashTableIter
iter' Ptr ()
value
HashTableIter -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr HashTableIter
iter
() -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
#if defined(ENABLE_OVERLOADING)
data HashTableIterReplaceMethodInfo
instance (signature ~ (Ptr () -> m ()), MonadIO m) => O.MethodInfo HashTableIterReplaceMethodInfo HashTableIter signature where
overloadedMethod = hashTableIterReplace
#endif
foreign import ccall "g_hash_table_iter_steal" g_hash_table_iter_steal ::
Ptr HashTableIter ->
IO ()
hashTableIterSteal ::
(B.CallStack.HasCallStack, MonadIO m) =>
HashTableIter
-> m ()
hashTableIterSteal :: HashTableIter -> m ()
hashTableIterSteal HashTableIter
iter = 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 HashTableIter
iter' <- HashTableIter -> IO (Ptr HashTableIter)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr HashTableIter
iter
Ptr HashTableIter -> IO ()
g_hash_table_iter_steal Ptr HashTableIter
iter'
HashTableIter -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr HashTableIter
iter
() -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
#if defined(ENABLE_OVERLOADING)
data HashTableIterStealMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.MethodInfo HashTableIterStealMethodInfo HashTableIter signature where
overloadedMethod = hashTableIterSteal
#endif
#if defined(ENABLE_OVERLOADING)
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 = O.MethodResolutionFailed l o
instance (info ~ ResolveHashTableIterMethod t HashTableIter, O.MethodInfo info HashTableIter p) => OL.IsLabel t (HashTableIter -> p) where
#if MIN_VERSION_base(4,10,0)
fromLabel = O.overloadedMethod @info
#else
fromLabel _ = O.overloadedMethod @info
#endif
#endif