{-# LANGUAGE FlexibleInstances, FlexibleContexts, TypeFamilies,
  MultiParamTypeClasses, OverlappingInstances, IncoherentInstances
  #-}
module HROOT.Core.TApplication.Cast where
import Foreign.Ptr
import FFICXX.Runtime.Cast
import System.IO.Unsafe
import HROOT.Core.TApplication.RawType
import HROOT.Core.TApplication.Interface

instance (ITApplication a, FPtr a) =>
         Castable (a) (Ptr RawTApplication)
         where
        cast :: forall r. a -> (Ptr RawTApplication -> IO r) -> IO r
cast a
x Ptr RawTApplication -> IO r
f = Ptr RawTApplication -> IO r
f (Ptr (Raw a) -> Ptr RawTApplication
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 RawTApplication -> (a -> IO r) -> IO r
uncast Ptr RawTApplication
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 RawTApplication -> Ptr (Raw a)
forall a b. Ptr a -> Ptr b
castPtr Ptr RawTApplication
x))

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