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

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

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