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

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

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