module Data.ABC.Internal.VecInt (
Vec_Int_t_
, Vec_Int_t
, clearVecInt
, vecIntSize , setVecIntSize
, vecIntCap , setVecIntCap
, vecIntArray, setVecIntArray
, vecIntEntry
, vecIntWriteEntry
, withVecInt
) where
import qualified Foreign.C.Types as C2HSImp
import qualified Foreign.Ptr as C2HSImp
import qualified Foreign.Storable as C2HSImp
import Control.Exception (bracket)
import Foreign.C
import Foreign
import Data.ABC.Internal.Field
data Vec_Int_t_
type Vec_Int_t = C2HSImp.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 {C2HSImp.pokeByteOff ptr 4 (val :: C2HSImp.CInt)})
vecIntCap :: Vec_Int_t -> IO CInt
vecIntCap = (\ptr -> do {C2HSImp.peekByteOff ptr 0 :: IO C2HSImp.CInt})
setVecIntCap :: Vec_Int_t -> CInt -> IO ()
setVecIntCap = (\ptr val -> do {C2HSImp.pokeByteOff ptr 0 (val :: C2HSImp.CInt)})
clearVecInt :: Vec_Int_t -> IO ()
clearVecInt v = writeAt vecIntSizeField v 0
vecIntArray :: Vec_Int_t -> IO (Ptr CInt)
vecIntArray = (\ptr -> do {C2HSImp.peekByteOff ptr 8 :: IO (C2HSImp.Ptr C2HSImp.CInt)})
setVecIntArray :: Vec_Int_t -> Ptr CInt -> IO ()
setVecIntArray = (\ptr val -> do {C2HSImp.pokeByteOff ptr 8 (val :: (C2HSImp.Ptr C2HSImp.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