{- |
Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
License    : LGPL-2.1
Maintainer : Iñaki García Etxebarria (inaki@blueleaf.cc)

The class of a flags type holds information about its
possible values.
-}

#define ENABLE_OVERLOADING (MIN_VERSION_haskell_gi_overloading(1,0,0) \
       && !defined(__HADDOCK_VERSION__))

module GI.GObject.Structs.FlagsClass
    (

-- * Exported types
    FlagsClass(..)                          ,
    newZeroFlagsClass                       ,
    noFlagsClass                            ,


 -- * Properties
-- ** gTypeClass #attr:gTypeClass#
{- | the parent class
-}
#if ENABLE_OVERLOADING
    flagsClass_gTypeClass                   ,
#endif
    getFlagsClassGTypeClass                 ,


-- ** mask #attr:mask#
{- | a mask covering all possible values.
-}
#if ENABLE_OVERLOADING
    flagsClass_mask                         ,
#endif
    getFlagsClassMask                       ,
    setFlagsClassMask                       ,


-- ** nValues #attr:nValues#
{- | the number of possible values.
-}
#if ENABLE_OVERLOADING
    flagsClass_nValues                      ,
#endif
    getFlagsClassNValues                    ,
    setFlagsClassNValues                    ,


-- ** values #attr:values#
{- | an array of 'GI.GObject.Structs.FlagsValue.FlagsValue' structs describing the
 individual values.
-}
    clearFlagsClassValues                   ,
#if ENABLE_OVERLOADING
    flagsClass_values                       ,
#endif
    getFlagsClassValues                     ,
    setFlagsClassValues                     ,




    ) 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.GClosure as B.GClosure
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.GI.Base.Properties as B.Properties
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
import qualified GHC.OverloadedLabels as OL

import {-# SOURCE #-} qualified GI.GObject.Structs.FlagsValue as GObject.FlagsValue
import {-# SOURCE #-} qualified GI.GObject.Structs.TypeClass as GObject.TypeClass

-- | Memory-managed wrapper type.
newtype FlagsClass = FlagsClass (ManagedPtr FlagsClass)
instance WrappedPtr FlagsClass where
    wrappedPtrCalloc = callocBytes 24
    wrappedPtrCopy = \p -> withManagedPtr p (copyBytes 24 >=> wrapPtr FlagsClass)
    wrappedPtrFree = Just ptr_to_g_free

-- | Construct a `FlagsClass` struct initialized to zero.
newZeroFlagsClass :: MonadIO m => m FlagsClass
newZeroFlagsClass = liftIO $ wrappedPtrCalloc >>= wrapPtr FlagsClass

instance tag ~ 'AttrSet => Constructible FlagsClass tag where
    new _ attrs = do
        o <- newZeroFlagsClass
        GI.Attributes.set o attrs
        return o


-- | A convenience alias for `Nothing` :: `Maybe` `FlagsClass`.
noFlagsClass :: Maybe FlagsClass
noFlagsClass = Nothing

{- |
Get the value of the “@g_type_class@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.get' flagsClass #gTypeClass
@
-}
getFlagsClassGTypeClass :: MonadIO m => FlagsClass -> m GObject.TypeClass.TypeClass
getFlagsClassGTypeClass s = liftIO $ withManagedPtr s $ \ptr -> do
    let val = ptr `plusPtr` 0 :: (Ptr GObject.TypeClass.TypeClass)
    val' <- (newPtr GObject.TypeClass.TypeClass) val
    return val'

#if ENABLE_OVERLOADING
data FlagsClassGTypeClassFieldInfo
instance AttrInfo FlagsClassGTypeClassFieldInfo where
    type AttrAllowedOps FlagsClassGTypeClassFieldInfo = '[ 'AttrGet]
    type AttrSetTypeConstraint FlagsClassGTypeClassFieldInfo = (~) (Ptr GObject.TypeClass.TypeClass)
    type AttrBaseTypeConstraint FlagsClassGTypeClassFieldInfo = (~) FlagsClass
    type AttrGetType FlagsClassGTypeClassFieldInfo = GObject.TypeClass.TypeClass
    type AttrLabel FlagsClassGTypeClassFieldInfo = "g_type_class"
    type AttrOrigin FlagsClassGTypeClassFieldInfo = FlagsClass
    attrGet _ = getFlagsClassGTypeClass
    attrSet _ = undefined
    attrConstruct = undefined
    attrClear _ = undefined

flagsClass_gTypeClass :: AttrLabelProxy "gTypeClass"
flagsClass_gTypeClass = AttrLabelProxy

#endif


{- |
Get the value of the “@mask@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.get' flagsClass #mask
@
-}
getFlagsClassMask :: MonadIO m => FlagsClass -> m Word32
getFlagsClassMask s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 8) :: IO Word32
    return val

{- |
Set the value of the “@mask@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.set' flagsClass [ #mask 'Data.GI.Base.Attributes.:=' value ]
@
-}
setFlagsClassMask :: MonadIO m => FlagsClass -> Word32 -> m ()
setFlagsClassMask s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 8) (val :: Word32)

#if ENABLE_OVERLOADING
data FlagsClassMaskFieldInfo
instance AttrInfo FlagsClassMaskFieldInfo where
    type AttrAllowedOps FlagsClassMaskFieldInfo = '[ 'AttrSet, 'AttrGet]
    type AttrSetTypeConstraint FlagsClassMaskFieldInfo = (~) Word32
    type AttrBaseTypeConstraint FlagsClassMaskFieldInfo = (~) FlagsClass
    type AttrGetType FlagsClassMaskFieldInfo = Word32
    type AttrLabel FlagsClassMaskFieldInfo = "mask"
    type AttrOrigin FlagsClassMaskFieldInfo = FlagsClass
    attrGet _ = getFlagsClassMask
    attrSet _ = setFlagsClassMask
    attrConstruct = undefined
    attrClear _ = undefined

flagsClass_mask :: AttrLabelProxy "mask"
flagsClass_mask = AttrLabelProxy

#endif


{- |
Get the value of the “@n_values@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.get' flagsClass #nValues
@
-}
getFlagsClassNValues :: MonadIO m => FlagsClass -> m Word32
getFlagsClassNValues s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 12) :: IO Word32
    return val

{- |
Set the value of the “@n_values@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.set' flagsClass [ #nValues 'Data.GI.Base.Attributes.:=' value ]
@
-}
setFlagsClassNValues :: MonadIO m => FlagsClass -> Word32 -> m ()
setFlagsClassNValues s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 12) (val :: Word32)

#if ENABLE_OVERLOADING
data FlagsClassNValuesFieldInfo
instance AttrInfo FlagsClassNValuesFieldInfo where
    type AttrAllowedOps FlagsClassNValuesFieldInfo = '[ 'AttrSet, 'AttrGet]
    type AttrSetTypeConstraint FlagsClassNValuesFieldInfo = (~) Word32
    type AttrBaseTypeConstraint FlagsClassNValuesFieldInfo = (~) FlagsClass
    type AttrGetType FlagsClassNValuesFieldInfo = Word32
    type AttrLabel FlagsClassNValuesFieldInfo = "n_values"
    type AttrOrigin FlagsClassNValuesFieldInfo = FlagsClass
    attrGet _ = getFlagsClassNValues
    attrSet _ = setFlagsClassNValues
    attrConstruct = undefined
    attrClear _ = undefined

flagsClass_nValues :: AttrLabelProxy "nValues"
flagsClass_nValues = AttrLabelProxy

#endif


{- |
Get the value of the “@values@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.get' flagsClass #values
@
-}
getFlagsClassValues :: MonadIO m => FlagsClass -> m (Maybe GObject.FlagsValue.FlagsValue)
getFlagsClassValues s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 16) :: IO (Ptr GObject.FlagsValue.FlagsValue)
    result <- SP.convertIfNonNull val $ \val' -> do
        val'' <- (newPtr GObject.FlagsValue.FlagsValue) val'
        return val''
    return result

{- |
Set the value of the “@values@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.set' flagsClass [ #values 'Data.GI.Base.Attributes.:=' value ]
@
-}
setFlagsClassValues :: MonadIO m => FlagsClass -> Ptr GObject.FlagsValue.FlagsValue -> m ()
setFlagsClassValues s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 16) (val :: Ptr GObject.FlagsValue.FlagsValue)

{- |
Set the value of the “@values@” field to `Nothing`.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.clear' #values
@
-}
clearFlagsClassValues :: MonadIO m => FlagsClass -> m ()
clearFlagsClassValues s = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 16) (FP.nullPtr :: Ptr GObject.FlagsValue.FlagsValue)

#if ENABLE_OVERLOADING
data FlagsClassValuesFieldInfo
instance AttrInfo FlagsClassValuesFieldInfo where
    type AttrAllowedOps FlagsClassValuesFieldInfo = '[ 'AttrSet, 'AttrGet, 'AttrClear]
    type AttrSetTypeConstraint FlagsClassValuesFieldInfo = (~) (Ptr GObject.FlagsValue.FlagsValue)
    type AttrBaseTypeConstraint FlagsClassValuesFieldInfo = (~) FlagsClass
    type AttrGetType FlagsClassValuesFieldInfo = Maybe GObject.FlagsValue.FlagsValue
    type AttrLabel FlagsClassValuesFieldInfo = "values"
    type AttrOrigin FlagsClassValuesFieldInfo = FlagsClass
    attrGet _ = getFlagsClassValues
    attrSet _ = setFlagsClassValues
    attrConstruct = undefined
    attrClear _ = clearFlagsClassValues

flagsClass_values :: AttrLabelProxy "values"
flagsClass_values = AttrLabelProxy

#endif



#if ENABLE_OVERLOADING
instance O.HasAttributeList FlagsClass
type instance O.AttributeList FlagsClass = FlagsClassAttributeList
type FlagsClassAttributeList = ('[ '("gTypeClass", FlagsClassGTypeClassFieldInfo), '("mask", FlagsClassMaskFieldInfo), '("nValues", FlagsClassNValuesFieldInfo), '("values", FlagsClassValuesFieldInfo)] :: [(Symbol, *)])
#endif

#if ENABLE_OVERLOADING
type family ResolveFlagsClassMethod (t :: Symbol) (o :: *) :: * where
    ResolveFlagsClassMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveFlagsClassMethod t FlagsClass, O.MethodInfo info FlagsClass p) => OL.IsLabel t (FlagsClass -> 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