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

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

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