{-# LANGUAGE EmptyDataDecls, FlexibleInstances,
  MultiParamTypeClasses, TypeFamilies #-}
module STD.Pair.Template where
import Foreign.C.Types
import Foreign.Ptr
import FFICXX.Runtime.Cast

data RawPair tp1 tp2

newtype Pair tp1 tp2 = Pair (Ptr (RawPair tp1 tp2))

class () => IPair tp1 tp2 where
        newPair :: tp1 -> tp2 -> IO (Pair tp1 tp2)
        
        deletePair :: Pair tp1 tp2 -> IO ()
        
        first_get :: Pair tp1 tp2 -> IO tp1
        
        first_set :: Pair tp1 tp2 -> tp1 -> IO ()
        
        second_get :: Pair tp1 tp2 -> IO tp2
        
        second_set :: Pair tp1 tp2 -> tp2 -> IO ()

instance () => FPtr (Pair tp1 tp2) where
        type Raw (Pair tp1 tp2) = RawPair tp1 tp2
        get_fptr :: Pair tp1 tp2 -> Ptr (Raw (Pair tp1 tp2))
get_fptr (Pair Ptr (RawPair tp1 tp2)
ptr) = Ptr (RawPair tp1 tp2)
ptr
        cast_fptr_to_obj :: Ptr (Raw (Pair tp1 tp2)) -> Pair tp1 tp2
cast_fptr_to_obj = forall tp1 tp2. Ptr (RawPair tp1 tp2) -> Pair tp1 tp2
Pair

instance () => Castable (Pair tp1 tp2) (Ptr (RawPair tp1 tp2))
         where
        cast :: forall r. Pair tp1 tp2 -> (Ptr (RawPair tp1 tp2) -> IO r) -> IO r
cast Pair tp1 tp2
x Ptr (RawPair tp1 tp2) -> IO r
f = Ptr (RawPair tp1 tp2) -> IO r
f (forall a b. Ptr a -> Ptr b
castPtr (forall a. FPtr a => a -> Ptr (Raw a)
get_fptr Pair tp1 tp2
x))
        uncast :: forall r. Ptr (RawPair tp1 tp2) -> (Pair tp1 tp2 -> IO r) -> IO r
uncast Ptr (RawPair tp1 tp2)
x Pair tp1 tp2 -> IO r
f = Pair tp1 tp2 -> IO r
f (forall a. FPtr a => Ptr (Raw a) -> a
cast_fptr_to_obj (forall a b. Ptr a -> Ptr b
castPtr Ptr (RawPair tp1 tp2)
x))