{-# LINE 1 "Data/GI/Base/GValue.hsc" #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedStrings #-}
module Data.GI.Base.GValue
    (
    -- * Constructing GValues
      GValue(..)
    , IsGValue(..)
    , GValueConstruct(..)

    , newGValue
    , buildGValue
    , noGValue

    -- * Setters and getters
    , set_string
    , get_string
    , set_pointer
    , get_pointer
    , set_int
    , get_int
    , set_uint
    , get_uint
    , set_long
    , get_long
    , set_ulong
    , get_ulong
    , set_int32
    , get_int32
    , set_uint32
    , get_uint32
    , set_int64
    , get_int64
    , set_uint64
    , get_uint64
    , set_float
    , get_float
    , set_double
    , get_double
    , set_boolean
    , get_boolean
    , set_gtype
    , get_gtype
    , set_object
    , get_object
    , set_boxed
    , get_boxed
    , set_variant
    , get_variant
    , set_enum
    , get_enum
    , set_flags
    , get_flags
    , set_stablePtr
    , get_stablePtr
    , take_stablePtr
    ) where



import Data.Coerce (coerce)
import Data.Word
import Data.Int
import Data.Text (Text, pack, unpack)

import Foreign.C.Types (CInt(..), CUInt(..), CFloat(..), CDouble(..),
                        CLong(..), CULong(..))
import Foreign.C.String (CString)
import Foreign.Ptr (Ptr, nullPtr)
import Foreign.StablePtr (StablePtr, castStablePtrToPtr, castPtrToStablePtr)

import Data.GI.Base.BasicTypes
import Data.GI.Base.BasicConversions (cstringToText, textToCString)
import Data.GI.Base.GType
import Data.GI.Base.ManagedPtr
import Data.GI.Base.Utils (callocBytes, freeMem)

-- | Haskell-side representation of a @GValue@.
newtype GValue = GValue (ManagedPtr GValue)

-- | A convenience alias for @`Nothing` :: `Maybe` `GValue`@.
noGValue :: Maybe GValue
noGValue :: Maybe GValue
noGValue = Maybe GValue
forall a. Maybe a
Nothing

foreign import ccall unsafe "g_value_get_type" c_g_value_get_type ::
    IO CGType

instance BoxedObject GValue where
    boxedType :: GValue -> IO GType
boxedType _ = CGType -> GType
GType (CGType -> GType) -> IO CGType -> IO GType
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IO CGType
c_g_value_get_type

foreign import ccall "g_value_init" g_value_init ::
    Ptr GValue -> CGType -> IO (Ptr GValue)

-- | A type holding a `GValue` with an associated label. It is
-- parameterized by a phantom type encoding the target type for the
-- `GValue` (useful when constructing properties).
data GValueConstruct o = GValueConstruct String GValue

-- | Build a new, empty, `GValue` of the given type.
newGValue :: GType -> IO GValue
newGValue :: GType -> IO GValue
newGValue (GType gtype :: CGType
gtype) = do
  Ptr GValue
gvptr <- Int -> IO (Ptr GValue)
forall a. Int -> IO (Ptr a)
callocBytes ((24))
{-# LINE 102 "Data/GI/Base/GValue.hsc" #-}
  _ <- g_value_init gvptr gtype
  GValue
gv <- (ManagedPtr GValue -> GValue) -> Ptr GValue -> IO GValue
forall a.
(HasCallStack, BoxedObject a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
wrapBoxed ManagedPtr GValue -> GValue
GValue Ptr GValue
gvptr
  GValue -> IO GValue
forall (m :: * -> *) a. Monad m => a -> m a
return (GValue -> IO GValue) -> GValue -> IO GValue
forall a b. (a -> b) -> a -> b
$! GValue
gv

-- | A convenience function for building a new GValue and setting the
-- initial value.
buildGValue :: GType -> (GValue -> a -> IO ()) -> a -> IO GValue
buildGValue :: GType -> (GValue -> a -> IO ()) -> a -> IO GValue
buildGValue gtype :: GType
gtype setter :: GValue -> a -> IO ()
setter val :: a
val = do
  GValue
gv <- GType -> IO GValue
newGValue GType
gtype
  GValue -> a -> IO ()
setter GValue
gv a
val
  GValue -> IO GValue
forall (m :: * -> *) a. Monad m => a -> m a
return GValue
gv

-- | A convenience class for marshaling back and forth between Haskell
-- values and `GValue`s.
class IsGValue a where
    toGValue :: a -> IO GValue
    fromGValue :: GValue -> IO a

instance IsGValue (Maybe String) where
    toGValue :: Maybe String -> IO GValue
toGValue = GType -> (GValue -> Maybe Text -> IO ()) -> Maybe Text -> IO GValue
forall a. GType -> (GValue -> a -> IO ()) -> a -> IO GValue
buildGValue GType
gtypeString GValue -> Maybe Text -> IO ()
set_string (Maybe Text -> IO GValue)
-> (Maybe String -> Maybe Text) -> Maybe String -> IO GValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> Text) -> Maybe String -> Maybe Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> Text
pack
    fromGValue :: GValue -> IO (Maybe String)
fromGValue v :: GValue
v = ((Text -> String) -> Maybe Text -> Maybe String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Text -> String
unpack) (Maybe Text -> Maybe String)
-> IO (Maybe Text) -> IO (Maybe String)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> GValue -> IO (Maybe Text)
get_string GValue
v

instance IsGValue (Maybe Text) where
    toGValue :: Maybe Text -> IO GValue
toGValue = GType -> (GValue -> Maybe Text -> IO ()) -> Maybe Text -> IO GValue
forall a. GType -> (GValue -> a -> IO ()) -> a -> IO GValue
buildGValue GType
gtypeString GValue -> Maybe Text -> IO ()
set_string
    fromGValue :: GValue -> IO (Maybe Text)
fromGValue = GValue -> IO (Maybe Text)
get_string

instance IsGValue (Ptr a) where
    toGValue :: Ptr a -> IO GValue
toGValue = GType -> (GValue -> Ptr a -> IO ()) -> Ptr a -> IO GValue
forall a. GType -> (GValue -> a -> IO ()) -> a -> IO GValue
buildGValue GType
gtypePointer GValue -> Ptr a -> IO ()
forall a. GValue -> Ptr a -> IO ()
set_pointer
    fromGValue :: GValue -> IO (Ptr a)
fromGValue = GValue -> IO (Ptr a)
forall a. GValue -> IO (Ptr a)
get_pointer

instance IsGValue Int32 where
    toGValue :: Int32 -> IO GValue
toGValue = GType -> (GValue -> Int32 -> IO ()) -> Int32 -> IO GValue
forall a. GType -> (GValue -> a -> IO ()) -> a -> IO GValue
buildGValue GType
gtypeInt GValue -> Int32 -> IO ()
set_int32
    fromGValue :: GValue -> IO Int32
fromGValue = GValue -> IO Int32
get_int32

instance IsGValue Word32 where
    toGValue :: Word32 -> IO GValue
toGValue = GType -> (GValue -> Word32 -> IO ()) -> Word32 -> IO GValue
forall a. GType -> (GValue -> a -> IO ()) -> a -> IO GValue
buildGValue GType
gtypeUInt GValue -> Word32 -> IO ()
set_uint32
    fromGValue :: GValue -> IO Word32
fromGValue = GValue -> IO Word32
get_uint32

instance IsGValue CInt where
    toGValue :: CInt -> IO GValue
toGValue = GType -> (GValue -> CInt -> IO ()) -> CInt -> IO GValue
forall a. GType -> (GValue -> a -> IO ()) -> a -> IO GValue
buildGValue GType
gtypeInt GValue -> CInt -> IO ()
set_int
    fromGValue :: GValue -> IO CInt
fromGValue = GValue -> IO CInt
get_int

instance IsGValue CUInt where
    toGValue :: CUInt -> IO GValue
toGValue = GType -> (GValue -> CUInt -> IO ()) -> CUInt -> IO GValue
forall a. GType -> (GValue -> a -> IO ()) -> a -> IO GValue
buildGValue GType
gtypeUInt GValue -> CUInt -> IO ()
set_uint
    fromGValue :: GValue -> IO CUInt
fromGValue = GValue -> IO CUInt
get_uint

instance IsGValue CLong where
    toGValue :: CLong -> IO GValue
toGValue = GType -> (GValue -> CLong -> IO ()) -> CLong -> IO GValue
forall a. GType -> (GValue -> a -> IO ()) -> a -> IO GValue
buildGValue GType
gtypeLong GValue -> CLong -> IO ()
set_long
    fromGValue :: GValue -> IO CLong
fromGValue = GValue -> IO CLong
get_long

instance IsGValue CULong where
    toGValue :: CULong -> IO GValue
toGValue = GType -> (GValue -> CULong -> IO ()) -> CULong -> IO GValue
forall a. GType -> (GValue -> a -> IO ()) -> a -> IO GValue
buildGValue GType
gtypeULong GValue -> CULong -> IO ()
set_ulong
    fromGValue :: GValue -> IO CULong
fromGValue = GValue -> IO CULong
get_ulong

instance IsGValue Int64 where
    toGValue :: Int64 -> IO GValue
toGValue = GType -> (GValue -> Int64 -> IO ()) -> Int64 -> IO GValue
forall a. GType -> (GValue -> a -> IO ()) -> a -> IO GValue
buildGValue GType
gtypeInt64 GValue -> Int64 -> IO ()
set_int64
    fromGValue :: GValue -> IO Int64
fromGValue = GValue -> IO Int64
get_int64

instance IsGValue Word64 where
    toGValue :: CGType -> IO GValue
toGValue = GType -> (GValue -> CGType -> IO ()) -> CGType -> IO GValue
forall a. GType -> (GValue -> a -> IO ()) -> a -> IO GValue
buildGValue GType
gtypeUInt64 GValue -> CGType -> IO ()
set_uint64
    fromGValue :: GValue -> IO CGType
fromGValue = GValue -> IO CGType
get_uint64

instance IsGValue Float where
    toGValue :: Float -> IO GValue
toGValue = GType -> (GValue -> Float -> IO ()) -> Float -> IO GValue
forall a. GType -> (GValue -> a -> IO ()) -> a -> IO GValue
buildGValue GType
gtypeFloat GValue -> Float -> IO ()
set_float
    fromGValue :: GValue -> IO Float
fromGValue = GValue -> IO Float
get_float

instance IsGValue Double where
    toGValue :: Double -> IO GValue
toGValue = GType -> (GValue -> Double -> IO ()) -> Double -> IO GValue
forall a. GType -> (GValue -> a -> IO ()) -> a -> IO GValue
buildGValue GType
gtypeDouble GValue -> Double -> IO ()
set_double
    fromGValue :: GValue -> IO Double
fromGValue = GValue -> IO Double
get_double

instance IsGValue Bool where
    toGValue :: Bool -> IO GValue
toGValue = GType -> (GValue -> Bool -> IO ()) -> Bool -> IO GValue
forall a. GType -> (GValue -> a -> IO ()) -> a -> IO GValue
buildGValue GType
gtypeBoolean GValue -> Bool -> IO ()
set_boolean
    fromGValue :: GValue -> IO Bool
fromGValue = GValue -> IO Bool
get_boolean

instance IsGValue GType where
    toGValue :: GType -> IO GValue
toGValue = GType -> (GValue -> GType -> IO ()) -> GType -> IO GValue
forall a. GType -> (GValue -> a -> IO ()) -> a -> IO GValue
buildGValue GType
gtypeGType GValue -> GType -> IO ()
set_gtype
    fromGValue :: GValue -> IO GType
fromGValue = GValue -> IO GType
get_gtype

instance IsGValue (StablePtr a) where
    toGValue :: StablePtr a -> IO GValue
toGValue = GType
-> (GValue -> StablePtr a -> IO ()) -> StablePtr a -> IO GValue
forall a. GType -> (GValue -> a -> IO ()) -> a -> IO GValue
buildGValue GType
gtypeStablePtr GValue -> StablePtr a -> IO ()
forall a. GValue -> StablePtr a -> IO ()
set_stablePtr
    fromGValue :: GValue -> IO (StablePtr a)
fromGValue = GValue -> IO (StablePtr a)
forall a. GValue -> IO (StablePtr a)
get_stablePtr

foreign import ccall "g_value_set_string" _set_string ::
    Ptr GValue -> CString -> IO ()
foreign import ccall "g_value_get_string" _get_string ::
    Ptr GValue -> IO CString

set_string :: GValue -> Maybe Text -> IO ()
set_string :: GValue -> Maybe Text -> IO ()
set_string gv :: GValue
gv maybeStr :: Maybe Text
maybeStr =
    GValue -> (Ptr GValue -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr GValue
gv ((Ptr GValue -> IO ()) -> IO ()) -> (Ptr GValue -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \ptr :: Ptr GValue
ptr -> do
      CString
cstr <- case Maybe Text
maybeStr of
                Just str :: Text
str -> Text -> IO CString
textToCString Text
str
                Nothing -> CString -> IO CString
forall (m :: * -> *) a. Monad m => a -> m a
return CString
forall a. Ptr a
nullPtr
      Ptr GValue -> CString -> IO ()
_set_string Ptr GValue
ptr CString
cstr
      CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
cstr

get_string :: GValue -> IO (Maybe Text)
get_string :: GValue -> IO (Maybe Text)
get_string gv :: GValue
gv = GValue -> (Ptr GValue -> IO (Maybe Text)) -> IO (Maybe Text)
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr GValue
gv ((Ptr GValue -> IO (Maybe Text)) -> IO (Maybe Text))
-> (Ptr GValue -> IO (Maybe Text)) -> IO (Maybe Text)
forall a b. (a -> b) -> a -> b
$ \gvptr :: Ptr GValue
gvptr -> do
                  CString
cstr <- Ptr GValue -> IO CString
_get_string Ptr GValue
gvptr
                  if CString
cstr CString -> CString -> Bool
forall a. Eq a => a -> a -> Bool
/= CString
forall a. Ptr a
nullPtr
                  then Text -> Maybe Text
forall a. a -> Maybe a
Just (Text -> Maybe Text) -> IO Text -> IO (Maybe Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> HasCallStack => CString -> IO Text
CString -> IO Text
cstringToText CString
cstr
                  else Maybe Text -> IO (Maybe Text)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Text
forall a. Maybe a
Nothing

foreign import ccall unsafe "g_value_set_pointer" _set_pointer ::
    Ptr GValue -> Ptr a -> IO ()
foreign import ccall unsafe "g_value_get_pointer" _get_pointer ::
    Ptr GValue -> IO (Ptr b)

set_pointer :: GValue -> Ptr a -> IO ()
set_pointer :: GValue -> Ptr a -> IO ()
set_pointer gv :: GValue
gv ptr :: Ptr a
ptr = GValue -> (Ptr GValue -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr GValue
gv ((Ptr GValue -> IO ()) -> IO ()) -> (Ptr GValue -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ (Ptr GValue -> Ptr a -> IO ()) -> Ptr a -> Ptr GValue -> IO ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip Ptr GValue -> Ptr a -> IO ()
forall a. Ptr GValue -> Ptr a -> IO ()
_set_pointer Ptr a
ptr

get_pointer :: GValue -> IO (Ptr b)
get_pointer :: GValue -> IO (Ptr b)
get_pointer gv :: GValue
gv = GValue -> (Ptr GValue -> IO (Ptr b)) -> IO (Ptr b)
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr GValue
gv Ptr GValue -> IO (Ptr b)
forall b. Ptr GValue -> IO (Ptr b)
_get_pointer

foreign import ccall unsafe "g_value_set_int" _set_int ::
    Ptr GValue -> CInt -> IO ()
foreign import ccall unsafe "g_value_get_int" _get_int ::
    Ptr GValue -> IO CInt

set_int32 :: GValue -> Int32 -> IO ()
set_int32 :: GValue -> Int32 -> IO ()
set_int32 gv :: GValue
gv n :: Int32
n = GValue -> (Ptr GValue -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr GValue
gv ((Ptr GValue -> IO ()) -> IO ()) -> (Ptr GValue -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ (Ptr GValue -> CInt -> IO ()) -> CInt -> Ptr GValue -> IO ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip Ptr GValue -> CInt -> IO ()
_set_int (Int32 -> CInt
forall a b. Coercible a b => a -> b
coerce Int32
n)

get_int32 :: GValue -> IO Int32
get_int32 :: GValue -> IO Int32
get_int32 gv :: GValue
gv = CInt -> Int32
forall a b. Coercible a b => a -> b
coerce (CInt -> Int32) -> IO CInt -> IO Int32
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> GValue -> (Ptr GValue -> IO CInt) -> IO CInt
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr GValue
gv Ptr GValue -> IO CInt
_get_int

set_int :: GValue -> CInt -> IO ()
set_int :: GValue -> CInt -> IO ()
set_int gv :: GValue
gv n :: CInt
n = GValue -> (Ptr GValue -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr GValue
gv ((Ptr GValue -> IO ()) -> IO ()) -> (Ptr GValue -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ (Ptr GValue -> CInt -> IO ()) -> CInt -> Ptr GValue -> IO ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip Ptr GValue -> CInt -> IO ()
_set_int CInt
n

get_int :: GValue -> IO CInt
get_int :: GValue -> IO CInt
get_int gv :: GValue
gv = GValue -> (Ptr GValue -> IO CInt) -> IO CInt
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr GValue
gv Ptr GValue -> IO CInt
_get_int

foreign import ccall unsafe "g_value_set_uint" _set_uint ::
    Ptr GValue -> CUInt -> IO ()
foreign import ccall unsafe "g_value_get_uint" _get_uint ::
    Ptr GValue -> IO CUInt

set_uint32 :: GValue -> Word32 -> IO ()
set_uint32 :: GValue -> Word32 -> IO ()
set_uint32 gv :: GValue
gv n :: Word32
n = GValue -> (Ptr GValue -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr GValue
gv ((Ptr GValue -> IO ()) -> IO ()) -> (Ptr GValue -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ (Ptr GValue -> CUInt -> IO ()) -> CUInt -> Ptr GValue -> IO ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip Ptr GValue -> CUInt -> IO ()
_set_uint (Word32 -> CUInt
forall a b. Coercible a b => a -> b
coerce Word32
n)

get_uint32 :: GValue -> IO Word32
get_uint32 :: GValue -> IO Word32
get_uint32 gv :: GValue
gv = CUInt -> Word32
forall a b. Coercible a b => a -> b
coerce (CUInt -> Word32) -> IO CUInt -> IO Word32
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> GValue -> (Ptr GValue -> IO CUInt) -> IO CUInt
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr GValue
gv Ptr GValue -> IO CUInt
_get_uint

set_uint :: GValue -> CUInt -> IO ()
set_uint :: GValue -> CUInt -> IO ()
set_uint gv :: GValue
gv n :: CUInt
n = GValue -> (Ptr GValue -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr GValue
gv ((Ptr GValue -> IO ()) -> IO ()) -> (Ptr GValue -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ (Ptr GValue -> CUInt -> IO ()) -> CUInt -> Ptr GValue -> IO ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip Ptr GValue -> CUInt -> IO ()
_set_uint CUInt
n

get_uint :: GValue -> IO CUInt
get_uint :: GValue -> IO CUInt
get_uint gv :: GValue
gv = GValue -> (Ptr GValue -> IO CUInt) -> IO CUInt
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr GValue
gv Ptr GValue -> IO CUInt
_get_uint

foreign import ccall unsafe "g_value_set_long" _set_long ::
    Ptr GValue -> CLong -> IO ()
foreign import ccall unsafe "g_value_get_long" _get_long ::
    Ptr GValue -> IO CLong

set_long :: GValue -> CLong -> IO ()
set_long :: GValue -> CLong -> IO ()
set_long gv :: GValue
gv n :: CLong
n = GValue -> (Ptr GValue -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr GValue
gv ((Ptr GValue -> IO ()) -> IO ()) -> (Ptr GValue -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ (Ptr GValue -> CLong -> IO ()) -> CLong -> Ptr GValue -> IO ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip Ptr GValue -> CLong -> IO ()
_set_long CLong
n

get_long :: GValue -> IO CLong
get_long :: GValue -> IO CLong
get_long gv :: GValue
gv = GValue -> (Ptr GValue -> IO CLong) -> IO CLong
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr GValue
gv Ptr GValue -> IO CLong
_get_long

foreign import ccall unsafe "g_value_set_ulong" _set_ulong ::
    Ptr GValue -> CULong -> IO ()
foreign import ccall unsafe "g_value_get_ulong" _get_ulong ::
    Ptr GValue -> IO CULong

set_ulong :: GValue -> CULong -> IO ()
set_ulong :: GValue -> CULong -> IO ()
set_ulong gv :: GValue
gv n :: CULong
n = GValue -> (Ptr GValue -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr GValue
gv ((Ptr GValue -> IO ()) -> IO ()) -> (Ptr GValue -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ (Ptr GValue -> CULong -> IO ()) -> CULong -> Ptr GValue -> IO ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip Ptr GValue -> CULong -> IO ()
_set_ulong CULong
n

get_ulong :: GValue -> IO CULong
get_ulong :: GValue -> IO CULong
get_ulong gv :: GValue
gv = GValue -> (Ptr GValue -> IO CULong) -> IO CULong
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr GValue
gv Ptr GValue -> IO CULong
_get_ulong

foreign import ccall unsafe "g_value_set_int64" _set_int64 ::
    Ptr GValue -> Int64 -> IO ()
foreign import ccall unsafe "g_value_get_int64" _get_int64 ::
    Ptr GValue -> IO Int64

set_int64 :: GValue -> Int64 -> IO ()
set_int64 :: GValue -> Int64 -> IO ()
set_int64 gv :: GValue
gv n :: Int64
n = GValue -> (Ptr GValue -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr GValue
gv ((Ptr GValue -> IO ()) -> IO ()) -> (Ptr GValue -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ (Ptr GValue -> Int64 -> IO ()) -> Int64 -> Ptr GValue -> IO ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip Ptr GValue -> Int64 -> IO ()
_set_int64 Int64
n

get_int64 :: GValue -> IO Int64
get_int64 :: GValue -> IO Int64
get_int64 gv :: GValue
gv = GValue -> (Ptr GValue -> IO Int64) -> IO Int64
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr GValue
gv Ptr GValue -> IO Int64
_get_int64

foreign import ccall unsafe "g_value_set_uint64" _set_uint64 ::
    Ptr GValue -> Word64 -> IO ()
foreign import ccall unsafe "g_value_get_uint64" _get_uint64 ::
    Ptr GValue -> IO Word64

set_uint64 :: GValue -> Word64 -> IO ()
set_uint64 :: GValue -> CGType -> IO ()
set_uint64 gv :: GValue
gv n :: CGType
n = GValue -> (Ptr GValue -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr GValue
gv ((Ptr GValue -> IO ()) -> IO ()) -> (Ptr GValue -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ (Ptr GValue -> CGType -> IO ()) -> CGType -> Ptr GValue -> IO ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip Ptr GValue -> CGType -> IO ()
_set_uint64 CGType
n

get_uint64 :: GValue -> IO Word64
get_uint64 :: GValue -> IO CGType
get_uint64 gv :: GValue
gv = GValue -> (Ptr GValue -> IO CGType) -> IO CGType
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr GValue
gv Ptr GValue -> IO CGType
_get_uint64

foreign import ccall unsafe "g_value_set_float" _set_float ::
    Ptr GValue -> CFloat -> IO ()
foreign import ccall unsafe "g_value_get_float" _get_float ::
    Ptr GValue -> IO CFloat

set_float :: GValue -> Float -> IO ()
set_float :: GValue -> Float -> IO ()
set_float gv :: GValue
gv f :: Float
f = GValue -> (Ptr GValue -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr GValue
gv ((Ptr GValue -> IO ()) -> IO ()) -> (Ptr GValue -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ (Ptr GValue -> CFloat -> IO ()) -> CFloat -> Ptr GValue -> IO ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip Ptr GValue -> CFloat -> IO ()
_set_float (Float -> CFloat
forall a b. (Real a, Fractional b) => a -> b
realToFrac Float
f)

get_float :: GValue -> IO Float
get_float :: GValue -> IO Float
get_float gv :: GValue
gv = CFloat -> Float
forall a b. (Real a, Fractional b) => a -> b
realToFrac (CFloat -> Float) -> IO CFloat -> IO Float
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> GValue -> (Ptr GValue -> IO CFloat) -> IO CFloat
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr GValue
gv Ptr GValue -> IO CFloat
_get_float

foreign import ccall unsafe "g_value_set_double" _set_double ::
    Ptr GValue -> CDouble -> IO ()
foreign import ccall unsafe "g_value_get_double" _get_double ::
    Ptr GValue -> IO CDouble

set_double :: GValue -> Double -> IO ()
set_double :: GValue -> Double -> IO ()
set_double gv :: GValue
gv d :: Double
d = GValue -> (Ptr GValue -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr GValue
gv ((Ptr GValue -> IO ()) -> IO ()) -> (Ptr GValue -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ (Ptr GValue -> CDouble -> IO ()) -> CDouble -> Ptr GValue -> IO ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip Ptr GValue -> CDouble -> IO ()
_set_double (Double -> CDouble
forall a b. (Real a, Fractional b) => a -> b
realToFrac Double
d)

get_double :: GValue -> IO Double
get_double :: GValue -> IO Double
get_double gv :: GValue
gv = CDouble -> Double
forall a b. (Real a, Fractional b) => a -> b
realToFrac (CDouble -> Double) -> IO CDouble -> IO Double
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> GValue -> (Ptr GValue -> IO CDouble) -> IO CDouble
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr GValue
gv Ptr GValue -> IO CDouble
_get_double

foreign import ccall unsafe "g_value_set_boolean" _set_boolean ::
    Ptr GValue -> CInt -> IO ()
foreign import ccall unsafe "g_value_get_boolean" _get_boolean ::
    Ptr GValue -> IO CInt

set_boolean :: GValue -> Bool -> IO ()
set_boolean :: GValue -> Bool -> IO ()
set_boolean gv :: GValue
gv b :: Bool
b = GValue -> (Ptr GValue -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr GValue
gv ((Ptr GValue -> IO ()) -> IO ()) -> (Ptr GValue -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \ptr :: Ptr GValue
ptr ->
                   Ptr GValue -> CInt -> IO ()
_set_boolean Ptr GValue
ptr (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> CInt) -> Int -> CInt
forall a b. (a -> b) -> a -> b
$ Bool -> Int
forall a. Enum a => a -> Int
fromEnum Bool
b)

get_boolean :: GValue -> IO Bool
get_boolean :: GValue -> IO Bool
get_boolean gv :: GValue
gv = GValue -> (Ptr GValue -> IO Bool) -> IO Bool
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr GValue
gv ((Ptr GValue -> IO Bool) -> IO Bool)
-> (Ptr GValue -> IO Bool) -> IO Bool
forall a b. (a -> b) -> a -> b
$ \ptr :: Ptr GValue
ptr -> (CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
/= 0) (CInt -> Bool) -> IO CInt -> IO Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ptr GValue -> IO CInt
_get_boolean Ptr GValue
ptr

foreign import ccall unsafe "g_value_set_gtype" _set_gtype ::
    Ptr GValue -> CGType -> IO ()
foreign import ccall unsafe "g_value_get_gtype" _get_gtype ::
    Ptr GValue -> IO CGType

set_gtype :: GValue -> GType -> IO ()
set_gtype :: GValue -> GType -> IO ()
set_gtype gv :: GValue
gv (GType g :: CGType
g) = GValue -> (Ptr GValue -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr GValue
gv ((Ptr GValue -> IO ()) -> IO ()) -> (Ptr GValue -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \ptr :: Ptr GValue
ptr -> Ptr GValue -> CGType -> IO ()
_set_gtype Ptr GValue
ptr CGType
g

get_gtype :: GValue -> IO GType
get_gtype :: GValue -> IO GType
get_gtype gv :: GValue
gv = CGType -> GType
GType (CGType -> GType) -> IO CGType -> IO GType
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> GValue -> (Ptr GValue -> IO CGType) -> IO CGType
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr GValue
gv Ptr GValue -> IO CGType
_get_gtype

foreign import ccall "g_value_set_object" _set_object ::
    Ptr GValue -> Ptr a -> IO ()
foreign import ccall "g_value_get_object" _get_object ::
    Ptr GValue -> IO (Ptr a)

set_object :: GObject a => GValue -> Ptr a -> IO ()
set_object :: GValue -> Ptr a -> IO ()
set_object gv :: GValue
gv o :: Ptr a
o = GValue -> (Ptr GValue -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr GValue
gv ((Ptr GValue -> IO ()) -> IO ()) -> (Ptr GValue -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ (Ptr GValue -> Ptr a -> IO ()) -> Ptr a -> Ptr GValue -> IO ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip Ptr GValue -> Ptr a -> IO ()
forall a. Ptr GValue -> Ptr a -> IO ()
_set_object Ptr a
o

get_object :: GObject b => GValue -> IO (Ptr b)
get_object :: GValue -> IO (Ptr b)
get_object gv :: GValue
gv = GValue -> (Ptr GValue -> IO (Ptr b)) -> IO (Ptr b)
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr GValue
gv Ptr GValue -> IO (Ptr b)
forall b. Ptr GValue -> IO (Ptr b)
_get_object

foreign import ccall "g_value_set_boxed" _set_boxed ::
    Ptr GValue -> Ptr a -> IO ()
foreign import ccall "g_value_get_boxed" _get_boxed ::
    Ptr GValue -> IO (Ptr b)

set_boxed :: GValue -> Ptr a -> IO ()
set_boxed :: GValue -> Ptr a -> IO ()
set_boxed gv :: GValue
gv b :: Ptr a
b = GValue -> (Ptr GValue -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr GValue
gv ((Ptr GValue -> IO ()) -> IO ()) -> (Ptr GValue -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ (Ptr GValue -> Ptr a -> IO ()) -> Ptr a -> Ptr GValue -> IO ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip Ptr GValue -> Ptr a -> IO ()
forall a. Ptr GValue -> Ptr a -> IO ()
_set_boxed Ptr a
b

get_boxed :: GValue -> IO (Ptr b)
get_boxed :: GValue -> IO (Ptr b)
get_boxed gv :: GValue
gv = GValue -> (Ptr GValue -> IO (Ptr b)) -> IO (Ptr b)
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr GValue
gv Ptr GValue -> IO (Ptr b)
forall b. Ptr GValue -> IO (Ptr b)
_get_boxed

foreign import ccall "g_value_set_variant" _set_variant ::
    Ptr GValue -> Ptr GVariant -> IO ()
foreign import ccall "g_value_get_variant" _get_variant ::
    Ptr GValue -> IO (Ptr GVariant)

set_variant :: GValue -> Ptr GVariant -> IO ()
set_variant :: GValue -> Ptr GVariant -> IO ()
set_variant gv :: GValue
gv v :: Ptr GVariant
v = GValue -> (Ptr GValue -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr GValue
gv ((Ptr GValue -> IO ()) -> IO ()) -> (Ptr GValue -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ (Ptr GValue -> Ptr GVariant -> IO ())
-> Ptr GVariant -> Ptr GValue -> IO ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip Ptr GValue -> Ptr GVariant -> IO ()
_set_variant Ptr GVariant
v

get_variant :: GValue -> IO (Ptr GVariant)
get_variant :: GValue -> IO (Ptr GVariant)
get_variant gv :: GValue
gv = GValue -> (Ptr GValue -> IO (Ptr GVariant)) -> IO (Ptr GVariant)
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr GValue
gv Ptr GValue -> IO (Ptr GVariant)
_get_variant

foreign import ccall unsafe "g_value_set_enum" _set_enum ::
    Ptr GValue -> CUInt -> IO ()
foreign import ccall unsafe "g_value_get_enum" _get_enum ::
    Ptr GValue -> IO CUInt

set_enum :: GValue -> CUInt -> IO ()
set_enum :: GValue -> CUInt -> IO ()
set_enum gv :: GValue
gv e :: CUInt
e = GValue -> (Ptr GValue -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr GValue
gv ((Ptr GValue -> IO ()) -> IO ()) -> (Ptr GValue -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ (Ptr GValue -> CUInt -> IO ()) -> CUInt -> Ptr GValue -> IO ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip Ptr GValue -> CUInt -> IO ()
_set_enum CUInt
e

get_enum :: GValue -> IO CUInt
get_enum :: GValue -> IO CUInt
get_enum gv :: GValue
gv = GValue -> (Ptr GValue -> IO CUInt) -> IO CUInt
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr GValue
gv Ptr GValue -> IO CUInt
_get_enum

foreign import ccall unsafe "g_value_set_flags" _set_flags ::
    Ptr GValue -> CUInt -> IO ()
foreign import ccall unsafe "g_value_get_flags" _get_flags ::
    Ptr GValue -> IO CUInt

set_flags :: GValue -> CUInt -> IO ()
set_flags :: GValue -> CUInt -> IO ()
set_flags gv :: GValue
gv f :: CUInt
f = GValue -> (Ptr GValue -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr GValue
gv ((Ptr GValue -> IO ()) -> IO ()) -> (Ptr GValue -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ (Ptr GValue -> CUInt -> IO ()) -> CUInt -> Ptr GValue -> IO ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip Ptr GValue -> CUInt -> IO ()
_set_flags CUInt
f

get_flags :: GValue -> IO CUInt
get_flags :: GValue -> IO CUInt
get_flags gv :: GValue
gv = GValue -> (Ptr GValue -> IO CUInt) -> IO CUInt
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr GValue
gv Ptr GValue -> IO CUInt
_get_flags

-- | Set the value of `GValue` containing a `StablePtr`
set_stablePtr :: GValue -> StablePtr a -> IO ()
set_stablePtr :: GValue -> StablePtr a -> IO ()
set_stablePtr gv :: GValue
gv ptr :: StablePtr a
ptr = GValue -> (Ptr GValue -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr GValue
gv ((Ptr GValue -> IO ()) -> IO ()) -> (Ptr GValue -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ (Ptr GValue -> Ptr () -> IO ()) -> Ptr () -> Ptr GValue -> IO ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip Ptr GValue -> Ptr () -> IO ()
forall a. Ptr GValue -> Ptr a -> IO ()
_set_boxed (StablePtr a -> Ptr ()
forall a. StablePtr a -> Ptr ()
castStablePtrToPtr StablePtr a
ptr)

foreign import ccall g_value_take_boxed :: Ptr GValue -> StablePtr a -> IO ()

-- | Like `set_stablePtr`, but the `GValue` takes ownership of the `StablePtr`
take_stablePtr :: Ptr GValue -> StablePtr a -> IO ()
take_stablePtr :: Ptr GValue -> StablePtr a -> IO ()
take_stablePtr = Ptr GValue -> StablePtr a -> IO ()
forall a. Ptr GValue -> StablePtr a -> IO ()
g_value_take_boxed

-- | Get the value of a `GValue` containing a `StablePtr`
get_stablePtr :: GValue -> IO (StablePtr a)
get_stablePtr :: GValue -> IO (StablePtr a)
get_stablePtr gv :: GValue
gv = Ptr () -> StablePtr a
forall a. Ptr () -> StablePtr a
castPtrToStablePtr (Ptr () -> StablePtr a) -> IO (Ptr ()) -> IO (StablePtr a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> GValue -> (Ptr GValue -> IO (Ptr ())) -> IO (Ptr ())
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr GValue
gv Ptr GValue -> IO (Ptr ())
forall b. Ptr GValue -> IO (Ptr b)
_get_boxed