module Graphics.Text.Font.Choose.Result (FcException(..), throwBool, throwNull, throwString) where
import Foreign.Ptr (Ptr, nullPtr)
import Text.Read (readMaybe)
import Control.Exception (Exception, throwIO)
data FcException = ErrType | ErrNoId | ErrOOM | ErrOther deriving (Read, Show, Eq, Enum)
instance Exception FcException
throwBool :: Bool -> IO ()
throwBool False = throwIO ErrOOM
throwBool True = return ()
throwNull :: Ptr a -> IO (Ptr a)
throwNull a | a == nullPtr = throwIO ErrOOM
| otherwise = return a
throwString :: String -> IO ()
throwString a | Just b <- readMaybe a :: Maybe FcException = throwIO b
| otherwise = return ()