{-# LANGUAGE FlexibleInstances, FlexibleContexts, TypeFamilies, MultiParamTypeClasses, OverlappingInstances, IncoherentInstances #-} module HROOT.Core.TKey.Cast where import Foreign.Ptr import FFICXX.Runtime.Cast import System.IO.Unsafe import HROOT.Core.TKey.RawType import HROOT.Core.TKey.Interface instance (ITKey a, FPtr a) => Castable (a) (Ptr RawTKey) where cast :: forall r. a -> (Ptr RawTKey -> IO r) -> IO r cast a x Ptr RawTKey -> IO r f = Ptr RawTKey -> IO r f (Ptr (Raw a) -> Ptr RawTKey forall a b. Ptr a -> Ptr b castPtr (a -> Ptr (Raw a) forall a. FPtr a => a -> Ptr (Raw a) get_fptr a x)) uncast :: forall r. Ptr RawTKey -> (a -> IO r) -> IO r uncast Ptr RawTKey x a -> IO r f = a -> IO r f (Ptr (Raw a) -> a forall a. FPtr a => Ptr (Raw a) -> a cast_fptr_to_obj (Ptr RawTKey -> Ptr (Raw a) forall a b. Ptr a -> Ptr b castPtr Ptr RawTKey x)) instance () => Castable (TKey) (Ptr RawTKey) where cast :: forall r. TKey -> (Ptr RawTKey -> IO r) -> IO r cast TKey x Ptr RawTKey -> IO r f = Ptr RawTKey -> IO r f (Ptr RawTKey -> Ptr RawTKey forall a b. Ptr a -> Ptr b castPtr (TKey -> Ptr (Raw TKey) forall a. FPtr a => a -> Ptr (Raw a) get_fptr TKey x)) uncast :: forall r. Ptr RawTKey -> (TKey -> IO r) -> IO r uncast Ptr RawTKey x TKey -> IO r f = TKey -> IO r f (Ptr (Raw TKey) -> TKey forall a. FPtr a => Ptr (Raw a) -> a cast_fptr_to_obj (Ptr RawTKey -> Ptr RawTKey forall a b. Ptr a -> Ptr b castPtr Ptr RawTKey x))