module Data.ABC.Internal.VecInt (
Vec_Int_t_
, Vec_Int_t
, clearVecInt
, vecIntSize , setVecIntSize
, vecIntCap , setVecIntCap
, vecIntArray, setVecIntArray
, vecIntEntry
, vecIntWriteEntry
, withVecInt
) where
import Control.Exception (bracket)
import Foreign.C
import Foreign
import Data.ABC.Internal.Field
data Vec_Int_t_
type Vec_Int_t = Ptr (Vec_Int_t_)
vecIntSizeField :: Field Vec_Int_t CInt
vecIntSizeField = fieldFromOffset (4)
vecIntSize :: Vec_Int_t -> IO CInt
vecIntSize = readAt vecIntSizeField
setVecIntSize :: Vec_Int_t -> CInt -> IO ()
setVecIntSize = (\ptr val -> do {pokeByteOff ptr 4 (val::CInt)})
vecIntCap :: Vec_Int_t -> IO CInt
vecIntCap = (\ptr -> do {peekByteOff ptr 0 ::IO CInt})
setVecIntCap :: Vec_Int_t -> CInt -> IO ()
setVecIntCap = (\ptr val -> do {pokeByteOff ptr 0 (val::CInt)})
clearVecInt :: Vec_Int_t -> IO ()
clearVecInt v = writeAt vecIntSizeField v 0
vecIntArray :: Vec_Int_t -> IO (Ptr CInt)
vecIntArray = (\ptr -> do {peekByteOff ptr 8 ::IO (Ptr CInt)})
setVecIntArray :: Vec_Int_t -> Ptr CInt -> IO ()
setVecIntArray = (\ptr val -> do {pokeByteOff ptr 8 (val::(Ptr CInt))})
vecIntEntry :: Vec_Int_t -> CInt -> IO CInt
vecIntEntry v i = do
a <- vecIntArray v
peekElemOff a (fromIntegral i)
vecIntWriteEntry :: Vec_Int_t -> CInt -> CInt -> IO ()
vecIntWriteEntry v i u = do
a <- vecIntArray v
pokeElemOff a (fromIntegral i) u
withVecInt :: CInt -> Ptr CInt -> (Vec_Int_t -> IO a) -> IO a
withVecInt sz p act = do
bracket (mallocBytes 16) free $ \v -> do
setVecIntSize v sz
setVecIntCap v sz
setVecIntArray v p
act v