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

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

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