packages feed

gi-gobject-0.2.46.13: GI/GObject/Unions/TypeCValue.hs


{- |
Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
License    : LGPL-2.1
Maintainer : Iñaki García Etxebarria (garetxe@gmail.com)
-}

module GI.GObject.Unions.TypeCValue
    ( 

-- * Exported types
    TypeCValue(..)                          ,
    newZeroTypeCValue                       ,
    noTypeCValue                            ,


 -- * Properties
-- ** VDouble
    typeCValueReadVDouble                   ,


-- ** VInt
    typeCValueReadVInt                      ,


-- ** VInt64
    typeCValueReadVInt64                    ,


-- ** VLong
    typeCValueReadVLong                     ,


-- ** VPointer
    typeCValueReadVPointer                  ,




    ) where

import Prelude ()
import Data.GI.Base.ShortPrelude

import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map

import GI.GObject.Types
import GI.GObject.Callbacks

newtype TypeCValue = TypeCValue (ForeignPtr TypeCValue)
-- | Construct a `TypeCValue` struct initialized to zero.
newZeroTypeCValue :: MonadIO m => m TypeCValue
newZeroTypeCValue = liftIO $ callocBytes 8 >>= wrapPtr TypeCValue

noTypeCValue :: Maybe TypeCValue
noTypeCValue = Nothing

typeCValueReadVInt :: TypeCValue -> IO Int32
typeCValueReadVInt s = withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 0) :: IO Int32
    return val

typeCValueReadVLong :: TypeCValue -> IO Int64
typeCValueReadVLong s = withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 0) :: IO Int64
    return val

typeCValueReadVInt64 :: TypeCValue -> IO Int64
typeCValueReadVInt64 s = withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 0) :: IO Int64
    return val

typeCValueReadVDouble :: TypeCValue -> IO Double
typeCValueReadVDouble s = withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 0) :: IO CDouble
    let val' = realToFrac val
    return val'

typeCValueReadVPointer :: TypeCValue -> IO (Ptr ())
typeCValueReadVPointer s = withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 0) :: IO (Ptr ())
    return val

type family ResolveTypeCValueMethod (t :: Symbol) (o :: *) :: * where
    ResolveTypeCValueMethod l o = MethodResolutionFailed l o

instance (info ~ ResolveTypeCValueMethod t TypeCValue, MethodInfo info TypeCValue p) => IsLabelProxy t (TypeCValue -> p) where
    fromLabelProxy _ = overloadedMethod (MethodProxy :: MethodProxy info)

#if MIN_VERSION_base(4,9,0)
instance (info ~ ResolveTypeCValueMethod t TypeCValue, MethodInfo info TypeCValue p) => IsLabel t (TypeCValue -> p) where
    fromLabel _ = overloadedMethod (MethodProxy :: MethodProxy info)
#endif