{-# LANGUAGE TypeApplications #-}
#if (MIN_VERSION_haskell_gi_overloading(1,0,0) && !defined(__HADDOCK_VERSION__))
#define ENABLE_OVERLOADING
#endif
module GI.GLib.Structs.PtrArray
(
PtrArray(..) ,
newZeroPtrArray ,
#if defined(ENABLE_OVERLOADING)
ResolvePtrArrayMethod ,
#endif
getPtrArrayLen ,
#if defined(ENABLE_OVERLOADING)
ptrArray_len ,
#endif
setPtrArrayLen ,
clearPtrArrayPdata ,
getPtrArrayPdata ,
#if defined(ENABLE_OVERLOADING)
ptrArray_pdata ,
#endif
setPtrArrayPdata ,
) 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 PtrArray = PtrArray (SP.ManagedPtr PtrArray)
deriving (PtrArray -> PtrArray -> Bool
(PtrArray -> PtrArray -> Bool)
-> (PtrArray -> PtrArray -> Bool) -> Eq PtrArray
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PtrArray -> PtrArray -> Bool
$c/= :: PtrArray -> PtrArray -> Bool
== :: PtrArray -> PtrArray -> Bool
$c== :: PtrArray -> PtrArray -> Bool
Eq)
instance SP.ManagedPtrNewtype PtrArray where
toManagedPtr :: PtrArray -> ManagedPtr PtrArray
toManagedPtr (PtrArray ManagedPtr PtrArray
p) = ManagedPtr PtrArray
p
foreign import ccall "g_ptr_array_get_type" c_g_ptr_array_get_type ::
IO GType
type instance O.ParentTypes PtrArray = '[]
instance O.HasParentTypes PtrArray
instance B.Types.TypedObject PtrArray where
glibType :: IO GType
glibType = IO GType
c_g_ptr_array_get_type
instance B.Types.GBoxed PtrArray
instance B.GValue.IsGValue PtrArray where
toGValue :: PtrArray -> IO GValue
toGValue PtrArray
o = do
GType
gtype <- IO GType
c_g_ptr_array_get_type
PtrArray -> (Ptr PtrArray -> IO GValue) -> IO GValue
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
B.ManagedPtr.withManagedPtr PtrArray
o (GType
-> (GValue -> Ptr PtrArray -> IO ()) -> Ptr PtrArray -> IO GValue
forall a. GType -> (GValue -> a -> IO ()) -> a -> IO GValue
B.GValue.buildGValue GType
gtype GValue -> Ptr PtrArray -> IO ()
forall a. GValue -> Ptr a -> IO ()
B.GValue.set_boxed)
fromGValue :: GValue -> IO PtrArray
fromGValue GValue
gv = do
Ptr PtrArray
ptr <- GValue -> IO (Ptr PtrArray)
forall b. GValue -> IO (Ptr b)
B.GValue.get_boxed GValue
gv :: IO (Ptr PtrArray)
(ManagedPtr PtrArray -> PtrArray) -> Ptr PtrArray -> IO PtrArray
forall a.
(HasCallStack, GBoxed a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
B.ManagedPtr.newBoxed ManagedPtr PtrArray -> PtrArray
PtrArray Ptr PtrArray
ptr
newZeroPtrArray :: MonadIO m => m PtrArray
newZeroPtrArray :: m PtrArray
newZeroPtrArray = IO PtrArray -> m PtrArray
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO PtrArray -> m PtrArray) -> IO PtrArray -> m PtrArray
forall a b. (a -> b) -> a -> b
$ Int -> IO (Ptr PtrArray)
forall a. GBoxed a => Int -> IO (Ptr a)
callocBoxedBytes Int
16 IO (Ptr PtrArray) -> (Ptr PtrArray -> IO PtrArray) -> IO PtrArray
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (ManagedPtr PtrArray -> PtrArray) -> Ptr PtrArray -> IO PtrArray
forall a.
(HasCallStack, GBoxed a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
wrapBoxed ManagedPtr PtrArray -> PtrArray
PtrArray
instance tag ~ 'AttrSet => Constructible PtrArray tag where
new :: (ManagedPtr PtrArray -> PtrArray)
-> [AttrOp PtrArray tag] -> m PtrArray
new ManagedPtr PtrArray -> PtrArray
_ [AttrOp PtrArray tag]
attrs = do
PtrArray
o <- m PtrArray
forall (m :: * -> *). MonadIO m => m PtrArray
newZeroPtrArray
PtrArray -> [AttrOp PtrArray 'AttrSet] -> m ()
forall o (m :: * -> *).
MonadIO m =>
o -> [AttrOp o 'AttrSet] -> m ()
GI.Attributes.set PtrArray
o [AttrOp PtrArray tag]
[AttrOp PtrArray 'AttrSet]
attrs
PtrArray -> m PtrArray
forall (m :: * -> *) a. Monad m => a -> m a
return PtrArray
o
getPtrArrayPdata :: MonadIO m => PtrArray -> m (Ptr ())
getPtrArrayPdata :: PtrArray -> m (Ptr ())
getPtrArrayPdata PtrArray
s = IO (Ptr ()) -> m (Ptr ())
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Ptr ()) -> m (Ptr ())) -> IO (Ptr ()) -> m (Ptr ())
forall a b. (a -> b) -> a -> b
$ PtrArray -> (Ptr PtrArray -> IO (Ptr ())) -> IO (Ptr ())
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr PtrArray
s ((Ptr PtrArray -> IO (Ptr ())) -> IO (Ptr ()))
-> (Ptr PtrArray -> IO (Ptr ())) -> IO (Ptr ())
forall a b. (a -> b) -> a -> b
$ \Ptr PtrArray
ptr -> do
Ptr ()
val <- Ptr (Ptr ()) -> IO (Ptr ())
forall a. Storable a => Ptr a -> IO a
peek (Ptr PtrArray
ptr Ptr PtrArray -> Int -> Ptr (Ptr ())
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
0) :: IO (Ptr ())
Ptr () -> IO (Ptr ())
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr ()
val
setPtrArrayPdata :: MonadIO m => PtrArray -> Ptr () -> m ()
setPtrArrayPdata :: PtrArray -> Ptr () -> m ()
setPtrArrayPdata PtrArray
s Ptr ()
val = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ PtrArray -> (Ptr PtrArray -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr PtrArray
s ((Ptr PtrArray -> IO ()) -> IO ())
-> (Ptr PtrArray -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr PtrArray
ptr -> do
Ptr (Ptr ()) -> Ptr () -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (Ptr PtrArray
ptr Ptr PtrArray -> Int -> Ptr (Ptr ())
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
0) (Ptr ()
val :: Ptr ())
clearPtrArrayPdata :: MonadIO m => PtrArray -> m ()
clearPtrArrayPdata :: PtrArray -> m ()
clearPtrArrayPdata PtrArray
s = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ PtrArray -> (Ptr PtrArray -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr PtrArray
s ((Ptr PtrArray -> IO ()) -> IO ())
-> (Ptr PtrArray -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr PtrArray
ptr -> do
Ptr (Ptr ()) -> Ptr () -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (Ptr PtrArray
ptr Ptr PtrArray -> Int -> Ptr (Ptr ())
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
0) (Ptr ()
forall a. Ptr a
FP.nullPtr :: Ptr ())
#if defined(ENABLE_OVERLOADING)
data PtrArrayPdataFieldInfo
instance AttrInfo PtrArrayPdataFieldInfo where
type AttrBaseTypeConstraint PtrArrayPdataFieldInfo = (~) PtrArray
type AttrAllowedOps PtrArrayPdataFieldInfo = '[ 'AttrSet, 'AttrGet, 'AttrClear]
type AttrSetTypeConstraint PtrArrayPdataFieldInfo = (~) (Ptr ())
type AttrTransferTypeConstraint PtrArrayPdataFieldInfo = (~)(Ptr ())
type AttrTransferType PtrArrayPdataFieldInfo = (Ptr ())
type AttrGetType PtrArrayPdataFieldInfo = Ptr ()
type AttrLabel PtrArrayPdataFieldInfo = "pdata"
type AttrOrigin PtrArrayPdataFieldInfo = PtrArray
attrGet = getPtrArrayPdata
attrSet = setPtrArrayPdata
attrConstruct = undefined
attrClear = clearPtrArrayPdata
attrTransfer _ v = do
return v
ptrArray_pdata :: AttrLabelProxy "pdata"
ptrArray_pdata = AttrLabelProxy
#endif
getPtrArrayLen :: MonadIO m => PtrArray -> m Word32
getPtrArrayLen :: PtrArray -> m Word32
getPtrArrayLen PtrArray
s = IO Word32 -> m Word32
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Word32 -> m Word32) -> IO Word32 -> m Word32
forall a b. (a -> b) -> a -> b
$ PtrArray -> (Ptr PtrArray -> IO Word32) -> IO Word32
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr PtrArray
s ((Ptr PtrArray -> IO Word32) -> IO Word32)
-> (Ptr PtrArray -> IO Word32) -> IO Word32
forall a b. (a -> b) -> a -> b
$ \Ptr PtrArray
ptr -> do
Word32
val <- Ptr Word32 -> IO Word32
forall a. Storable a => Ptr a -> IO a
peek (Ptr PtrArray
ptr Ptr PtrArray -> Int -> Ptr Word32
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
8) :: IO Word32
Word32 -> IO Word32
forall (m :: * -> *) a. Monad m => a -> m a
return Word32
val
setPtrArrayLen :: MonadIO m => PtrArray -> Word32 -> m ()
setPtrArrayLen :: PtrArray -> Word32 -> m ()
setPtrArrayLen PtrArray
s Word32
val = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ PtrArray -> (Ptr PtrArray -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr PtrArray
s ((Ptr PtrArray -> IO ()) -> IO ())
-> (Ptr PtrArray -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr PtrArray
ptr -> do
Ptr Word32 -> Word32 -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (Ptr PtrArray
ptr Ptr PtrArray -> Int -> Ptr Word32
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
8) (Word32
val :: Word32)
#if defined(ENABLE_OVERLOADING)
data PtrArrayLenFieldInfo
instance AttrInfo PtrArrayLenFieldInfo where
type AttrBaseTypeConstraint PtrArrayLenFieldInfo = (~) PtrArray
type AttrAllowedOps PtrArrayLenFieldInfo = '[ 'AttrSet, 'AttrGet]
type AttrSetTypeConstraint PtrArrayLenFieldInfo = (~) Word32
type AttrTransferTypeConstraint PtrArrayLenFieldInfo = (~)Word32
type AttrTransferType PtrArrayLenFieldInfo = Word32
type AttrGetType PtrArrayLenFieldInfo = Word32
type AttrLabel PtrArrayLenFieldInfo = "len"
type AttrOrigin PtrArrayLenFieldInfo = PtrArray
attrGet = getPtrArrayLen
attrSet = setPtrArrayLen
attrConstruct = undefined
attrClear = undefined
attrTransfer _ v = do
return v
ptrArray_len :: AttrLabelProxy "len"
ptrArray_len = AttrLabelProxy
#endif
#if defined(ENABLE_OVERLOADING)
instance O.HasAttributeList PtrArray
type instance O.AttributeList PtrArray = PtrArrayAttributeList
type PtrArrayAttributeList = ('[ '("pdata", PtrArrayPdataFieldInfo), '("len", PtrArrayLenFieldInfo)] :: [(Symbol, *)])
#endif
#if defined(ENABLE_OVERLOADING)
type family ResolvePtrArrayMethod (t :: Symbol) (o :: *) :: * where
ResolvePtrArrayMethod l o = O.MethodResolutionFailed l o
instance (info ~ ResolvePtrArrayMethod t PtrArray, O.MethodInfo info PtrArray p) => OL.IsLabel t (PtrArray -> p) where
#if MIN_VERSION_base(4,10,0)
fromLabel = O.overloadedMethod @info
#else
fromLabel _ = O.overloadedMethod @info
#endif
#endif