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

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

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