-- GENERATED by C->Haskell Compiler, version 0.28.1 Switcheroo, 1 April 2016 (Haskell)
-- Edit the ORIGNAL .chs file instead!


{-# LINE 1 "src/Graphics/QML/Internal/BindPrim.chs" #-}
{-# LANGUAGE
    ForeignFunctionInterface
  #-}

module Graphics.QML.Internal.BindPrim where
import qualified Foreign.C.Types as C2HSImp
import qualified Foreign.Ptr as C2HSImp



import Graphics.QML.Internal.Types

import Foreign.C.Types
import Foreign.Marshal.Alloc
import Foreign.Marshal.Utils
import Foreign.Ptr
import System.IO.Unsafe



cIntToEnum :: Enum a => CInt -> a
cIntToEnum = toEnum . fromIntegral

enumToCInt :: Enum a => a -> CInt
enumToCInt = fromIntegral . fromEnum

--
-- String
--

newtype HsQMLStringHandle = HsQMLStringHandle (C2HSImp.Ptr (HsQMLStringHandle))
{-# LINE 27 "src/Graphics/QML/Internal/BindPrim.chs" #-}


hsqmlGetStringSize :: IO ((Int))
hsqmlGetStringSize =
  hsqmlGetStringSize'_ >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 31 "src/Graphics/QML/Internal/BindPrim.chs" #-}


hsqmlStringSize :: Int
hsqmlStringSize = unsafeDupablePerformIO $ hsqmlGetStringSize

hsqmlInitString :: (HsQMLStringHandle) -> IO ()
hsqmlInitString a1 =
  let {a1' = id a1} in 
  hsqmlInitString'_ a1' >>
  return ()

{-# LINE 38 "src/Graphics/QML/Internal/BindPrim.chs" #-}


hsqmlDeinitString :: (HsQMLStringHandle) -> IO ()
hsqmlDeinitString a1 =
  let {a1' = id a1} in 
  hsqmlDeinitString'_ a1' >>
  return ()

{-# LINE 42 "src/Graphics/QML/Internal/BindPrim.chs" #-}


hsqmlWriteString :: (Int) -> (HsQMLStringHandle) -> IO ((Ptr CUShort))
hsqmlWriteString a1 a2 =
  let {a1' = fromIntegral a1} in 
  let {a2' = id a2} in 
  hsqmlWriteString'_ a1' a2' >>= \res ->
  let {res' = id res} in
  return (res')

{-# LINE 47 "src/Graphics/QML/Internal/BindPrim.chs" #-}


hsqmlReadString :: (HsQMLStringHandle) -> (Ptr (Ptr CUShort)) -> IO ((Int))
hsqmlReadString a1 a2 =
  let {a1' = id a1} in 
  let {a2' = id a2} in 
  hsqmlReadString'_ a1' a2' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 52 "src/Graphics/QML/Internal/BindPrim.chs" #-}


withStrHndl :: (HsQMLStringHandle -> IO b) -> IO b
withStrHndl contFn =
    allocaBytes hsqmlStringSize $ \ptr -> do
        let str = HsQMLStringHandle ptr
        hsqmlInitString str
        ret <- contFn str
        hsqmlDeinitString str
        return ret

--
-- JSValue
--

newtype HsQMLJValHandle = HsQMLJValHandle (C2HSImp.Ptr (HsQMLJValHandle))
{-# LINE 67 "src/Graphics/QML/Internal/BindPrim.chs" #-}


hsqmlGetJvalSize :: IO ((Int))
hsqmlGetJvalSize =
  hsqmlGetJvalSize'_ >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 71 "src/Graphics/QML/Internal/BindPrim.chs" #-}


hsqmlJValSize :: Int
hsqmlJValSize = unsafeDupablePerformIO $ hsqmlGetJvalSize

hsqmlGetJvalTypeid :: IO ((Int))
hsqmlGetJvalTypeid =
  hsqmlGetJvalTypeid'_ >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 78 "src/Graphics/QML/Internal/BindPrim.chs" #-}


hsqmlJValTypeId :: Int
hsqmlJValTypeId = unsafeDupablePerformIO $ hsqmlGetJvalTypeid

hsqmlInitJvalNull :: (HsQMLJValHandle) -> (Bool) -> IO ()
hsqmlInitJvalNull a1 a2 =
  let {a1' = id a1} in 
  let {a2' = fromBool a2} in 
  hsqmlInitJvalNull'_ a1' a2' >>
  return ()

{-# LINE 86 "src/Graphics/QML/Internal/BindPrim.chs" #-}


hsqmlDeinitJval :: (HsQMLJValHandle) -> IO ()
hsqmlDeinitJval a1 =
  let {a1' = id a1} in 
  hsqmlDeinitJval'_ a1' >>
  return ()

{-# LINE 90 "src/Graphics/QML/Internal/BindPrim.chs" #-}


hsqmlSetJval :: (HsQMLJValHandle) -> (HsQMLJValHandle) -> IO ()
hsqmlSetJval a1 a2 =
  let {a1' = id a1} in 
  let {a2' = id a2} in 
  hsqmlSetJval'_ a1' a2' >>
  return ()

{-# LINE 95 "src/Graphics/QML/Internal/BindPrim.chs" #-}


hsqmlInitJvalBool :: (HsQMLJValHandle) -> (Bool) -> IO ()
hsqmlInitJvalBool a1 a2 =
  let {a1' = id a1} in 
  let {a2' = fromBool a2} in 
  hsqmlInitJvalBool'_ a1' a2' >>
  return ()

{-# LINE 100 "src/Graphics/QML/Internal/BindPrim.chs" #-}


hsqmlIsJvalBool :: (HsQMLJValHandle) -> IO ((Bool))
hsqmlIsJvalBool a1 =
  let {a1' = id a1} in 
  hsqmlIsJvalBool'_ a1' >>= \res ->
  let {res' = toBool res} in
  return (res')

{-# LINE 104 "src/Graphics/QML/Internal/BindPrim.chs" #-}


hsqmlGetJvalBool :: (HsQMLJValHandle) -> IO ((Bool))
hsqmlGetJvalBool a1 =
  let {a1' = id a1} in 
  hsqmlGetJvalBool'_ a1' >>= \res ->
  let {res' = toBool res} in
  return (res')

{-# LINE 108 "src/Graphics/QML/Internal/BindPrim.chs" #-}


hsqmlInitJvalInt :: (HsQMLJValHandle) -> (CInt) -> IO ()
hsqmlInitJvalInt a1 a2 =
  let {a1' = id a1} in 
  let {a2' = id a2} in 
  hsqmlInitJvalInt'_ a1' a2' >>
  return ()

{-# LINE 113 "src/Graphics/QML/Internal/BindPrim.chs" #-}


hsqmlInitJvalDouble :: (HsQMLJValHandle) -> (CDouble) -> IO ()
hsqmlInitJvalDouble a1 a2 =
  let {a1' = id a1} in 
  let {a2' = id a2} in 
  hsqmlInitJvalDouble'_ a1' a2' >>
  return ()

{-# LINE 118 "src/Graphics/QML/Internal/BindPrim.chs" #-}


hsqmlIsJvalNumber :: (HsQMLJValHandle) -> IO ((Bool))
hsqmlIsJvalNumber a1 =
  let {a1' = id a1} in 
  hsqmlIsJvalNumber'_ a1' >>= \res ->
  let {res' = toBool res} in
  return (res')

{-# LINE 122 "src/Graphics/QML/Internal/BindPrim.chs" #-}


hsqmlGetJvalInt :: (HsQMLJValHandle) -> IO ((CInt))
hsqmlGetJvalInt a1 =
  let {a1' = id a1} in 
  hsqmlGetJvalInt'_ a1' >>= \res ->
  let {res' = id res} in
  return (res')

{-# LINE 126 "src/Graphics/QML/Internal/BindPrim.chs" #-}


hsqmlGetJvalDouble :: (HsQMLJValHandle) -> IO ((CDouble))
hsqmlGetJvalDouble a1 =
  let {a1' = id a1} in 
  hsqmlGetJvalDouble'_ a1' >>= \res ->
  let {res' = id res} in
  return (res')

{-# LINE 130 "src/Graphics/QML/Internal/BindPrim.chs" #-}


hsqmlInitJvalString :: (HsQMLJValHandle) -> (HsQMLStringHandle) -> IO ()
hsqmlInitJvalString a1 a2 =
  let {a1' = id a1} in 
  let {a2' = id a2} in 
  hsqmlInitJvalString'_ a1' a2' >>
  return ()

{-# LINE 135 "src/Graphics/QML/Internal/BindPrim.chs" #-}


hsqmlIsJvalString :: (HsQMLJValHandle) -> IO ((Bool))
hsqmlIsJvalString a1 =
  let {a1' = id a1} in 
  hsqmlIsJvalString'_ a1' >>= \res ->
  let {res' = toBool res} in
  return (res')

{-# LINE 139 "src/Graphics/QML/Internal/BindPrim.chs" #-}


hsqmlGetJvalString :: (HsQMLJValHandle) -> (HsQMLStringHandle) -> IO ()
hsqmlGetJvalString a1 a2 =
  let {a1' = id a1} in 
  let {a2' = id a2} in 
  hsqmlGetJvalString'_ a1' a2' >>
  return ()

{-# LINE 144 "src/Graphics/QML/Internal/BindPrim.chs" #-}


fromJVal ::
    Strength -> (HsQMLJValHandle -> IO Bool) -> (HsQMLJValHandle -> IO a) ->
    HsQMLJValHandle -> IO (Maybe a)
fromJVal Strong _ getFn jval =
    fmap Just $ getFn jval
fromJVal Weak isFn getFn jval = do
    is <- isFn jval
    if is then fmap Just $ getFn jval else return Nothing

withJVal ::
    (HsQMLJValHandle -> a -> IO ()) -> a -> (HsQMLJValHandle -> IO b) -> IO b
withJVal initFn val contFn =
    allocaBytes hsqmlJValSize $ \ptr -> do
        let jval = HsQMLJValHandle ptr
        initFn jval val
        ret <- contFn jval
        hsqmlDeinitJval jval
        return ret

--
-- Array
--

hsqmlInitJvalArray :: (HsQMLJValHandle) -> (Int) -> IO ()
hsqmlInitJvalArray a1 a2 =
  let {a1' = id a1} in 
  let {a2' = fromIntegral a2} in 
  hsqmlInitJvalArray'_ a1' a2' >>
  return ()

{-# LINE 172 "src/Graphics/QML/Internal/BindPrim.chs" #-}


hsqmlIsJvalArray :: (HsQMLJValHandle) -> IO ((Bool))
hsqmlIsJvalArray a1 =
  let {a1' = id a1} in 
  hsqmlIsJvalArray'_ a1' >>= \res ->
  let {res' = toBool res} in
  return (res')

{-# LINE 176 "src/Graphics/QML/Internal/BindPrim.chs" #-}


hsqmlGetJvalArrayLength :: (HsQMLJValHandle) -> IO ((Int))
hsqmlGetJvalArrayLength a1 =
  let {a1' = id a1} in 
  hsqmlGetJvalArrayLength'_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 180 "src/Graphics/QML/Internal/BindPrim.chs" #-}


hsqmlJvalArrayGet :: (HsQMLJValHandle) -> (Int) -> (HsQMLJValHandle) -> IO ()
hsqmlJvalArrayGet a1 a2 a3 =
  let {a1' = id a1} in 
  let {a2' = fromIntegral a2} in 
  let {a3' = id a3} in 
  hsqmlJvalArrayGet'_ a1' a2' a3' >>
  return ()

{-# LINE 186 "src/Graphics/QML/Internal/BindPrim.chs" #-}


hsqmlJvalArraySet :: (HsQMLJValHandle) -> (Int) -> (HsQMLJValHandle) -> IO ()
hsqmlJvalArraySet a1 a2 a3 =
  let {a1' = id a1} in 
  let {a2' = fromIntegral a2} in 
  let {a3' = id a3} in 
  hsqmlJvalArraySet'_ a1' a2' a3' >>
  return ()

{-# LINE 192 "src/Graphics/QML/Internal/BindPrim.chs" #-}


foreign import ccall unsafe "Graphics/QML/Internal/BindPrim.chs.h hsqml_get_string_size"
  hsqmlGetStringSize'_ :: (IO C2HSImp.CULong)

foreign import ccall unsafe "Graphics/QML/Internal/BindPrim.chs.h hsqml_init_string"
  hsqmlInitString'_ :: ((HsQMLStringHandle) -> (IO ()))

foreign import ccall unsafe "Graphics/QML/Internal/BindPrim.chs.h hsqml_deinit_string"
  hsqmlDeinitString'_ :: ((HsQMLStringHandle) -> (IO ()))

foreign import ccall unsafe "Graphics/QML/Internal/BindPrim.chs.h hsqml_write_string"
  hsqmlWriteString'_ :: (C2HSImp.CInt -> ((HsQMLStringHandle) -> (IO (C2HSImp.Ptr C2HSImp.CUShort))))

foreign import ccall unsafe "Graphics/QML/Internal/BindPrim.chs.h hsqml_read_string"
  hsqmlReadString'_ :: ((HsQMLStringHandle) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CUShort)) -> (IO C2HSImp.CInt)))

foreign import ccall unsafe "Graphics/QML/Internal/BindPrim.chs.h hsqml_get_jval_size"
  hsqmlGetJvalSize'_ :: (IO C2HSImp.CULong)

foreign import ccall unsafe "Graphics/QML/Internal/BindPrim.chs.h hsqml_get_jval_typeid"
  hsqmlGetJvalTypeid'_ :: (IO C2HSImp.CInt)

foreign import ccall unsafe "Graphics/QML/Internal/BindPrim.chs.h hsqml_init_jval_null"
  hsqmlInitJvalNull'_ :: ((HsQMLJValHandle) -> (C2HSImp.CInt -> (IO ())))

foreign import ccall unsafe "Graphics/QML/Internal/BindPrim.chs.h hsqml_deinit_jval"
  hsqmlDeinitJval'_ :: ((HsQMLJValHandle) -> (IO ()))

foreign import ccall unsafe "Graphics/QML/Internal/BindPrim.chs.h hsqml_set_jval"
  hsqmlSetJval'_ :: ((HsQMLJValHandle) -> ((HsQMLJValHandle) -> (IO ())))

foreign import ccall unsafe "Graphics/QML/Internal/BindPrim.chs.h hsqml_init_jval_bool"
  hsqmlInitJvalBool'_ :: ((HsQMLJValHandle) -> (C2HSImp.CInt -> (IO ())))

foreign import ccall unsafe "Graphics/QML/Internal/BindPrim.chs.h hsqml_is_jval_bool"
  hsqmlIsJvalBool'_ :: ((HsQMLJValHandle) -> (IO C2HSImp.CInt))

foreign import ccall unsafe "Graphics/QML/Internal/BindPrim.chs.h hsqml_get_jval_bool"
  hsqmlGetJvalBool'_ :: ((HsQMLJValHandle) -> (IO C2HSImp.CInt))

foreign import ccall unsafe "Graphics/QML/Internal/BindPrim.chs.h hsqml_init_jval_int"
  hsqmlInitJvalInt'_ :: ((HsQMLJValHandle) -> (C2HSImp.CInt -> (IO ())))

foreign import ccall unsafe "Graphics/QML/Internal/BindPrim.chs.h hsqml_init_jval_double"
  hsqmlInitJvalDouble'_ :: ((HsQMLJValHandle) -> (C2HSImp.CDouble -> (IO ())))

foreign import ccall unsafe "Graphics/QML/Internal/BindPrim.chs.h hsqml_is_jval_number"
  hsqmlIsJvalNumber'_ :: ((HsQMLJValHandle) -> (IO C2HSImp.CInt))

foreign import ccall unsafe "Graphics/QML/Internal/BindPrim.chs.h hsqml_get_jval_int"
  hsqmlGetJvalInt'_ :: ((HsQMLJValHandle) -> (IO C2HSImp.CInt))

foreign import ccall unsafe "Graphics/QML/Internal/BindPrim.chs.h hsqml_get_jval_double"
  hsqmlGetJvalDouble'_ :: ((HsQMLJValHandle) -> (IO C2HSImp.CDouble))

foreign import ccall unsafe "Graphics/QML/Internal/BindPrim.chs.h hsqml_init_jval_string"
  hsqmlInitJvalString'_ :: ((HsQMLJValHandle) -> ((HsQMLStringHandle) -> (IO ())))

foreign import ccall unsafe "Graphics/QML/Internal/BindPrim.chs.h hsqml_is_jval_string"
  hsqmlIsJvalString'_ :: ((HsQMLJValHandle) -> (IO C2HSImp.CInt))

foreign import ccall unsafe "Graphics/QML/Internal/BindPrim.chs.h hsqml_get_jval_string"
  hsqmlGetJvalString'_ :: ((HsQMLJValHandle) -> ((HsQMLStringHandle) -> (IO ())))

foreign import ccall unsafe "Graphics/QML/Internal/BindPrim.chs.h hsqml_init_jval_array"
  hsqmlInitJvalArray'_ :: ((HsQMLJValHandle) -> (C2HSImp.CUInt -> (IO ())))

foreign import ccall unsafe "Graphics/QML/Internal/BindPrim.chs.h hsqml_is_jval_array"
  hsqmlIsJvalArray'_ :: ((HsQMLJValHandle) -> (IO C2HSImp.CInt))

foreign import ccall unsafe "Graphics/QML/Internal/BindPrim.chs.h hsqml_get_jval_array_length"
  hsqmlGetJvalArrayLength'_ :: ((HsQMLJValHandle) -> (IO C2HSImp.CUInt))

foreign import ccall unsafe "Graphics/QML/Internal/BindPrim.chs.h hsqml_jval_array_get"
  hsqmlJvalArrayGet'_ :: ((HsQMLJValHandle) -> (C2HSImp.CUInt -> ((HsQMLJValHandle) -> (IO ()))))

foreign import ccall unsafe "Graphics/QML/Internal/BindPrim.chs.h hsqml_jval_array_set"
  hsqmlJvalArraySet'_ :: ((HsQMLJValHandle) -> (C2HSImp.CUInt -> ((HsQMLJValHandle) -> (IO ()))))