    {-# 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.AttrString.AttrString' structure is used to represent attributes with
    -- a string value.

    #if !defined(__HADDOCK_VERSION__)
    #define ENABLE_OVERLOADING
    #endif

    module GI.Pango.Structs.AttrString
        (

    -- * Exported types
        AttrString(..)                          ,
        newZeroAttrString                       ,

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

    #if defined(ENABLE_OVERLOADING)
        ResolveAttrStringMethod                 ,
    #endif

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

    #if defined(ENABLE_OVERLOADING)
        attrString_attr                         ,
    #endif
        getAttrStringAttr                       ,

    -- ** value #attr:value#
    -- | the string which is the value of the attribute

    #if defined(ENABLE_OVERLOADING)
        attrString_value                        ,
    #endif
        clearAttrStringValue                    ,
        getAttrStringValue                      ,
        setAttrStringValue                      ,

        ) 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.GArray as B.GArray
    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 AttrString = AttrString (SP.ManagedPtr AttrString)
        deriving (AttrString -> AttrString -> Bool
    (AttrString -> AttrString -> Bool)
    -> (AttrString -> AttrString -> Bool) -> Eq AttrString
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    /= :: AttrString -> AttrString -> Bool
    $c/= :: AttrString -> AttrString -> Bool
    == :: AttrString -> AttrString -> Bool
    $c== :: AttrString -> AttrString -> Bool
    Eq)

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

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

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

    instance tag ~ 'AttrSet => Constructible AttrString tag where
        new :: (ManagedPtr AttrString -> AttrString)
    -> [AttrOp AttrString tag] -> m AttrString
    new _ attrs :: [AttrOp AttrString tag]
    attrs = do
            AttrString
    o <- m AttrString
    forall (m :: * -> *). MonadIO m => m AttrString
    newZeroAttrString
            AttrString -> [AttrOp AttrString 'AttrSet] -> m ()
    forall o (m :: * -> *).
    MonadIO m =>
    o -> [AttrOp o 'AttrSet] -> m ()
    GI.Attributes.set AttrString
    o [AttrOp AttrString tag]
    [AttrOp AttrString 'AttrSet]
    attrs
            AttrString -> m AttrString
    forall (m :: * -> *) a. Monad m => a -> m a
    return AttrString
    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' attrString #attr
    -- @
    getAttrStringAttr :: MonadIO m => AttrString -> m Pango.Attribute.Attribute
    getAttrStringAttr :: AttrString -> m Attribute
    getAttrStringAttr s :: AttrString
    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
    $ AttrString -> (Ptr AttrString -> IO Attribute) -> IO Attribute
    forall a c.
    (HasCallStack, ManagedPtrNewtype a) =>
    a -> (Ptr a -> IO c) -> IO c
    withManagedPtr AttrString
    s ((Ptr AttrString -> IO Attribute) -> IO Attribute)
    -> (Ptr AttrString -> IO Attribute) -> IO Attribute
    forall a b. (a -> b) -> a -> b
    $ \ptr :: Ptr AttrString
    ptr -> do
        let val :: Ptr Attribute
    val = Ptr AttrString
    ptr Ptr AttrString -> Int -> Ptr Attribute
    forall a b. Ptr a -> Int -> Ptr b
    `plusPtr` 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 AttrStringAttrFieldInfo
    instance AttrInfo AttrStringAttrFieldInfo where
        type AttrBaseTypeConstraint AttrStringAttrFieldInfo = (~) AttrString
        type AttrAllowedOps AttrStringAttrFieldInfo = '[ 'AttrGet]
        type AttrSetTypeConstraint AttrStringAttrFieldInfo = (~) (Ptr Pango.Attribute.Attribute)
        type AttrTransferTypeConstraint AttrStringAttrFieldInfo = (~)(Ptr Pango.Attribute.Attribute)
        type AttrTransferType AttrStringAttrFieldInfo = (Ptr Pango.Attribute.Attribute)
        type AttrGetType AttrStringAttrFieldInfo = Pango.Attribute.Attribute
        type AttrLabel AttrStringAttrFieldInfo = "attr"
        type AttrOrigin AttrStringAttrFieldInfo = AttrString
        attrGet = getAttrStringAttr
        attrSet = undefined
        attrConstruct = undefined
        attrClear = undefined
        attrTransfer = undefined

    attrString_attr :: AttrLabelProxy "attr"
    attrString_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' attrString #value
    -- @
    getAttrStringValue :: MonadIO m => AttrString -> m (Maybe T.Text)
    getAttrStringValue :: AttrString -> m (Maybe Text)
    getAttrStringValue s :: AttrString
    s = IO (Maybe Text) -> m (Maybe Text)
    forall (m :: * -> *) a. MonadIO m => IO a -> m a
    liftIO (IO (Maybe Text) -> m (Maybe Text))
    -> IO (Maybe Text) -> m (Maybe Text)
    forall a b. (a -> b) -> a -> b
    $ AttrString
    -> (Ptr AttrString -> IO (Maybe Text)) -> IO (Maybe Text)
    forall a c.
    (HasCallStack, ManagedPtrNewtype a) =>
    a -> (Ptr a -> IO c) -> IO c
    withManagedPtr AttrString
    s ((Ptr AttrString -> IO (Maybe Text)) -> IO (Maybe Text))
    -> (Ptr AttrString -> IO (Maybe Text)) -> IO (Maybe Text)
    forall a b. (a -> b) -> a -> b
    $ \ptr :: Ptr AttrString
    ptr -> do
        CString
    val <- Ptr CString -> IO CString
    forall a. Storable a => Ptr a -> IO a
    peek (Ptr AttrString
    ptr Ptr AttrString -> Int -> Ptr CString
    forall a b. Ptr a -> Int -> Ptr b
    `plusPtr` 16) :: IO CString
        Maybe Text
    result <- CString -> (CString -> IO Text) -> IO (Maybe Text)
    forall a b. Ptr a -> (Ptr a -> IO b) -> IO (Maybe b)
    SP.convertIfNonNull CString
    val ((CString -> IO Text) -> IO (Maybe Text))
    -> (CString -> IO Text) -> IO (Maybe Text)
    forall a b. (a -> b) -> a -> b
    $ \val' :: CString
    val' -> do
            Text
    val'' <- HasCallStack => CString -> IO Text
    CString -> IO Text
    cstringToText CString
    val'
            Text -> IO Text
    forall (m :: * -> *) a. Monad m => a -> m a
    return Text
    val''
        Maybe Text -> IO (Maybe Text)
    forall (m :: * -> *) a. Monad m => a -> m a
    return Maybe Text
    result

    -- | 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' attrString [ #value 'Data.GI.Base.Attributes.:=' value ]
    -- @
    setAttrStringValue :: MonadIO m => AttrString -> CString -> m ()
    setAttrStringValue :: AttrString -> CString -> m ()
    setAttrStringValue s :: AttrString
    s val :: CString
    val = IO () -> m ()
    forall (m :: * -> *) a. MonadIO m => IO a -> m a
    liftIO (IO () -> m ()) -> IO () -> m ()
    forall a b. (a -> b) -> a -> b
    $ AttrString -> (Ptr AttrString -> IO ()) -> IO ()
    forall a c.
    (HasCallStack, ManagedPtrNewtype a) =>
    a -> (Ptr a -> IO c) -> IO c
    withManagedPtr AttrString
    s ((Ptr AttrString -> IO ()) -> IO ())
    -> (Ptr AttrString -> IO ()) -> IO ()
    forall a b. (a -> b) -> a -> b
    $ \ptr :: Ptr AttrString
    ptr -> do
        Ptr CString -> CString -> IO ()
    forall a. Storable a => Ptr a -> a -> IO ()
    poke (Ptr AttrString
    ptr Ptr AttrString -> Int -> Ptr CString
    forall a b. Ptr a -> Int -> Ptr b
    `plusPtr` 16) (CString
    val :: CString)

    -- | Set the value of the “@value@” 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' #value
    -- @
    clearAttrStringValue :: MonadIO m => AttrString -> m ()
    clearAttrStringValue :: AttrString -> m ()
    clearAttrStringValue s :: AttrString
    s = IO () -> m ()
    forall (m :: * -> *) a. MonadIO m => IO a -> m a
    liftIO (IO () -> m ()) -> IO () -> m ()
    forall a b. (a -> b) -> a -> b
    $ AttrString -> (Ptr AttrString -> IO ()) -> IO ()
    forall a c.
    (HasCallStack, ManagedPtrNewtype a) =>
    a -> (Ptr a -> IO c) -> IO c
    withManagedPtr AttrString
    s ((Ptr AttrString -> IO ()) -> IO ())
    -> (Ptr AttrString -> IO ()) -> IO ()
    forall a b. (a -> b) -> a -> b
    $ \ptr :: Ptr AttrString
    ptr -> do
        Ptr CString -> CString -> IO ()
    forall a. Storable a => Ptr a -> a -> IO ()
    poke (Ptr AttrString
    ptr Ptr AttrString -> Int -> Ptr CString
    forall a b. Ptr a -> Int -> Ptr b
    `plusPtr` 16) (CString
    forall a. Ptr a
    FP.nullPtr :: CString)

    #if defined(ENABLE_OVERLOADING)
    data AttrStringValueFieldInfo
    instance AttrInfo AttrStringValueFieldInfo where
        type AttrBaseTypeConstraint AttrStringValueFieldInfo = (~) AttrString
        type AttrAllowedOps AttrStringValueFieldInfo = '[ 'AttrSet, 'AttrGet, 'AttrClear]
        type AttrSetTypeConstraint AttrStringValueFieldInfo = (~) CString
        type AttrTransferTypeConstraint AttrStringValueFieldInfo = (~)CString
        type AttrTransferType AttrStringValueFieldInfo = CString
        type AttrGetType AttrStringValueFieldInfo = Maybe T.Text
        type AttrLabel AttrStringValueFieldInfo = "value"
        type AttrOrigin AttrStringValueFieldInfo = AttrString
        attrGet = getAttrStringValue
        attrSet = setAttrStringValue
        attrConstruct = undefined
        attrClear = clearAttrStringValue
        attrTransfer _ v = do
            return v

    attrString_value :: AttrLabelProxy "value"
    attrString_value = AttrLabelProxy

    #endif

    #if defined(ENABLE_OVERLOADING)
    instance O.HasAttributeList AttrString
    type instance O.AttributeList AttrString = AttrStringAttributeList
    type AttrStringAttributeList = ('[ '("attr", AttrStringAttrFieldInfo), '("value", AttrStringValueFieldInfo)] :: [(Symbol, *)])
    #endif

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

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

    #endif