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

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

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