module WinDll.Lib.Tuples where
import WinDll.Lib.NativeMapping
import Foreign
import Foreign.C
import Foreign.Ptr
import Foreign.Marshal.Alloc
import Foreign.Marshal.Utils
import Control.Monad
import Control.Monad.Instances
data Tuple2 a b = Tuple2 a b
data Tuple3 a b c = Tuple3 a b c
data Tuple4 a b c d = Tuple4 a b c d
data Tuple5 a b c d e = Tuple5 a b c d e
data Tuple6 a b c d e f = Tuple6 a b c d e f
data Tuple7 a b c d e f g = Tuple7 a b c d e f g
data Tuple8 a b c d e f g h = Tuple8 a b c d e f g h
type Tuple2Ptr a b = Ptr (Tuple2 a b)
type Tuple3Ptr a b c = Ptr (Tuple3 a b c)
type Tuple4Ptr a b c d = Ptr (Tuple4 a b c d)
type Tuple5Ptr a b c d e = Ptr (Tuple5 a b c d e)
type Tuple6Ptr a b c d e f = Ptr (Tuple6 a b c d e f)
type Tuple7Ptr a b c d e f g = Ptr (Tuple7 a b c d e f g)
type Tuple8Ptr a b c d e f g h = Ptr (Tuple8 a b c d e f g h)
instance Storable a => Functor (Tuple2 a) where
fmap f (Tuple2 a b) = Tuple2 a (f b)
instance Storable a => Functor (Tuple3 a b) where
fmap f (Tuple3 a b c) = Tuple3 a b (f c)
instance Storable a => Functor (Tuple4 a b c) where
fmap f (Tuple4 a b c d) = Tuple4 a b c (f d)
instance Storable a => Functor (Tuple5 a b c d) where
fmap f (Tuple5 a b c d e) = Tuple5 a b c d (f e)
instance Storable a => Functor (Tuple6 a b c d e) where
fmap f (Tuple6 a b c d e f') = Tuple6 a b c d e (f f')
instance Storable a => Functor (Tuple7 a b c d e f) where
fmap f (Tuple7 a b c d e f' g) = Tuple7 a b c d e f' (f g)
instance Storable a => Functor (Tuple8 a b c d e f g) where
fmap f (Tuple8 a b c d e f' g h) = Tuple8 a b c d e f' g (f h)
instance (FFIType a b,FFIType c d) => FFIType (a,c)
(Tuple2 b d) where
toFFI (a,b) = (Tuple2 (toFFI a) (toFFI b))
fromFFI (Tuple2 a b) = (fromFFI a, fromFFI b)
instance (FFIType a b,FFIType c d
,FFIType e f) => FFIType (a,c,e)
(Tuple3 b d f) where
toFFI (a,b,c) = (Tuple3 (toFFI a) (toFFI b) (toFFI c))
fromFFI (Tuple3 a b c) = (fromFFI a, fromFFI b, fromFFI c)
instance (FFIType a b,FFIType c d
,FFIType e f,FFIType g h) => FFIType (a,c,e,g)
(Tuple4 b d f h) where
toFFI (a,b,c,d) = (Tuple4 (toFFI a) (toFFI b) (toFFI c) (toFFI d))
fromFFI (Tuple4 a b c d) = (fromFFI a, fromFFI b, fromFFI c, fromFFI d)
instance (FFIType a b,FFIType c d
,FFIType e f,FFIType g h
,FFIType i j) => FFIType (a,c,e,g,i)
(Tuple5 b d f h j) where
toFFI (a,b,c,d,e) = (Tuple5 (toFFI a) (toFFI b) (toFFI c) (toFFI d)
(toFFI e))
fromFFI (Tuple5 a b c d e) = (fromFFI a, fromFFI b, fromFFI c, fromFFI d
,fromFFI e)
instance (FFIType a b,FFIType c d
,FFIType e f,FFIType g h
,FFIType i j,FFIType k l) => FFIType (a,c,e,g,i,k) (Tuple6 b d f h j l) where
toFFI (a,b,c,d,e,f) = (Tuple6 (toFFI a) (toFFI b) (toFFI c) (toFFI d)
(toFFI e) (toFFI f))
fromFFI (Tuple6 a b c d e f) = (fromFFI a, fromFFI b, fromFFI c, fromFFI d
,fromFFI e, fromFFI f)
instance (FFIType a b,FFIType c d
,FFIType e f,FFIType g h
,FFIType i j,FFIType k l
,FFIType m n) => FFIType (a,c,e,g,i,k,m)
(Tuple7 b d f h j l n) where
toFFI (a,b,c,d,e,f,g) = (Tuple7 (toFFI a) (toFFI b) (toFFI c) (toFFI d)
(toFFI e) (toFFI f) (toFFI g))
fromFFI (Tuple7 a b c d e f g) = (fromFFI a, fromFFI b, fromFFI c, fromFFI d
,fromFFI e, fromFFI f, fromFFI g)
instance (FFIType a b,FFIType c d
,FFIType e f,FFIType g h
,FFIType i j,FFIType k l
,FFIType m n,FFIType o p) => FFIType (a,c,e,g,i,k,m,o)
(Tuple8 b d f h j l n p) where
toFFI (a,b,c,d,e,f,g,h) = (Tuple8 (toFFI a) (toFFI b) (toFFI c) (toFFI d)
(toFFI e) (toFFI f) (toFFI g) (toFFI h))
fromFFI (Tuple8 a b c d e f g h) = (fromFFI a, fromFFI b, fromFFI c, fromFFI d
,fromFFI e, fromFFI f, fromFFI g, fromFFI h)
instance (FFIType a b,FFIType c d
,Storable b, Storable d) => FFIType (a,c)
(Tuple2Ptr b d) where
toNative x = new (toFFI x)
fromNative x = fmap fromFFI (peek x)
instance (FFIType a b,FFIType c d
,FFIType e f,Storable b
,Storable d, Storable f) => FFIType (a,c,e)
(Tuple3Ptr b d f) where
toNative x = new (toFFI x)
fromNative x = fmap fromFFI (peek x)
instance (FFIType a b,FFIType c d
,FFIType e f,FFIType g h
,Storable b,Storable d
,Storable f,Storable h) => FFIType (a,c,e,g)
(Tuple4Ptr b d f h) where
toNative x = new (toFFI x)
fromNative x = fmap fromFFI (peek x)
instance (FFIType a b,FFIType c d
,FFIType e f,FFIType g h
,FFIType i j,Storable j
,Storable b,Storable d
,Storable f,Storable h) => FFIType (a,c,e,g,i)
(Tuple5Ptr b d f h j) where
toNative x = new (toFFI x)
fromNative x = fmap fromFFI (peek x)
instance (FFIType a b,FFIType c d
,FFIType e f,FFIType g h
,FFIType i j,FFIType k l
,Storable j,Storable l
,Storable b,Storable d
,Storable f,Storable h) => FFIType (a,c,e,g,i,k)
(Tuple6Ptr b d f h j l) where
toNative x = new (toFFI x)
fromNative x = fmap fromFFI (peek x)
instance (FFIType a b,FFIType c d
,FFIType e f,FFIType g h
,FFIType i j,FFIType k l
,FFIType m n,Storable n
,Storable j,Storable l
,Storable b,Storable d
,Storable f,Storable h) => FFIType (a,c,e,g,i,k,m)
(Tuple7Ptr b d f h j l n) where
toNative x = new (toFFI x)
fromNative x = fmap fromFFI (peek x)
instance (FFIType a b,FFIType c d
,FFIType e f,FFIType g h
,FFIType i j,FFIType k l
,FFIType m n,FFIType o p
,Storable n,Storable p
,Storable j,Storable l
,Storable b,Storable d
,Storable f,Storable h) => FFIType (a,c,e,g,i,k,m,o)
(Tuple8Ptr b d f h j l n p) where
toNative x = new (toFFI x)
fromNative x = fmap fromFFI (peek x)
instance (Storable a, Storable b) => Storable (Tuple2 a b) where
sizeOf _ = (8)
alignment _ = 4
poke ptr (Tuple2 a1 a2) = do
((\hsc_ptr -> pokeByteOff hsc_ptr 0)) ptr a1
((\hsc_ptr -> pokeByteOff hsc_ptr 4)) ptr a2
peek ptr = do
a1' <- ((\hsc_ptr -> peekByteOff hsc_ptr 0)) ptr
a2' <- ((\hsc_ptr -> peekByteOff hsc_ptr 4)) ptr
return $ (Tuple2 a1' a2')
instance (Storable a, Storable b, Storable c) => Storable (Tuple3 a b c) where
sizeOf _ = (12)
alignment _ = 4
poke ptr (Tuple3 a1 a2 a3) = do
((\hsc_ptr -> pokeByteOff hsc_ptr 0)) ptr a1
((\hsc_ptr -> pokeByteOff hsc_ptr 4)) ptr a2
((\hsc_ptr -> pokeByteOff hsc_ptr 8)) ptr a3
peek ptr = do
a1' <- ((\hsc_ptr -> peekByteOff hsc_ptr 0)) ptr
a2' <- ((\hsc_ptr -> peekByteOff hsc_ptr 4)) ptr
a3' <- ((\hsc_ptr -> peekByteOff hsc_ptr 8)) ptr
return $ (Tuple3 a1' a2' a3')
instance (Storable a, Storable b, Storable c, Storable d) => Storable (Tuple4 a b c d) where
sizeOf _ = (16)
alignment _ = 4
poke ptr (Tuple4 a1 a2 a3 a4) = do
((\hsc_ptr -> pokeByteOff hsc_ptr 0)) ptr a1
((\hsc_ptr -> pokeByteOff hsc_ptr 4)) ptr a2
((\hsc_ptr -> pokeByteOff hsc_ptr 8)) ptr a3
((\hsc_ptr -> pokeByteOff hsc_ptr 12)) ptr a4
peek ptr = do
a1' <- ((\hsc_ptr -> peekByteOff hsc_ptr 0)) ptr
a2' <- ((\hsc_ptr -> peekByteOff hsc_ptr 4)) ptr
a3' <- ((\hsc_ptr -> peekByteOff hsc_ptr 8)) ptr
a4' <- ((\hsc_ptr -> peekByteOff hsc_ptr 12)) ptr
return $ (Tuple4 a1' a2' a3' a4')
instance (Storable a, Storable b, Storable c, Storable d, Storable e) => Storable (Tuple5 a b c d e) where
sizeOf _ = (20)
alignment _ = 4
poke ptr (Tuple5 a1 a2 a3 a4 a5) = do
((\hsc_ptr -> pokeByteOff hsc_ptr 0)) ptr a1
((\hsc_ptr -> pokeByteOff hsc_ptr 4)) ptr a2
((\hsc_ptr -> pokeByteOff hsc_ptr 8)) ptr a3
((\hsc_ptr -> pokeByteOff hsc_ptr 12)) ptr a4
((\hsc_ptr -> pokeByteOff hsc_ptr 16)) ptr a5
peek ptr = do
a1' <- ((\hsc_ptr -> peekByteOff hsc_ptr 0)) ptr
a2' <- ((\hsc_ptr -> peekByteOff hsc_ptr 4)) ptr
a3' <- ((\hsc_ptr -> peekByteOff hsc_ptr 8)) ptr
a4' <- ((\hsc_ptr -> peekByteOff hsc_ptr 12)) ptr
a5' <- ((\hsc_ptr -> peekByteOff hsc_ptr 16)) ptr
return $ (Tuple5 a1' a2' a3' a4' a5')
instance (Storable a, Storable b, Storable c, Storable d, Storable e, Storable f) => Storable (Tuple6 a b c d e f) where
sizeOf _ = (24)
alignment _ = 4
poke ptr (Tuple6 a1 a2 a3 a4 a5 a6) = do
((\hsc_ptr -> pokeByteOff hsc_ptr 0)) ptr a1
((\hsc_ptr -> pokeByteOff hsc_ptr 4)) ptr a2
((\hsc_ptr -> pokeByteOff hsc_ptr 8)) ptr a3
((\hsc_ptr -> pokeByteOff hsc_ptr 12)) ptr a4
((\hsc_ptr -> pokeByteOff hsc_ptr 16)) ptr a5
((\hsc_ptr -> pokeByteOff hsc_ptr 20)) ptr a6
peek ptr = do
a1' <- ((\hsc_ptr -> peekByteOff hsc_ptr 0)) ptr
a2' <- ((\hsc_ptr -> peekByteOff hsc_ptr 4)) ptr
a3' <- ((\hsc_ptr -> peekByteOff hsc_ptr 8)) ptr
a4' <- ((\hsc_ptr -> peekByteOff hsc_ptr 12)) ptr
a5' <- ((\hsc_ptr -> peekByteOff hsc_ptr 16)) ptr
a6' <- ((\hsc_ptr -> peekByteOff hsc_ptr 20)) ptr
return $ (Tuple6 a1' a2' a3' a4' a5' a6')
instance (Storable a, Storable b, Storable c, Storable d, Storable e, Storable f, Storable g) => Storable (Tuple7 a b c d e f g) where
sizeOf _ = (28)
alignment _ = 4
poke ptr (Tuple7 a1 a2 a3 a4 a5 a6 a7) = do
((\hsc_ptr -> pokeByteOff hsc_ptr 0)) ptr a1
((\hsc_ptr -> pokeByteOff hsc_ptr 4)) ptr a2
((\hsc_ptr -> pokeByteOff hsc_ptr 8)) ptr a3
((\hsc_ptr -> pokeByteOff hsc_ptr 12)) ptr a4
((\hsc_ptr -> pokeByteOff hsc_ptr 16)) ptr a5
((\hsc_ptr -> pokeByteOff hsc_ptr 20)) ptr a6
((\hsc_ptr -> pokeByteOff hsc_ptr 24)) ptr a7
peek ptr = do
a1' <- ((\hsc_ptr -> peekByteOff hsc_ptr 0)) ptr
a2' <- ((\hsc_ptr -> peekByteOff hsc_ptr 4)) ptr
a3' <- ((\hsc_ptr -> peekByteOff hsc_ptr 8)) ptr
a4' <- ((\hsc_ptr -> peekByteOff hsc_ptr 12)) ptr
a5' <- ((\hsc_ptr -> peekByteOff hsc_ptr 16)) ptr
a6' <- ((\hsc_ptr -> peekByteOff hsc_ptr 20)) ptr
a7' <- ((\hsc_ptr -> peekByteOff hsc_ptr 24)) ptr
return $ (Tuple7 a1' a2' a3' a4' a5' a6' a7')
instance (Storable a, Storable b, Storable c, Storable d, Storable e, Storable f, Storable g, Storable h) => Storable (Tuple8 a b c d e f g h) where
sizeOf _ = (32)
alignment _ = 4
poke ptr (Tuple8 a1 a2 a3 a4 a5 a6 a7 a8) = do
((\hsc_ptr -> pokeByteOff hsc_ptr 0)) ptr a1
((\hsc_ptr -> pokeByteOff hsc_ptr 4)) ptr a2
((\hsc_ptr -> pokeByteOff hsc_ptr 8)) ptr a3
((\hsc_ptr -> pokeByteOff hsc_ptr 12)) ptr a4
((\hsc_ptr -> pokeByteOff hsc_ptr 16)) ptr a5
((\hsc_ptr -> pokeByteOff hsc_ptr 20)) ptr a6
((\hsc_ptr -> pokeByteOff hsc_ptr 24)) ptr a7
((\hsc_ptr -> pokeByteOff hsc_ptr 28)) ptr a8
peek ptr = do
a1' <- ((\hsc_ptr -> peekByteOff hsc_ptr 0)) ptr
a2' <- ((\hsc_ptr -> peekByteOff hsc_ptr 4)) ptr
a3' <- ((\hsc_ptr -> peekByteOff hsc_ptr 8)) ptr
a4' <- ((\hsc_ptr -> peekByteOff hsc_ptr 12)) ptr
a5' <- ((\hsc_ptr -> peekByteOff hsc_ptr 16)) ptr
a6' <- ((\hsc_ptr -> peekByteOff hsc_ptr 20)) ptr
a7' <- ((\hsc_ptr -> peekByteOff hsc_ptr 24)) ptr
a8' <- ((\hsc_ptr -> peekByteOff hsc_ptr 28)) ptr
return $ (Tuple8 a1' a2' a3' a4' a5' a6' a7' a8')
instance (Storable a, Storable b) => Storable (a, b) where
sizeOf _ = (8)
alignment _ = 4
poke ptr (a1, a2) = do
((\hsc_ptr -> pokeByteOff hsc_ptr 0)) ptr a1
((\hsc_ptr -> pokeByteOff hsc_ptr 4)) ptr a2
peek ptr = do
a1' <- ((\hsc_ptr -> peekByteOff hsc_ptr 0)) ptr
a2' <- ((\hsc_ptr -> peekByteOff hsc_ptr 4)) ptr
return $ (a1', a2')
instance (Storable a, Storable b, Storable c) => Storable (a, b, c) where
sizeOf _ = (12)
alignment _ = 4
poke ptr (a1, a2, a3) = do
((\hsc_ptr -> pokeByteOff hsc_ptr 0)) ptr a1
((\hsc_ptr -> pokeByteOff hsc_ptr 4)) ptr a2
((\hsc_ptr -> pokeByteOff hsc_ptr 8)) ptr a3
peek ptr = do
a1' <- ((\hsc_ptr -> peekByteOff hsc_ptr 0)) ptr
a2' <- ((\hsc_ptr -> peekByteOff hsc_ptr 4)) ptr
a3' <- ((\hsc_ptr -> peekByteOff hsc_ptr 8)) ptr
return $ (a1', a2', a3')
instance (Storable a, Storable b, Storable c, Storable d) => Storable (a, b, c, d) where
sizeOf _ = (16)
alignment _ = 4
poke ptr (a1, a2, a3, a4) = do
((\hsc_ptr -> pokeByteOff hsc_ptr 0)) ptr a1
((\hsc_ptr -> pokeByteOff hsc_ptr 4)) ptr a2
((\hsc_ptr -> pokeByteOff hsc_ptr 8)) ptr a3
((\hsc_ptr -> pokeByteOff hsc_ptr 12)) ptr a4
peek ptr = do
a1' <- ((\hsc_ptr -> peekByteOff hsc_ptr 0)) ptr
a2' <- ((\hsc_ptr -> peekByteOff hsc_ptr 4)) ptr
a3' <- ((\hsc_ptr -> peekByteOff hsc_ptr 8)) ptr
a4' <- ((\hsc_ptr -> peekByteOff hsc_ptr 12)) ptr
return $ (a1', a2', a3', a4')
instance (Storable a, Storable b, Storable c, Storable d, Storable e) => Storable (a, b, c, d, e) where
sizeOf _ = (20)
alignment _ = 4
poke ptr (a1, a2, a3, a4, a5) = do
((\hsc_ptr -> pokeByteOff hsc_ptr 0)) ptr a1
((\hsc_ptr -> pokeByteOff hsc_ptr 4)) ptr a2
((\hsc_ptr -> pokeByteOff hsc_ptr 8)) ptr a3
((\hsc_ptr -> pokeByteOff hsc_ptr 12)) ptr a4
((\hsc_ptr -> pokeByteOff hsc_ptr 16)) ptr a5
peek ptr = do
a1' <- ((\hsc_ptr -> peekByteOff hsc_ptr 0)) ptr
a2' <- ((\hsc_ptr -> peekByteOff hsc_ptr 4)) ptr
a3' <- ((\hsc_ptr -> peekByteOff hsc_ptr 8)) ptr
a4' <- ((\hsc_ptr -> peekByteOff hsc_ptr 12)) ptr
a5' <- ((\hsc_ptr -> peekByteOff hsc_ptr 16)) ptr
return $ (a1', a2', a3', a4', a5')
instance (Storable a, Storable b, Storable c, Storable d, Storable e, Storable f) => Storable (a, b, c, d, e, f) where
sizeOf _ = (24)
alignment _ = 4
poke ptr (a1, a2, a3, a4, a5, a6) = do
((\hsc_ptr -> pokeByteOff hsc_ptr 0)) ptr a1
((\hsc_ptr -> pokeByteOff hsc_ptr 4)) ptr a2
((\hsc_ptr -> pokeByteOff hsc_ptr 8)) ptr a3
((\hsc_ptr -> pokeByteOff hsc_ptr 12)) ptr a4
((\hsc_ptr -> pokeByteOff hsc_ptr 16)) ptr a5
((\hsc_ptr -> pokeByteOff hsc_ptr 20)) ptr a6
peek ptr = do
a1' <- ((\hsc_ptr -> peekByteOff hsc_ptr 0)) ptr
a2' <- ((\hsc_ptr -> peekByteOff hsc_ptr 4)) ptr
a3' <- ((\hsc_ptr -> peekByteOff hsc_ptr 8)) ptr
a4' <- ((\hsc_ptr -> peekByteOff hsc_ptr 12)) ptr
a5' <- ((\hsc_ptr -> peekByteOff hsc_ptr 16)) ptr
a6' <- ((\hsc_ptr -> peekByteOff hsc_ptr 20)) ptr
return $ (a1', a2', a3', a4', a5', a6')
instance (Storable a, Storable b, Storable c, Storable d, Storable e, Storable f, Storable g) => Storable (a, b, c, d, e, f, g) where
sizeOf _ = (28)
alignment _ = 4
poke ptr (a1, a2, a3, a4, a5, a6, a7) = do
((\hsc_ptr -> pokeByteOff hsc_ptr 0)) ptr a1
((\hsc_ptr -> pokeByteOff hsc_ptr 4)) ptr a2
((\hsc_ptr -> pokeByteOff hsc_ptr 8)) ptr a3
((\hsc_ptr -> pokeByteOff hsc_ptr 12)) ptr a4
((\hsc_ptr -> pokeByteOff hsc_ptr 16)) ptr a5
((\hsc_ptr -> pokeByteOff hsc_ptr 20)) ptr a6
((\hsc_ptr -> pokeByteOff hsc_ptr 24)) ptr a7
peek ptr = do
a1' <- ((\hsc_ptr -> peekByteOff hsc_ptr 0)) ptr
a2' <- ((\hsc_ptr -> peekByteOff hsc_ptr 4)) ptr
a3' <- ((\hsc_ptr -> peekByteOff hsc_ptr 8)) ptr
a4' <- ((\hsc_ptr -> peekByteOff hsc_ptr 12)) ptr
a5' <- ((\hsc_ptr -> peekByteOff hsc_ptr 16)) ptr
a6' <- ((\hsc_ptr -> peekByteOff hsc_ptr 20)) ptr
a7' <- ((\hsc_ptr -> peekByteOff hsc_ptr 24)) ptr
return $ (a1', a2', a3', a4', a5', a6', a7')
instance (Storable a, Storable b, Storable c, Storable d, Storable e, Storable f, Storable g, Storable h) => Storable (a, b, c, d, e, f, g, h) where
sizeOf _ = (32)
alignment _ = 4
poke ptr (a1, a2, a3, a4, a5, a6, a7, a8) = do
((\hsc_ptr -> pokeByteOff hsc_ptr 0)) ptr a1
((\hsc_ptr -> pokeByteOff hsc_ptr 4)) ptr a2
((\hsc_ptr -> pokeByteOff hsc_ptr 8)) ptr a3
((\hsc_ptr -> pokeByteOff hsc_ptr 12)) ptr a4
((\hsc_ptr -> pokeByteOff hsc_ptr 16)) ptr a5
((\hsc_ptr -> pokeByteOff hsc_ptr 20)) ptr a6
((\hsc_ptr -> pokeByteOff hsc_ptr 24)) ptr a7
((\hsc_ptr -> pokeByteOff hsc_ptr 28)) ptr a8
peek ptr = do
a1' <- ((\hsc_ptr -> peekByteOff hsc_ptr 0)) ptr
a2' <- ((\hsc_ptr -> peekByteOff hsc_ptr 4)) ptr
a3' <- ((\hsc_ptr -> peekByteOff hsc_ptr 8)) ptr
a4' <- ((\hsc_ptr -> peekByteOff hsc_ptr 12)) ptr
a5' <- ((\hsc_ptr -> peekByteOff hsc_ptr 16)) ptr
a6' <- ((\hsc_ptr -> peekByteOff hsc_ptr 20)) ptr
a7' <- ((\hsc_ptr -> peekByteOff hsc_ptr 24)) ptr
a8' <- ((\hsc_ptr -> peekByteOff hsc_ptr 28)) ptr
return $ (a1', a2', a3', a4', a5', a6', a7', a8')