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

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

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