{-# 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 (Raw (Pair tp1 tp2)) Ptr (RawPair tp1 tp2) ptr cast_fptr_to_obj :: Ptr (Raw (Pair tp1 tp2)) -> Pair tp1 tp2 cast_fptr_to_obj = Ptr (Raw (Pair tp1 tp2)) -> Pair tp1 tp2 Ptr (RawPair tp1 tp2) -> Pair tp1 tp2 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 (Ptr (RawPair tp1 tp2) -> Ptr (RawPair tp1 tp2) forall a b. Ptr a -> Ptr b castPtr (Pair tp1 tp2 -> Ptr (Raw (Pair tp1 tp2)) 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 (Ptr (Raw (Pair tp1 tp2)) -> Pair tp1 tp2 forall a. FPtr a => Ptr (Raw a) -> a cast_fptr_to_obj (Ptr (RawPair tp1 tp2) -> Ptr (RawPair tp1 tp2) forall a b. Ptr a -> Ptr b castPtr Ptr (RawPair tp1 tp2) x))