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