{-# LANGUAGE FlexibleInstances, FlexibleContexts, TypeFamilies, MultiParamTypeClasses, OverlappingInstances, IncoherentInstances #-} module OGDF.GraphIO.Cast where import Foreign.Ptr import FFICXX.Runtime.Cast import System.IO.Unsafe import OGDF.GraphIO.RawType import OGDF.GraphIO.Interface instance (IGraphIO a, FPtr a) => Castable (a) (Ptr RawGraphIO) where cast :: forall r. a -> (Ptr RawGraphIO -> IO r) -> IO r cast a x Ptr RawGraphIO -> IO r f = Ptr RawGraphIO -> IO r f (Ptr (Raw a) -> Ptr RawGraphIO 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 RawGraphIO -> (a -> IO r) -> IO r uncast Ptr RawGraphIO 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 RawGraphIO -> Ptr (Raw a) forall a b. Ptr a -> Ptr b castPtr Ptr RawGraphIO x)) instance () => Castable (GraphIO) (Ptr RawGraphIO) where cast :: forall r. GraphIO -> (Ptr RawGraphIO -> IO r) -> IO r cast GraphIO x Ptr RawGraphIO -> IO r f = Ptr RawGraphIO -> IO r f (Ptr RawGraphIO -> Ptr RawGraphIO forall a b. Ptr a -> Ptr b castPtr (GraphIO -> Ptr (Raw GraphIO) forall a. FPtr a => a -> Ptr (Raw a) get_fptr GraphIO x)) uncast :: forall r. Ptr RawGraphIO -> (GraphIO -> IO r) -> IO r uncast Ptr RawGraphIO x GraphIO -> IO r f = GraphIO -> IO r f (Ptr (Raw GraphIO) -> GraphIO forall a. FPtr a => Ptr (Raw a) -> a cast_fptr_to_obj (Ptr RawGraphIO -> Ptr RawGraphIO forall a b. Ptr a -> Ptr b castPtr Ptr RawGraphIO x))