{-# LANGUAGE DeriveDataTypeable, EmptyDataDecls, ForeignFunctionInterface #-}
-- |
-- Module      : Data.Text.ICU.Collate.Internal
-- Copyright   : (c) 2010 Bryan O'Sullivan
--
-- License     : BSD-style
-- Maintainer  : bos@serpentine.com
-- Stability   : experimental
-- Portability : GHC
--
-- Internals of the string collation infrastructure.

module Data.Text.ICU.Number.Internal
    (
    -- * Unicode collation API
      MNumberFormat(..)
    , NumberFormat(..)
    , UNumberFormat
    , withNumberFormat
    , wrap
    )
where

import Data.Typeable (Typeable)
import Foreign.ForeignPtr (ForeignPtr, withForeignPtr)
import Foreign.Ptr (FunPtr, Ptr)
import Data.Text.ICU.Internal (newICUPtr)

-- $api
--

data UNumberFormat

-- | This is the number formatter. It can be created with 'formatter'. Use it to format numbers with the 'format' function.
data MNumberFormat = MNumberFormat {-# UNPACK #-} !(ForeignPtr UNumberFormat)
                 deriving (Typeable)

-- | This is the number formatter. It can be created with 'formatter'. Use it to format numbers with the 'format' function.
newtype NumberFormat = C MNumberFormat
    deriving (Typeable)

withNumberFormat :: MNumberFormat -> (Ptr UNumberFormat -> IO a) -> IO a
withNumberFormat :: forall a. MNumberFormat -> (Ptr UNumberFormat -> IO a) -> IO a
withNumberFormat (MNumberFormat ForeignPtr UNumberFormat
col) Ptr UNumberFormat -> IO a
action = forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr UNumberFormat
col Ptr UNumberFormat -> IO a
action
{-# INLINE withNumberFormat #-}

wrap :: IO (Ptr UNumberFormat) -> IO MNumberFormat
wrap :: IO (Ptr UNumberFormat) -> IO MNumberFormat
wrap = forall a i.
(ForeignPtr a -> i) -> FinalizerPtr a -> IO (Ptr a) -> IO i
newICUPtr ForeignPtr UNumberFormat -> MNumberFormat
MNumberFormat FunPtr (Ptr UNumberFormat -> IO ())
unum_close
{-# INLINE wrap #-}

foreign import ccall unsafe "hs_text_icu.h &__hs_unum_close" unum_close
    :: FunPtr (Ptr UNumberFormat -> IO ())