{-# 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.Coverage.Coverage' structure represents a map from Unicode characters
-- to t'GI.Pango.Enums.CoverageLevel'. It is an opaque structure with no public fields.

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

module GI.Pango.Structs.Coverage
    ( 

-- * Exported types
    Coverage(..)                            ,
    noCoverage                              ,


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

#if defined(ENABLE_OVERLOADING)
    ResolveCoverageMethod                   ,
#endif


-- ** get #method:get#

#if defined(ENABLE_OVERLOADING)
    CoverageGetMethodInfo                   ,
#endif
    coverageGet                             ,


-- ** max #method:max#

#if defined(ENABLE_OVERLOADING)
    CoverageMaxMethodInfo                   ,
#endif
    coverageMax                             ,


-- ** set #method:set#

#if defined(ENABLE_OVERLOADING)
    CoverageSetMethodInfo                   ,
#endif
    coverageSet                             ,


-- ** toBytes #method:toBytes#

#if defined(ENABLE_OVERLOADING)
    CoverageToBytesMethodInfo               ,
#endif
    coverageToBytes                         ,


-- ** unref #method:unref#

#if defined(ENABLE_OVERLOADING)
    CoverageUnrefMethodInfo                 ,
#endif
    coverageUnref                           ,




    ) 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.GI.Base.Signals as B.Signals
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.Enums as Pango.Enums

-- | Memory-managed wrapper type.
newtype Coverage = Coverage (ManagedPtr Coverage)
    deriving (Coverage -> Coverage -> Bool
(Coverage -> Coverage -> Bool)
-> (Coverage -> Coverage -> Bool) -> Eq Coverage
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Coverage -> Coverage -> Bool
$c/= :: Coverage -> Coverage -> Bool
== :: Coverage -> Coverage -> Bool
$c== :: Coverage -> Coverage -> Bool
Eq)
-- XXX Wrapping a foreign struct/union with no known destructor or size, leak?
instance WrappedPtr Coverage where
    wrappedPtrCalloc :: IO (Ptr Coverage)
wrappedPtrCalloc = Ptr Coverage -> IO (Ptr Coverage)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Coverage
forall a. Ptr a
nullPtr
    wrappedPtrCopy :: Coverage -> IO Coverage
wrappedPtrCopy = Coverage -> IO Coverage
forall (m :: * -> *) a. Monad m => a -> m a
return
    wrappedPtrFree :: Maybe (GDestroyNotify Coverage)
wrappedPtrFree = Maybe (GDestroyNotify Coverage)
forall a. Maybe a
Nothing

-- | A convenience alias for `Nothing` :: `Maybe` `Coverage`.
noCoverage :: Maybe Coverage
noCoverage :: Maybe Coverage
noCoverage = Maybe Coverage
forall a. Maybe a
Nothing


#if defined(ENABLE_OVERLOADING)
instance O.HasAttributeList Coverage
type instance O.AttributeList Coverage = CoverageAttributeList
type CoverageAttributeList = ('[ ] :: [(Symbol, *)])
#endif

-- method Coverage::get
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "coverage"
--           , argType =
--               TInterface Name { namespace = "Pango" , name = "Coverage" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #PangoCoverage" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "index_"
--           , argType = TBasicType TInt
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the index to check" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just
--               (TInterface Name { namespace = "Pango" , name = "CoverageLevel" })
-- throws : False
-- Skip return : False

foreign import ccall "pango_coverage_get" pango_coverage_get :: 
    Ptr Coverage ->                         -- coverage : TInterface (Name {namespace = "Pango", name = "Coverage"})
    Int32 ->                                -- index_ : TBasicType TInt
    IO CUInt

-- | Determine whether a particular index is covered by /@coverage@/
coverageGet ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Coverage
    -- ^ /@coverage@/: a t'GI.Pango.Structs.Coverage.Coverage'
    -> Int32
    -- ^ /@index_@/: the index to check
    -> m Pango.Enums.CoverageLevel
    -- ^ __Returns:__ the coverage level of /@coverage@/ for character /@index_@/.
coverageGet :: Coverage -> Int32 -> m CoverageLevel
coverageGet coverage :: Coverage
coverage index_ :: Int32
index_ = IO CoverageLevel -> m CoverageLevel
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO CoverageLevel -> m CoverageLevel)
-> IO CoverageLevel -> m CoverageLevel
forall a b. (a -> b) -> a -> b
$ do
    Ptr Coverage
coverage' <- Coverage -> IO (Ptr Coverage)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Coverage
coverage
    CUInt
result <- Ptr Coverage -> Int32 -> IO CUInt
pango_coverage_get Ptr Coverage
coverage' Int32
index_
    let result' :: CoverageLevel
result' = (Int -> CoverageLevel
forall a. Enum a => Int -> a
toEnum (Int -> CoverageLevel) -> (CUInt -> Int) -> CUInt -> CoverageLevel
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CUInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral) CUInt
result
    Coverage -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Coverage
coverage
    CoverageLevel -> IO CoverageLevel
forall (m :: * -> *) a. Monad m => a -> m a
return CoverageLevel
result'

#if defined(ENABLE_OVERLOADING)
data CoverageGetMethodInfo
instance (signature ~ (Int32 -> m Pango.Enums.CoverageLevel), MonadIO m) => O.MethodInfo CoverageGetMethodInfo Coverage signature where
    overloadedMethod = coverageGet

#endif

-- method Coverage::max
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "coverage"
--           , argType =
--               TInterface Name { namespace = "Pango" , name = "Coverage" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #PangoCoverage" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "other"
--           , argType =
--               TInterface Name { namespace = "Pango" , name = "Coverage" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "another #PangoCoverage"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Nothing
-- throws : False
-- Skip return : False

foreign import ccall "pango_coverage_max" pango_coverage_max :: 
    Ptr Coverage ->                         -- coverage : TInterface (Name {namespace = "Pango", name = "Coverage"})
    Ptr Coverage ->                         -- other : TInterface (Name {namespace = "Pango", name = "Coverage"})
    IO ()

-- | Set the coverage for each index in /@coverage@/ to be the max (better)
-- value of the current coverage for the index and the coverage for
-- the corresponding index in /@other@/.
coverageMax ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Coverage
    -- ^ /@coverage@/: a t'GI.Pango.Structs.Coverage.Coverage'
    -> Coverage
    -- ^ /@other@/: another t'GI.Pango.Structs.Coverage.Coverage'
    -> m ()
coverageMax :: Coverage -> Coverage -> m ()
coverageMax coverage :: Coverage
coverage other :: Coverage
other = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    Ptr Coverage
coverage' <- Coverage -> IO (Ptr Coverage)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Coverage
coverage
    Ptr Coverage
other' <- Coverage -> IO (Ptr Coverage)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Coverage
other
    Ptr Coverage -> Ptr Coverage -> IO ()
pango_coverage_max Ptr Coverage
coverage' Ptr Coverage
other'
    Coverage -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Coverage
coverage
    Coverage -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Coverage
other
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

#if defined(ENABLE_OVERLOADING)
data CoverageMaxMethodInfo
instance (signature ~ (Coverage -> m ()), MonadIO m) => O.MethodInfo CoverageMaxMethodInfo Coverage signature where
    overloadedMethod = coverageMax

#endif

-- method Coverage::set
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "coverage"
--           , argType =
--               TInterface Name { namespace = "Pango" , name = "Coverage" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #PangoCoverage" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "index_"
--           , argType = TBasicType TInt
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the index to modify"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "level"
--           , argType =
--               TInterface Name { namespace = "Pango" , name = "CoverageLevel" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the new level for @index_"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Nothing
-- throws : False
-- Skip return : False

foreign import ccall "pango_coverage_set" pango_coverage_set :: 
    Ptr Coverage ->                         -- coverage : TInterface (Name {namespace = "Pango", name = "Coverage"})
    Int32 ->                                -- index_ : TBasicType TInt
    CUInt ->                                -- level : TInterface (Name {namespace = "Pango", name = "CoverageLevel"})
    IO ()

-- | Modify a particular index within /@coverage@/
coverageSet ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Coverage
    -- ^ /@coverage@/: a t'GI.Pango.Structs.Coverage.Coverage'
    -> Int32
    -- ^ /@index_@/: the index to modify
    -> Pango.Enums.CoverageLevel
    -- ^ /@level@/: the new level for /@index_@/
    -> m ()
coverageSet :: Coverage -> Int32 -> CoverageLevel -> m ()
coverageSet coverage :: Coverage
coverage index_ :: Int32
index_ level :: CoverageLevel
level = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    Ptr Coverage
coverage' <- Coverage -> IO (Ptr Coverage)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Coverage
coverage
    let level' :: CUInt
level' = (Int -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> CUInt) -> (CoverageLevel -> Int) -> CoverageLevel -> CUInt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CoverageLevel -> Int
forall a. Enum a => a -> Int
fromEnum) CoverageLevel
level
    Ptr Coverage -> Int32 -> CUInt -> IO ()
pango_coverage_set Ptr Coverage
coverage' Int32
index_ CUInt
level'
    Coverage -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Coverage
coverage
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

#if defined(ENABLE_OVERLOADING)
data CoverageSetMethodInfo
instance (signature ~ (Int32 -> Pango.Enums.CoverageLevel -> m ()), MonadIO m) => O.MethodInfo CoverageSetMethodInfo Coverage signature where
    overloadedMethod = coverageSet

#endif

-- method Coverage::to_bytes
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "coverage"
--           , argType =
--               TInterface Name { namespace = "Pango" , name = "Coverage" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #PangoCoverage" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "bytes"
--           , argType = TCArray False (-1) 2 (TBasicType TUInt8)
--           , direction = DirectionOut
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText =
--                     Just "\n  location to store result (must be freed with g_free())"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferEverything
--           }
--       , Arg
--           { argCName = "n_bytes"
--           , argType = TBasicType TInt
--           , direction = DirectionOut
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "location to store size of result"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferEverything
--           }
--       ]
-- Lengths: [ Arg
--              { argCName = "n_bytes"
--              , argType = TBasicType TInt
--              , direction = DirectionOut
--              , mayBeNull = False
--              , argDoc =
--                  Documentation
--                    { rawDocText = Just "location to store size of result"
--                    , sinceVersion = Nothing
--                    }
--              , argScope = ScopeTypeInvalid
--              , argClosure = -1
--              , argDestroy = -1
--              , argCallerAllocates = False
--              , transfer = TransferEverything
--              }
--          ]
-- returnType: Nothing
-- throws : False
-- Skip return : False

foreign import ccall "pango_coverage_to_bytes" pango_coverage_to_bytes :: 
    Ptr Coverage ->                         -- coverage : TInterface (Name {namespace = "Pango", name = "Coverage"})
    Ptr (Ptr Word8) ->                      -- bytes : TCArray False (-1) 2 (TBasicType TUInt8)
    Ptr Int32 ->                            -- n_bytes : TBasicType TInt
    IO ()

-- | Convert a t'GI.Pango.Structs.Coverage.Coverage' structure into a flat binary format
coverageToBytes ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Coverage
    -- ^ /@coverage@/: a t'GI.Pango.Structs.Coverage.Coverage'
    -> m (ByteString)
coverageToBytes :: Coverage -> m ByteString
coverageToBytes coverage :: Coverage
coverage = IO ByteString -> m ByteString
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO ByteString -> m ByteString) -> IO ByteString -> m ByteString
forall a b. (a -> b) -> a -> b
$ do
    Ptr Coverage
coverage' <- Coverage -> IO (Ptr Coverage)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Coverage
coverage
    Ptr (Ptr Word8)
bytes <- IO (Ptr (Ptr Word8))
forall a. Storable a => IO (Ptr a)
allocMem :: IO (Ptr (Ptr Word8))
    Ptr Int32
nBytes <- IO (Ptr Int32)
forall a. Storable a => IO (Ptr a)
allocMem :: IO (Ptr Int32)
    Ptr Coverage -> Ptr (Ptr Word8) -> Ptr Int32 -> IO ()
pango_coverage_to_bytes Ptr Coverage
coverage' Ptr (Ptr Word8)
bytes Ptr Int32
nBytes
    Int32
nBytes' <- Ptr Int32 -> IO Int32
forall a. Storable a => Ptr a -> IO a
peek Ptr Int32
nBytes
    Ptr Word8
bytes' <- Ptr (Ptr Word8) -> IO (Ptr Word8)
forall a. Storable a => Ptr a -> IO a
peek Ptr (Ptr Word8)
bytes
    ByteString
bytes'' <- (Int32 -> Ptr Word8 -> IO ByteString
forall a. Integral a => a -> Ptr Word8 -> IO ByteString
unpackByteStringWithLength Int32
nBytes') Ptr Word8
bytes'
    Ptr Word8 -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr Word8
bytes'
    Coverage -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Coverage
coverage
    Ptr (Ptr Word8) -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr (Ptr Word8)
bytes
    Ptr Int32 -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr Int32
nBytes
    ByteString -> IO ByteString
forall (m :: * -> *) a. Monad m => a -> m a
return ByteString
bytes''

#if defined(ENABLE_OVERLOADING)
data CoverageToBytesMethodInfo
instance (signature ~ (m (ByteString)), MonadIO m) => O.MethodInfo CoverageToBytesMethodInfo Coverage signature where
    overloadedMethod = coverageToBytes

#endif

-- method Coverage::unref
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "coverage"
--           , argType =
--               TInterface Name { namespace = "Pango" , name = "Coverage" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #PangoCoverage" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Nothing
-- throws : False
-- Skip return : False

foreign import ccall "pango_coverage_unref" pango_coverage_unref :: 
    Ptr Coverage ->                         -- coverage : TInterface (Name {namespace = "Pango", name = "Coverage"})
    IO ()

-- | Decrease the reference count on the t'GI.Pango.Structs.Coverage.Coverage' by one.
-- If the result is zero, free the coverage and all associated memory.
coverageUnref ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Coverage
    -- ^ /@coverage@/: a t'GI.Pango.Structs.Coverage.Coverage'
    -> m ()
coverageUnref :: Coverage -> m ()
coverageUnref coverage :: Coverage
coverage = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    Ptr Coverage
coverage' <- Coverage -> IO (Ptr Coverage)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Coverage
coverage
    Ptr Coverage -> IO ()
pango_coverage_unref Ptr Coverage
coverage'
    Coverage -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Coverage
coverage
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

#if defined(ENABLE_OVERLOADING)
data CoverageUnrefMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.MethodInfo CoverageUnrefMethodInfo Coverage signature where
    overloadedMethod = coverageUnref

#endif

#if defined(ENABLE_OVERLOADING)
type family ResolveCoverageMethod (t :: Symbol) (o :: *) :: * where
    ResolveCoverageMethod "get" o = CoverageGetMethodInfo
    ResolveCoverageMethod "max" o = CoverageMaxMethodInfo
    ResolveCoverageMethod "set" o = CoverageSetMethodInfo
    ResolveCoverageMethod "toBytes" o = CoverageToBytesMethodInfo
    ResolveCoverageMethod "unref" o = CoverageUnrefMethodInfo
    ResolveCoverageMethod l o = O.MethodResolutionFailed l o

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

#endif