-- GENERATED by C->Haskell Compiler, version 0.13.12 (gtk2hs branch) "Bin IO", 27 May 2012 (Haskell)
-- Edit the ORIGNAL .chs file instead!

{-# LANGUAGE FlexibleInstances #-}

{-# LINE 1 "./Graphics/Rendering/Cairo/Internal/Utilities.chs" #-}
-----------------------------------------------------------------------------
-- |
-- Module      :  Graphics.Rendering.Cairo.Internal.Utilities
-- Copyright   :  (c) Paolo Martini 2005
-- License     :  BSD-style (see cairo/COPYRIGHT)
--
-- Maintainer  :  p.martini@neuralnoise.com
-- Stability   :  experimental
-- Portability :  portable
--
-- http://cairographics.org/manual/Support.html
-----------------------------------------------------------------------------

module Graphics.Rendering.Cairo.Internal.Utilities where

import Graphics.Rendering.Cairo.Types
{-# LINE 17 "./Graphics/Rendering/Cairo/Internal/Utilities.chs" #-}

import Foreign
import Foreign.C
import System.IO.Unsafe (unsafePerformIO)

import Codec.Binary.UTF8.String
import Data.Char (ord, chr)
import Data.Text (Text)
import Data.ByteString (useAsCString)
import qualified Data.Text.Encoding as T (encodeUtf8)


{-# LINE 31 "./Graphics/Rendering/Cairo/Internal/Utilities.chs" #-}

statusToString :: Status -> IO (String)
statusToString a1 =
  let {a1' = cFromEnum a1} in 
  statusToString'_ a1' >>= \res ->
  peekCString res >>= \res' ->
  return (res')
{-# LINE 33 "./Graphics/Rendering/Cairo/Internal/Utilities.chs" #-}
version :: Int
version =
  let {res = version'_} in
  let {res' = cIntConv res} in
  (res')
{-# LINE 34 "./Graphics/Rendering/Cairo/Internal/Utilities.chs" #-}
versionString :: String
versionString =
  unsafePerformIO $
  let {res = versionString'_} in
  peekCString res >>= \res' ->
  return (res')
{-# LINE 35 "./Graphics/Rendering/Cairo/Internal/Utilities.chs" #-}

class CairoString s where
    withUTFString :: s -> (CString -> IO a) -> IO a

instance CairoString [Char] where
    withUTFString = withCAString . encodeString

instance CairoString Text where
    withUTFString s = useAsCString (T.encodeUtf8 s)

foreign import ccall safe "dist/build/Graphics/Rendering/Cairo/Internal/Utilities.h cairo_status_to_string"
  statusToString'_ :: (CInt -> (IO (Ptr CChar)))

foreign import ccall safe "dist/build/Graphics/Rendering/Cairo/Internal/Utilities.h cairo_version"
  version'_ :: CInt

foreign import ccall safe "dist/build/Graphics/Rendering/Cairo/Internal/Utilities.h cairo_version_string"
  versionString'_ :: (Ptr CChar)