{-# LANGUAGE TypeApplications #-}


-- | Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
-- License    : LGPL-2.1
-- Maintainer : Iñaki García Etxebarria
-- 
-- The t'GI.Pango.Structs.AttrInt.AttrInt' structure is used to represent attributes with
-- an integer or enumeration value.

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

module GI.Pango.Structs.AttrInt
    ( 

-- * Exported types
    AttrInt(..)                             ,
    newZeroAttrInt                          ,


 -- * Methods
-- ** Overloaded methods #method:Overloaded methods#

#if defined(ENABLE_OVERLOADING)
    ResolveAttrIntMethod                    ,
#endif




 -- * Properties
-- ** attr #attr:attr#
-- | the common portion of the attribute

#if defined(ENABLE_OVERLOADING)
    attrInt_attr                            ,
#endif
    getAttrIntAttr                          ,


-- ** value #attr:value#
-- | the value of the attribute

#if defined(ENABLE_OVERLOADING)
    attrInt_value                           ,
#endif
    getAttrIntValue                         ,
    setAttrIntValue                         ,




    ) 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.BasicTypes as B.Types
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.GI.Base.Signals as B.Signals
import qualified Control.Monad.IO.Class as MIO
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.Pango.Structs.Attribute as Pango.Attribute

-- | Memory-managed wrapper type.
newtype AttrInt = AttrInt (SP.ManagedPtr AttrInt)
    deriving (AttrInt -> AttrInt -> Bool
(AttrInt -> AttrInt -> Bool)
-> (AttrInt -> AttrInt -> Bool) -> Eq AttrInt
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AttrInt -> AttrInt -> Bool
$c/= :: AttrInt -> AttrInt -> Bool
== :: AttrInt -> AttrInt -> Bool
$c== :: AttrInt -> AttrInt -> Bool
Eq)

instance SP.ManagedPtrNewtype AttrInt where
    toManagedPtr :: AttrInt -> ManagedPtr AttrInt
toManagedPtr (AttrInt ManagedPtr AttrInt
p) = ManagedPtr AttrInt
p

instance BoxedPtr AttrInt where
    boxedPtrCopy :: AttrInt -> IO AttrInt
boxedPtrCopy = \AttrInt
p -> AttrInt -> (Ptr AttrInt -> IO AttrInt) -> IO AttrInt
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
B.ManagedPtr.withManagedPtr AttrInt
p (Int -> Ptr AttrInt -> IO (Ptr AttrInt)
forall a. (HasCallStack, CallocPtr a) => Int -> Ptr a -> IO (Ptr a)
copyBytes Int
24 (Ptr AttrInt -> IO (Ptr AttrInt))
-> (Ptr AttrInt -> IO AttrInt) -> Ptr AttrInt -> IO AttrInt
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> (ManagedPtr AttrInt -> AttrInt) -> Ptr AttrInt -> IO AttrInt
forall a.
(HasCallStack, BoxedPtr a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
B.ManagedPtr.wrapPtr ManagedPtr AttrInt -> AttrInt
AttrInt)
    boxedPtrFree :: AttrInt -> IO ()
boxedPtrFree = \AttrInt
x -> AttrInt -> (Ptr AttrInt -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
SP.withManagedPtr AttrInt
x Ptr AttrInt -> IO ()
forall a. Ptr a -> IO ()
SP.freeMem
instance CallocPtr AttrInt where
    boxedPtrCalloc :: IO (Ptr AttrInt)
boxedPtrCalloc = Int -> IO (Ptr AttrInt)
forall a. Int -> IO (Ptr a)
callocBytes Int
24


-- | Construct a `AttrInt` struct initialized to zero.
newZeroAttrInt :: MonadIO m => m AttrInt
newZeroAttrInt :: m AttrInt
newZeroAttrInt = IO AttrInt -> m AttrInt
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO AttrInt -> m AttrInt) -> IO AttrInt -> m AttrInt
forall a b. (a -> b) -> a -> b
$ IO (Ptr AttrInt)
forall a. CallocPtr a => IO (Ptr a)
boxedPtrCalloc IO (Ptr AttrInt) -> (Ptr AttrInt -> IO AttrInt) -> IO AttrInt
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (ManagedPtr AttrInt -> AttrInt) -> Ptr AttrInt -> IO AttrInt
forall a.
(HasCallStack, BoxedPtr a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
wrapPtr ManagedPtr AttrInt -> AttrInt
AttrInt

instance tag ~ 'AttrSet => Constructible AttrInt tag where
    new :: (ManagedPtr AttrInt -> AttrInt)
-> [AttrOp AttrInt tag] -> m AttrInt
new ManagedPtr AttrInt -> AttrInt
_ [AttrOp AttrInt tag]
attrs = do
        AttrInt
o <- m AttrInt
forall (m :: * -> *). MonadIO m => m AttrInt
newZeroAttrInt
        AttrInt -> [AttrOp AttrInt 'AttrSet] -> m ()
forall o (m :: * -> *).
MonadIO m =>
o -> [AttrOp o 'AttrSet] -> m ()
GI.Attributes.set AttrInt
o [AttrOp AttrInt tag]
[AttrOp AttrInt 'AttrSet]
attrs
        AttrInt -> m AttrInt
forall (m :: * -> *) a. Monad m => a -> m a
return AttrInt
o


-- | Get the value of the “@attr@” field.
-- When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to
-- 
-- @
-- 'Data.GI.Base.Attributes.get' attrInt #attr
-- @
getAttrIntAttr :: MonadIO m => AttrInt -> m Pango.Attribute.Attribute
getAttrIntAttr :: AttrInt -> m Attribute
getAttrIntAttr AttrInt
s = IO Attribute -> m Attribute
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Attribute -> m Attribute) -> IO Attribute -> m Attribute
forall a b. (a -> b) -> a -> b
$ AttrInt -> (Ptr AttrInt -> IO Attribute) -> IO Attribute
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr AttrInt
s ((Ptr AttrInt -> IO Attribute) -> IO Attribute)
-> (Ptr AttrInt -> IO Attribute) -> IO Attribute
forall a b. (a -> b) -> a -> b
$ \Ptr AttrInt
ptr -> do
    let val :: Ptr Attribute
val = Ptr AttrInt
ptr Ptr AttrInt -> Int -> Ptr Attribute
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
0 :: (Ptr Pango.Attribute.Attribute)
    Attribute
val' <- ((ManagedPtr Attribute -> Attribute)
-> Ptr Attribute -> IO Attribute
forall a.
(HasCallStack, GBoxed a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
newBoxed ManagedPtr Attribute -> Attribute
Pango.Attribute.Attribute) Ptr Attribute
val
    Attribute -> IO Attribute
forall (m :: * -> *) a. Monad m => a -> m a
return Attribute
val'

#if defined(ENABLE_OVERLOADING)
data AttrIntAttrFieldInfo
instance AttrInfo AttrIntAttrFieldInfo where
    type AttrBaseTypeConstraint AttrIntAttrFieldInfo = (~) AttrInt
    type AttrAllowedOps AttrIntAttrFieldInfo = '[ 'AttrGet]
    type AttrSetTypeConstraint AttrIntAttrFieldInfo = (~) (Ptr Pango.Attribute.Attribute)
    type AttrTransferTypeConstraint AttrIntAttrFieldInfo = (~)(Ptr Pango.Attribute.Attribute)
    type AttrTransferType AttrIntAttrFieldInfo = (Ptr Pango.Attribute.Attribute)
    type AttrGetType AttrIntAttrFieldInfo = Pango.Attribute.Attribute
    type AttrLabel AttrIntAttrFieldInfo = "attr"
    type AttrOrigin AttrIntAttrFieldInfo = AttrInt
    attrGet = getAttrIntAttr
    attrSet = undefined
    attrConstruct = undefined
    attrClear = undefined
    attrTransfer = undefined

attrInt_attr :: AttrLabelProxy "attr"
attrInt_attr = AttrLabelProxy

#endif


-- | Get the value of the “@value@” field.
-- When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to
-- 
-- @
-- 'Data.GI.Base.Attributes.get' attrInt #value
-- @
getAttrIntValue :: MonadIO m => AttrInt -> m Int32
getAttrIntValue :: AttrInt -> m Int32
getAttrIntValue AttrInt
s = IO Int32 -> m Int32
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Int32 -> m Int32) -> IO Int32 -> m Int32
forall a b. (a -> b) -> a -> b
$ AttrInt -> (Ptr AttrInt -> IO Int32) -> IO Int32
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr AttrInt
s ((Ptr AttrInt -> IO Int32) -> IO Int32)
-> (Ptr AttrInt -> IO Int32) -> IO Int32
forall a b. (a -> b) -> a -> b
$ \Ptr AttrInt
ptr -> do
    Int32
val <- Ptr Int32 -> IO Int32
forall a. Storable a => Ptr a -> IO a
peek (Ptr AttrInt
ptr Ptr AttrInt -> Int -> Ptr Int32
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
16) :: IO Int32
    Int32 -> IO Int32
forall (m :: * -> *) a. Monad m => a -> m a
return Int32
val

-- | Set the value of the “@value@” field.
-- When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to
-- 
-- @
-- 'Data.GI.Base.Attributes.set' attrInt [ #value 'Data.GI.Base.Attributes.:=' value ]
-- @
setAttrIntValue :: MonadIO m => AttrInt -> Int32 -> m ()
setAttrIntValue :: AttrInt -> Int32 -> m ()
setAttrIntValue AttrInt
s Int32
val = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ AttrInt -> (Ptr AttrInt -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr AttrInt
s ((Ptr AttrInt -> IO ()) -> IO ())
-> (Ptr AttrInt -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr AttrInt
ptr -> do
    Ptr Int32 -> Int32 -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (Ptr AttrInt
ptr Ptr AttrInt -> Int -> Ptr Int32
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
16) (Int32
val :: Int32)

#if defined(ENABLE_OVERLOADING)
data AttrIntValueFieldInfo
instance AttrInfo AttrIntValueFieldInfo where
    type AttrBaseTypeConstraint AttrIntValueFieldInfo = (~) AttrInt
    type AttrAllowedOps AttrIntValueFieldInfo = '[ 'AttrSet, 'AttrGet]
    type AttrSetTypeConstraint AttrIntValueFieldInfo = (~) Int32
    type AttrTransferTypeConstraint AttrIntValueFieldInfo = (~)Int32
    type AttrTransferType AttrIntValueFieldInfo = Int32
    type AttrGetType AttrIntValueFieldInfo = Int32
    type AttrLabel AttrIntValueFieldInfo = "value"
    type AttrOrigin AttrIntValueFieldInfo = AttrInt
    attrGet = getAttrIntValue
    attrSet = setAttrIntValue
    attrConstruct = undefined
    attrClear = undefined
    attrTransfer _ v = do
        return v

attrInt_value :: AttrLabelProxy "value"
attrInt_value = AttrLabelProxy

#endif



#if defined(ENABLE_OVERLOADING)
instance O.HasAttributeList AttrInt
type instance O.AttributeList AttrInt = AttrIntAttributeList
type AttrIntAttributeList = ('[ '("attr", AttrIntAttrFieldInfo), '("value", AttrIntValueFieldInfo)] :: [(Symbol, *)])
#endif

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

instance (info ~ ResolveAttrIntMethod t AttrInt, O.MethodInfo info AttrInt p) => OL.IsLabel t (AttrInt -> p) where
#if MIN_VERSION_base(4,10,0)
    fromLabel = O.overloadedMethod @info
#else
    fromLabel _ = O.overloadedMethod @info
#endif

#endif