    {-# LANGUAGE TypeApplications #-}

    -- | Copyright  : Will Thompson and Iñaki García Etxebarria
    -- License    : LGPL-2.1
    -- Maintainer : Iñaki García Etxebarria
    --
    -- Contains the public fields of a @GPtrArray@.

    #if !defined(__HADDOCK_VERSION__)
    #define ENABLE_OVERLOADING
    #endif

    module GI.GLib.Structs.PtrArray
        (

    -- * Exported types
        PtrArray(..)                            ,
        newZeroPtrArray                         ,

     -- * Methods

    #if defined(ENABLE_OVERLOADING)
        ResolvePtrArrayMethod                   ,
    #endif

     -- * Properties

    -- ** len #attr:len#
    -- | the number of pointers in the array

        getPtrArrayLen                          ,
    #if defined(ENABLE_OVERLOADING)
        ptrArray_len                            ,
    #endif
        setPtrArrayLen                          ,

    -- ** pdata #attr:pdata#
    -- | a pointer to the array of pointers, which may be moved when the
    --     array grows

        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.GArray as B.GArray
    import qualified Data.GI.Base.GClosure as B.GClosure
    import qualified Data.GI.Base.GError as B.GError
    import qualified Data.GI.Base.GHashTable as B.GHT
    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.Coerce as Coerce
    import qualified Data.Text as T
    import qualified Data.Kind as DK
    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
    import qualified GHC.Records as R
    import qualified Data.Word as DW
    import qualified Data.Int as DI
    import qualified System.Posix.Types as SPT
    import qualified Foreign.C.Types as FCT

    -- Workaround for https://gitlab.haskell.org/ghc/ghc/-/issues/23392
    #if MIN_VERSION_base(4,18,0)

    #else

    #endif

    -- | Memory-managed wrapper type.
    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
    $c== :: PtrArray -> PtrArray -> Bool
    == :: PtrArray -> PtrArray -> Bool
    $c/= :: PtrArray -> PtrArray -> Bool
    /= :: 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

    -- | Convert t'PtrArray' to and from 'Data.GI.Base.GValue.GValue'. See 'Data.GI.Base.GValue.toGValue' and 'Data.GI.Base.GValue.fromGValue'.
    instance B.GValue.IsGValue (Maybe PtrArray) where
        gvalueGType_ :: IO GType
    gvalueGType_ = IO GType
    c_g_ptr_array_get_type
        gvalueSet_ :: Ptr GValue -> Maybe PtrArray -> IO ()
    gvalueSet_ Ptr GValue
    gv Maybe PtrArray
    P.Nothing = Ptr GValue -> Ptr PtrArray -> IO ()
    forall a. Ptr GValue -> Ptr a -> IO ()
    B.GValue.set_boxed Ptr GValue
    gv (Ptr PtrArray
    forall a. Ptr a
    FP.nullPtr :: FP.Ptr PtrArray)
        gvalueSet_ Ptr GValue
    gv (P.Just PtrArray
    obj) = PtrArray -> (Ptr PtrArray -> IO ()) -> IO ()
    forall a c.
    (HasCallStack, ManagedPtrNewtype a) =>
    a -> (Ptr a -> IO c) -> IO c
    B.ManagedPtr.withManagedPtr PtrArray
    obj (Ptr GValue -> Ptr PtrArray -> IO ()
    forall a. Ptr GValue -> Ptr a -> IO ()
    B.GValue.set_boxed Ptr GValue
    gv)
        gvalueGet_ :: Ptr GValue -> IO (Maybe PtrArray)
    gvalueGet_ Ptr GValue
    gv = do
            ptr <- Ptr GValue -> IO (Ptr PtrArray)
    forall b. Ptr GValue -> IO (Ptr b)
    B.GValue.get_boxed Ptr GValue
    gv :: IO (Ptr PtrArray)
            if ptr /= FP.nullPtr
            then P.Just <$> B.ManagedPtr.newBoxed PtrArray ptr
            else return P.Nothing

    -- | Construct a t'PtrArray' struct initialized to zero.
    newZeroPtrArray :: MonadIO m => m PtrArray
    newZeroPtrArray :: forall (m :: * -> *). MonadIO m => m PtrArray
    newZeroPtrArray = IO PtrArray -> m PtrArray
    forall a. IO a -> m a
    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 a b. IO a -> (a -> IO b) -> IO b
    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 :: forall (m :: * -> *).
    MonadIO m =>
    (ManagedPtr PtrArray -> PtrArray)
    -> [AttrOp PtrArray tag] -> m PtrArray
    new ManagedPtr PtrArray -> PtrArray
    _ [AttrOp PtrArray tag]
    attrs = do
            o <- m PtrArray
    forall (m :: * -> *). MonadIO m => m PtrArray
    newZeroPtrArray
            GI.Attributes.set o attrs
            return o

    -- | Get the value of the “@pdata@” field.
    -- When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to
    --
    -- @
    -- 'Data.GI.Base.Attributes.get' ptrArray #pdata
    -- @
    getPtrArrayPdata :: MonadIO m => PtrArray -> m (Ptr ())
    getPtrArrayPdata :: forall (m :: * -> *). MonadIO m => PtrArray -> m (Ptr ())
    getPtrArrayPdata PtrArray
    s = IO (Ptr ()) -> m (Ptr ())
    forall a. IO a -> m a
    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
        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 ())
        return val

    -- | Set the value of the “@pdata@” field.
    -- When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to
    --
    -- @
    -- 'Data.GI.Base.Attributes.set' ptrArray [ #pdata 'Data.GI.Base.Attributes.:=' value ]
    -- @
    setPtrArrayPdata :: MonadIO m => PtrArray -> Ptr () -> m ()
    setPtrArrayPdata :: forall (m :: * -> *). MonadIO m => PtrArray -> Ptr () -> m ()
    setPtrArrayPdata PtrArray
    s Ptr ()
    val = IO () -> m ()
    forall a. IO a -> m a
    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 ())

    -- | Set the value of the “@pdata@” field to `Nothing`.
    -- When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to
    --
    -- @
    -- 'Data.GI.Base.Attributes.clear' #pdata
    -- @
    clearPtrArrayPdata :: MonadIO m => PtrArray -> m ()
    clearPtrArrayPdata :: forall (m :: * -> *). MonadIO m => PtrArray -> m ()
    clearPtrArrayPdata PtrArray
    s = IO () -> m ()
    forall a. IO a -> m a
    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
        dbgAttrInfo = P.Just (O.ResolvedSymbolInfo {
            O.resolvedSymbolName = "GI.GLib.Structs.PtrArray.pdata"
            , O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-glib-2.0.30/docs/GI-GLib-Structs-PtrArray.html#g:attr:pdata"
            })

    ptrArray_pdata :: AttrLabelProxy "pdata"
    ptrArray_pdata = AttrLabelProxy

    #endif

    -- | Get the value of the “@len@” field.
    -- When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to
    --
    -- @
    -- 'Data.GI.Base.Attributes.get' ptrArray #len
    -- @
    getPtrArrayLen :: MonadIO m => PtrArray -> m Word32
    getPtrArrayLen :: forall (m :: * -> *). MonadIO m => PtrArray -> m Word32
    getPtrArrayLen PtrArray
    s = IO Word32 -> m Word32
    forall a. IO a -> m a
    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
        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
        return val

    -- | Set the value of the “@len@” field.
    -- When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to
    --
    -- @
    -- 'Data.GI.Base.Attributes.set' ptrArray [ #len 'Data.GI.Base.Attributes.:=' value ]
    -- @
    setPtrArrayLen :: MonadIO m => PtrArray -> Word32 -> m ()
    setPtrArrayLen :: forall (m :: * -> *). MonadIO m => PtrArray -> Word32 -> m ()
    setPtrArrayLen PtrArray
    s Word32
    val = IO () -> m ()
    forall a. IO a -> m a
    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
        dbgAttrInfo = P.Just (O.ResolvedSymbolInfo {
            O.resolvedSymbolName = "GI.GLib.Structs.PtrArray.len"
            , O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-glib-2.0.30/docs/GI-GLib-Structs-PtrArray.html#g:attr:len"
            })

    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, DK.Type)])
    #endif

    #if defined(ENABLE_OVERLOADING)
    type family ResolvePtrArrayMethod (t :: Symbol) (o :: DK.Type) :: DK.Type where
        ResolvePtrArrayMethod l o = O.MethodResolutionFailed l o

    instance (info ~ ResolvePtrArrayMethod t PtrArray, O.OverloadedMethod 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

    #if MIN_VERSION_base(4,13,0)
    instance (info ~ ResolvePtrArrayMethod t PtrArray, O.OverloadedMethod info PtrArray p, R.HasField t PtrArray p) => R.HasField t PtrArray p where
        getField = O.overloadedMethod @info

    #endif

    instance (info ~ ResolvePtrArrayMethod t PtrArray, O.OverloadedMethodInfo info PtrArray) => OL.IsLabel t (O.MethodProxy info PtrArray) where
    #if MIN_VERSION_base(4,10,0)
        fromLabel = O.MethodProxy
    #else
        fromLabel _ = O.MethodProxy
    #endif

    #endif