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

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

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