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

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

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