module SFML.System.InputStream
(
InputStreamReadFunc
, InputStreamSeekFunc
, InputStreamTellFunc
, InputStreamGetSizeFunc
, InputStream(..)
)
where
import Control.Applicative ((<$>), (<*>))
import Data.Word (Word64)
import Foreign.C.Types (CInt)
import Foreign.Ptr (Ptr)
import Foreign.Storable
type InputStreamReadFunc a
= Ptr Char
-> Word64
-> Ptr a
-> IO Word64
type InputStreamSeekFunc a
= Word64
-> Ptr a
-> IO Word64
type InputStreamTellFunc a
= Ptr a
-> IO Word64
type InputStreamGetSizeFunc a
= Ptr a
-> IO Word64
data InputStream = forall a. InputStream
{ read :: Ptr (InputStreamReadFunc a)
, seek :: Ptr (InputStreamSeekFunc a)
, tell :: Ptr (InputStreamTellFunc a)
, getSize :: Ptr (InputStreamGetSizeFunc a)
, userData :: Ptr a
}
instance Storable InputStream where
sizeOf _ = size_InputStream
alignment _ = alignment (undefined :: CInt)
peek ptr = InputStream
<$> (\hsc_ptr -> peekByteOff hsc_ptr 0) ptr
<*> (\hsc_ptr -> peekByteOff hsc_ptr 8) ptr
<*> (\hsc_ptr -> peekByteOff hsc_ptr 16) ptr
<*> (\hsc_ptr -> peekByteOff hsc_ptr 24) ptr
<*> (\hsc_ptr -> peekByteOff hsc_ptr 32) ptr
poke ptr (InputStream read seek tell gets udata) = do
(\hsc_ptr -> pokeByteOff hsc_ptr 0) ptr read
(\hsc_ptr -> pokeByteOff hsc_ptr 8) ptr seek
(\hsc_ptr -> pokeByteOff hsc_ptr 16) ptr tell
(\hsc_ptr -> pokeByteOff hsc_ptr 24) ptr gets
(\hsc_ptr -> pokeByteOff hsc_ptr 32) ptr udata
size_InputStream = (40)
instance Show InputStream where
show (InputStream read seek tell getSize userData) =
"InputStream { read = " ++ show read ++
", seek = " ++ show seek ++
", tell = " ++ show tell ++
", getSize = " ++ show getSize ++
", userData = " ++ show userData ++
"}"