-- GENERATED by C->Haskell Compiler, version 0.20.1 The shapeless maps, 31 Oct 2014 (Haskell)
-- Edit the ORIGNAL .chs file instead!


{-# LINE 1 "src/Data/ABC/Internal/VecPtr.chs" #-}
{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE EmptyDataDecls #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

{- |
Module      : Data.ABC.Internal.VecPtr
Copyright   : Galois, Inc. 2010
License     : BSD3
Maintainer  : jhendrix@galois.com
Stability   : experimental
Portability : non-portable (c2hs, language extensions)

/Incomplete./ Binding of @misc\/vec\/vecPtr.h@ for manipulating
vectors of pointers.

-}

module Data.ABC.Internal.VecPtr (
      Vec_Ptr_t_
    , Vec_Ptr_t
    , clearVec
    , vecPtrSize
    , vecPtrArray
    , vecPtrEntry
    , clearVecPtr
    ) where





import Control.Exception (assert)
import Foreign
import Foreign.C

import Data.ABC.Internal.Field

data Vec_Ptr_t_

type Vec_Ptr_t = Ptr (Vec_Ptr_t_)
{-# LINE 40 "src/Data/ABC/Internal/VecPtr.chs" #-}


vecSizeField :: Field Vec_Ptr_t CInt
vecSizeField = fieldFromOffset (4)
{-# LINE 43 "src/Data/ABC/Internal/VecPtr.chs" #-}


clearVec :: Vec_Ptr_t -> IO ()
clearVec v = writeAt vecSizeField v 0

vecPtrSize :: Vec_Ptr_t -> IO Int
vecPtrSize v = fromIntegral `fmap` readAt vecSizeField v

vecPtrArray :: Vec_Ptr_t -> IO (Ptr (Ptr a))
vecPtrArray v = castPtr `fmap` (\ptr -> do {peekByteOff ptr 8 ::IO (Ptr (Ptr ()))}) v

clearVecPtr :: Vec_Ptr_t -> IO ()
clearVecPtr v = writeAt vecSizeField v 0

vecPtrEntry :: Vec_Ptr_t -> Int -> IO (Ptr a)
vecPtrEntry v i = do
  assert (i >= 0) $ return ()
  do sz <- vecPtrSize v
     assert (i < sz) $ return ()
  a <- vecPtrArray v
  peekElemOff a i