#define ENABLE_OVERLOADING (MIN_VERSION_haskell_gi_overloading(1,0,0) \
&& !defined(__HADDOCK_VERSION__))
module GI.GObject.Structs.Parameter
(
Parameter(..) ,
newZeroParameter ,
noParameter ,
clearParameterName ,
getParameterName ,
#if ENABLE_OVERLOADING
parameter_name ,
#endif
setParameterName ,
getParameterValue ,
#if ENABLE_OVERLOADING
parameter_value ,
#endif
) where
import Data.GI.Base.ShortPrelude
import qualified Data.GI.Base.ShortPrelude as SP
import qualified Data.GI.Base.Overloading as O
import qualified Prelude as P
import qualified Data.GI.Base.Attributes as GI.Attributes
import qualified Data.GI.Base.ManagedPtr as B.ManagedPtr
import qualified Data.GI.Base.GError as B.GError
import qualified Data.GI.Base.GVariant as B.GVariant
import qualified Data.GI.Base.GValue as B.GValue
import qualified Data.GI.Base.GParamSpec as B.GParamSpec
import qualified Data.GI.Base.CallStack as B.CallStack
import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map
import qualified Foreign.Ptr as FP
newtype Parameter = Parameter (ManagedPtr Parameter)
instance WrappedPtr Parameter where
wrappedPtrCalloc = callocBytes 32
wrappedPtrCopy = \p -> withManagedPtr p (copyBytes 32 >=> wrapPtr Parameter)
wrappedPtrFree = Just ptr_to_g_free
newZeroParameter :: MonadIO m => m Parameter
newZeroParameter = liftIO $ wrappedPtrCalloc >>= wrapPtr Parameter
instance tag ~ 'AttrSet => Constructible Parameter tag where
new _ attrs = do
o <- newZeroParameter
GI.Attributes.set o attrs
return o
noParameter :: Maybe Parameter
noParameter = Nothing
getParameterName :: MonadIO m => Parameter -> m (Maybe T.Text)
getParameterName s = liftIO $ withManagedPtr s $ \ptr -> do
val <- peek (ptr `plusPtr` 0) :: IO CString
result <- SP.convertIfNonNull val $ \val' -> do
val'' <- cstringToText val'
return val''
return result
setParameterName :: MonadIO m => Parameter -> CString -> m ()
setParameterName s val = liftIO $ withManagedPtr s $ \ptr -> do
poke (ptr `plusPtr` 0) (val :: CString)
clearParameterName :: MonadIO m => Parameter -> m ()
clearParameterName s = liftIO $ withManagedPtr s $ \ptr -> do
poke (ptr `plusPtr` 0) (FP.nullPtr :: CString)
#if ENABLE_OVERLOADING
data ParameterNameFieldInfo
instance AttrInfo ParameterNameFieldInfo where
type AttrAllowedOps ParameterNameFieldInfo = '[ 'AttrSet, 'AttrGet, 'AttrClear]
type AttrSetTypeConstraint ParameterNameFieldInfo = (~) CString
type AttrBaseTypeConstraint ParameterNameFieldInfo = (~) Parameter
type AttrGetType ParameterNameFieldInfo = Maybe T.Text
type AttrLabel ParameterNameFieldInfo = "name"
type AttrOrigin ParameterNameFieldInfo = Parameter
attrGet _ = getParameterName
attrSet _ = setParameterName
attrConstruct = undefined
attrClear _ = clearParameterName
parameter_name :: AttrLabelProxy "name"
parameter_name = AttrLabelProxy
#endif
getParameterValue :: MonadIO m => Parameter -> m GValue
getParameterValue s = liftIO $ withManagedPtr s $ \ptr -> do
let val = ptr `plusPtr` 8 :: (Ptr GValue)
val' <- (newBoxed GValue) val
return val'
#if ENABLE_OVERLOADING
data ParameterValueFieldInfo
instance AttrInfo ParameterValueFieldInfo where
type AttrAllowedOps ParameterValueFieldInfo = '[ 'AttrGet]
type AttrSetTypeConstraint ParameterValueFieldInfo = (~) (Ptr GValue)
type AttrBaseTypeConstraint ParameterValueFieldInfo = (~) Parameter
type AttrGetType ParameterValueFieldInfo = GValue
type AttrLabel ParameterValueFieldInfo = "value"
type AttrOrigin ParameterValueFieldInfo = Parameter
attrGet _ = getParameterValue
attrSet _ = undefined
attrConstruct = undefined
attrClear _ = undefined
parameter_value :: AttrLabelProxy "value"
parameter_value = AttrLabelProxy
#endif
#if ENABLE_OVERLOADING
instance O.HasAttributeList Parameter
type instance O.AttributeList Parameter = ParameterAttributeList
type ParameterAttributeList = ('[ '("name", ParameterNameFieldInfo), '("value", ParameterValueFieldInfo)] :: [(Symbol, *)])
#endif
#if ENABLE_OVERLOADING
type family ResolveParameterMethod (t :: Symbol) (o :: *) :: * where
ResolveParameterMethod l o = O.MethodResolutionFailed l o
instance (info ~ ResolveParameterMethod t Parameter, O.MethodInfo info Parameter p) => O.IsLabelProxy t (Parameter -> p) where
fromLabelProxy _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#if MIN_VERSION_base(4,9,0)
instance (info ~ ResolveParameterMethod t Parameter, O.MethodInfo info Parameter p) => O.IsLabel t (Parameter -> p) where
#if MIN_VERSION_base(4,10,0)
fromLabel = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#else
fromLabel _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#endif
#endif
#endif