    {-# LANGUAGE GeneralizedNewtypeDeriving #-}
    module Bindings.HDF5.PropertyList.LAPL
        ( module Bindings.HDF5.PropertyList

        , LAPL
        , LinkAccessPropertyList

        , setNLinks
        , getNLinks

        , setELinkPrefix
        , getELinkPrefix

        , setELinkFAPL
        , getELinkFAPL

        , setELinkAccFlags
        , getELinkAccFlags
        ) where

    import Bindings.HDF5.Raw.H5P
    import Bindings.HDF5.Core
    import Bindings.HDF5.Error
    import Bindings.HDF5.PropertyList
    import Bindings.HDF5.PropertyList.FAPL

    import qualified Data.ByteString as BS
    import Foreign.Ptr.Conventions
    import Foreign.C.Types

    class PropertyList t => LinkAccessPropertyList t where
    newtype LAPL = LAPL PropertyListID
        deriving (LAPL -> LAPL -> Bool
    (LAPL -> LAPL -> Bool) -> (LAPL -> LAPL -> Bool) -> Eq LAPL
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: LAPL -> LAPL -> Bool
    == :: LAPL -> LAPL -> Bool
    $c/= :: LAPL -> LAPL -> Bool
    /= :: LAPL -> LAPL -> Bool
    Eq, LAPL -> HId_t
    (LAPL -> HId_t) -> HId LAPL
    forall t. (t -> HId_t) -> HId t
    $chid :: LAPL -> HId_t
    hid :: LAPL -> HId_t
    HId, HId_t -> LAPL
    (HId_t -> LAPL) -> FromHId LAPL
    forall t. (HId_t -> t) -> FromHId t
    $cuncheckedFromHId :: HId_t -> LAPL
    uncheckedFromHId :: HId_t -> LAPL
    FromHId, LAPL -> Bool
    (LAPL -> Bool) -> HDFResultType LAPL
    forall t. (t -> Bool) -> HDFResultType t
    $cisError :: LAPL -> Bool
    isError :: LAPL -> Bool
    HDFResultType, FromHId LAPL
    HId LAPL
    (HId LAPL, FromHId LAPL) => PropertyListOrClass LAPL
    forall t. (HId t, FromHId t) => PropertyListOrClass t
    PropertyListOrClass)
    instance PropertyList LAPL where
        staticPlistClass :: Tagged LAPL PropertyListClassID
    staticPlistClass = PropertyListClassID -> Tagged LAPL PropertyListClassID
    forall {k} (s :: k) b. b -> Tagged s b
    Tagged PropertyListClassID
    linkAccess
    instance LinkAccessPropertyList LAPL

    setNLinks :: LinkAccessPropertyList lapl => lapl -> CSize -> IO ()
    setNLinks :: forall lapl. LinkAccessPropertyList lapl => lapl -> CSize -> IO ()
    setNLinks lapl
    lapl CSize
    nLinks =
        IO HErr_t -> IO ()
    forall t. HDFResultType t => IO t -> IO ()
    withErrorCheck_ (IO HErr_t -> IO ()) -> IO HErr_t -> IO ()
    forall a b. (a -> b) -> a -> b
    $
            HId_t -> CSize -> IO HErr_t
    h5p_set_nlinks (lapl -> HId_t
    forall t. HId t => t -> HId_t
    hid lapl
    lapl) CSize
    nLinks

    getNLinks :: LinkAccessPropertyList lapl => lapl -> IO CSize
    getNLinks :: forall lapl. LinkAccessPropertyList lapl => lapl -> IO CSize
    getNLinks lapl
    lapl =
        (Out CSize -> IO ()) -> IO CSize
    forall a (m :: * -> *) b.
    (Storable a, MonadBaseControl IO m, MonadIO m) =>
    (Out a -> m b) -> m a
    withOut_ ((Out CSize -> IO ()) -> IO CSize)
    -> (Out CSize -> IO ()) -> IO CSize
    forall a b. (a -> b) -> a -> b
    $ \Out CSize
    nLinks ->
            IO HErr_t -> IO ()
    forall t. HDFResultType t => IO t -> IO ()
    withErrorCheck_ (IO HErr_t -> IO ()) -> IO HErr_t -> IO ()
    forall a b. (a -> b) -> a -> b
    $
                HId_t -> Out CSize -> IO HErr_t
    h5p_get_nlinks (lapl -> HId_t
    forall t. HId t => t -> HId_t
    hid lapl
    lapl) Out CSize
    nLinks

    setELinkPrefix :: LinkAccessPropertyList lapl => lapl -> BS.ByteString -> IO ()
    setELinkPrefix :: forall lapl.
    LinkAccessPropertyList lapl =>
    lapl -> ByteString -> IO ()
    setELinkPrefix lapl
    lapl ByteString
    prefix =
        IO HErr_t -> IO ()
    forall t. HDFResultType t => IO t -> IO ()
    withErrorCheck_ (IO HErr_t -> IO ()) -> IO HErr_t -> IO ()
    forall a b. (a -> b) -> a -> b
    $
            ByteString -> (CString -> IO HErr_t) -> IO HErr_t
    forall a. ByteString -> (CString -> IO a) -> IO a
    BS.useAsCString ByteString
    prefix ((CString -> IO HErr_t) -> IO HErr_t)
    -> (CString -> IO HErr_t) -> IO HErr_t
    forall a b. (a -> b) -> a -> b
    $ \CString
    cprefix ->
                HId_t -> CString -> IO HErr_t
    h5p_set_elink_prefix (lapl -> HId_t
    forall t. HId t => t -> HId_t
    hid lapl
    lapl) CString
    cprefix

    getELinkPrefix :: LinkAccessPropertyList lapl => lapl -> IO BS.ByteString
    getELinkPrefix :: forall lapl. LinkAccessPropertyList lapl => lapl -> IO ByteString
    getELinkPrefix lapl
    lapl =
        (OutArray CChar -> CSize -> IO CSSize) -> IO ByteString
    forall (m :: * -> *) a b.
    (MonadBaseControl IO m, MonadIO m, Integral a, Integral b) =>
    (OutArray CChar -> a -> m b) -> m ByteString
    withOutByteString ((OutArray CChar -> CSize -> IO CSSize) -> IO ByteString)
    -> (OutArray CChar -> CSize -> IO CSSize) -> IO ByteString
    forall a b. (a -> b) -> a -> b
    $ \OutArray CChar
    buf CSize
    bufSz ->
            (CSSize -> Bool) -> IO CSSize -> IO CSSize
    forall t. (t -> Bool) -> IO t -> IO t
    withErrorWhen (CSSize -> CSSize -> Bool
    forall a. Ord a => a -> a -> Bool
    < CSSize
    0) (IO CSSize -> IO CSSize) -> IO CSSize -> IO CSSize
    forall a b. (a -> b) -> a -> b
    $
                HId_t -> OutArray CChar -> CSize -> IO CSSize
    h5p_get_elink_prefix (lapl -> HId_t
    forall t. HId t => t -> HId_t
    hid lapl
    lapl) OutArray CChar
    buf CSize
    bufSz

    getELinkFAPL :: LinkAccessPropertyList lapl => lapl -> IO FAPL
    getELinkFAPL :: forall lapl. LinkAccessPropertyList lapl => lapl -> IO FAPL
    getELinkFAPL lapl
    lapl =
        (HId_t -> FAPL) -> IO HId_t -> IO FAPL
    forall a b. (a -> b) -> IO a -> IO b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap HId_t -> FAPL
    forall t. FromHId t => HId_t -> t
    uncheckedFromHId (IO HId_t -> IO FAPL) -> IO HId_t -> IO FAPL
    forall a b. (a -> b) -> a -> b
    $
            IO HId_t -> IO HId_t
    forall t. HDFResultType t => IO t -> IO t
    withErrorCheck (IO HId_t -> IO HId_t) -> IO HId_t -> IO HId_t
    forall a b. (a -> b) -> a -> b
    $
                HId_t -> IO HId_t
    h5p_get_elink_fapl (lapl -> HId_t
    forall t. HId t => t -> HId_t
    hid lapl
    lapl)

    setELinkFAPL :: LinkAccessPropertyList lapl => lapl -> FAPL -> IO ()
    setELinkFAPL :: forall lapl. LinkAccessPropertyList lapl => lapl -> FAPL -> IO ()
    setELinkFAPL lapl
    lapl FAPL
    fapl =
        IO HErr_t -> IO ()
    forall t. HDFResultType t => IO t -> IO ()
    withErrorCheck_ (IO HErr_t -> IO ()) -> IO HErr_t -> IO ()
    forall a b. (a -> b) -> a -> b
    $
            HId_t -> HId_t -> IO HErr_t
    h5p_set_elink_fapl (lapl -> HId_t
    forall t. HId t => t -> HId_t
    hid lapl
    lapl) (FAPL -> HId_t
    forall t. HId t => t -> HId_t
    hid FAPL
    fapl)

    -- TODO: an enumeration type for these flags
    setELinkAccFlags :: LinkAccessPropertyList lapl => lapl -> CUInt -> IO ()
    setELinkAccFlags :: forall lapl. LinkAccessPropertyList lapl => lapl -> CUInt -> IO ()
    setELinkAccFlags lapl
    lapl CUInt
    flags =
        IO HErr_t -> IO ()
    forall t. HDFResultType t => IO t -> IO ()
    withErrorCheck_ (IO HErr_t -> IO ()) -> IO HErr_t -> IO ()
    forall a b. (a -> b) -> a -> b
    $
            HId_t -> CUInt -> IO HErr_t
    h5p_set_elink_acc_flags (lapl -> HId_t
    forall t. HId t => t -> HId_t
    hid lapl
    lapl) CUInt
    flags

    getELinkAccFlags :: LinkAccessPropertyList lapl => lapl -> IO CUInt
    getELinkAccFlags :: forall lapl. LinkAccessPropertyList lapl => lapl -> IO CUInt
    getELinkAccFlags lapl
    lapl =
        (Out CUInt -> IO ()) -> IO CUInt
    forall a (m :: * -> *) b.
    (Storable a, MonadBaseControl IO m, MonadIO m) =>
    (Out a -> m b) -> m a
    withOut_ ((Out CUInt -> IO ()) -> IO CUInt)
    -> (Out CUInt -> IO ()) -> IO CUInt
    forall a b. (a -> b) -> a -> b
    $ \Out CUInt
    flags ->
            IO HErr_t -> IO ()
    forall t. HDFResultType t => IO t -> IO ()
    withErrorCheck_ (IO HErr_t -> IO ()) -> IO HErr_t -> IO ()
    forall a b. (a -> b) -> a -> b
    $
                HId_t -> Out CUInt -> IO HErr_t
    h5p_get_elink_acc_flags (lapl -> HId_t
    forall t. HId t => t -> HId_t
    hid lapl
    lapl) Out CUInt
    flags

    -- type ELinkTraverse = BS.ByteString -> BS.ByteString -> BS.ByteString -> BS.ByteString -> Ptr CUInt -> FAPL -> IO ()
    -- h5p_set_elink_cb :: HId_t -> H5L_elink_traverse_t a -> Ptr a -> IO HErr_t
    -- h5p_get_elink_cb :: HId_t -> Out (H5L_elink_traverse_t a) -> Out (Ptr a) -> IO HErr_t