gi-ggit-1.0.4: GI/Ggit/Structs/OId.hs
{- |
Copyright : Will Thompson, Iñaki García Etxebarria and Jonas Platte
License : LGPL-2.1
Maintainer : Iñaki García Etxebarria (inaki@blueleaf.cc)
Represents a unique ID of any object.
-}
#define ENABLE_OVERLOADING (MIN_VERSION_haskell_gi_overloading(1,0,0) \
&& !defined(__HADDOCK_VERSION__))
module GI.Ggit.Structs.OId
(
-- * Exported types
OId(..) ,
noOId ,
-- * Methods
-- ** compare #method:compare#
#if ENABLE_OVERLOADING
OIdCompareMethodInfo ,
#endif
oIdCompare ,
-- ** copy #method:copy#
#if ENABLE_OVERLOADING
OIdCopyMethodInfo ,
#endif
oIdCopy ,
-- ** equal #method:equal#
#if ENABLE_OVERLOADING
OIdEqualMethodInfo ,
#endif
oIdEqual ,
-- ** free #method:free#
#if ENABLE_OVERLOADING
OIdFreeMethodInfo ,
#endif
oIdFree ,
-- ** hasPrefix #method:hasPrefix#
#if ENABLE_OVERLOADING
OIdHasPrefixMethodInfo ,
#endif
oIdHasPrefix ,
-- ** hash #method:hash#
#if ENABLE_OVERLOADING
OIdHashMethodInfo ,
#endif
oIdHash ,
-- ** isZero #method:isZero#
#if ENABLE_OVERLOADING
OIdIsZeroMethodInfo ,
#endif
oIdIsZero ,
-- ** newFromRaw #method:newFromRaw#
oIdNewFromRaw ,
-- ** newFromString #method:newFromString#
oIdNewFromString ,
-- ** toString #method:toString#
#if ENABLE_OVERLOADING
OIdToStringMethodInfo ,
#endif
oIdToString ,
) 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
-- | Memory-managed wrapper type.
newtype OId = OId (ManagedPtr OId)
foreign import ccall "ggit_oid_get_type" c_ggit_oid_get_type ::
IO GType
instance BoxedObject OId where
boxedType _ = c_ggit_oid_get_type
-- | A convenience alias for `Nothing` :: `Maybe` `OId`.
noOId :: Maybe OId
noOId = Nothing
#if ENABLE_OVERLOADING
instance O.HasAttributeList OId
type instance O.AttributeList OId = OIdAttributeList
type OIdAttributeList = ('[ ] :: [(Symbol, *)])
#endif
-- method OId::new_from_raw
-- method type : Constructor
-- Args : [Arg {argCName = "raw", argType = TBasicType TUInt8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the raw input bytes to be copied.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Ggit", name = "OId"}))
-- throws : False
-- Skip return : False
foreign import ccall "ggit_oid_new_from_raw" ggit_oid_new_from_raw ::
Word8 -> -- raw : TBasicType TUInt8
IO (Ptr OId)
{- |
Creates a new 'GI.Ggit.Structs.OId.OId' from a raw oid.
-}
oIdNewFromRaw ::
(B.CallStack.HasCallStack, MonadIO m) =>
Word8
{- ^ /@raw@/: the raw input bytes to be copied. -}
-> m (Maybe OId)
{- ^ __Returns:__ a newly allocated 'GI.Ggit.Structs.OId.OId' or 'Nothing' on error. -}
oIdNewFromRaw raw = liftIO $ do
result <- ggit_oid_new_from_raw raw
maybeResult <- convertIfNonNull result $ \result' -> do
result'' <- (wrapBoxed OId) result'
return result''
return maybeResult
#if ENABLE_OVERLOADING
#endif
-- method OId::new_from_string
-- method type : Constructor
-- Args : [Arg {argCName = "str", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "input hex string; must be pointing at the start of\n the hex sequence and have at least the number of bytes\n needed for an oid encoded in hex (40 bytes).", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Ggit", name = "OId"}))
-- throws : False
-- Skip return : False
foreign import ccall "ggit_oid_new_from_string" ggit_oid_new_from_string ::
CString -> -- str : TBasicType TUTF8
IO (Ptr OId)
{- |
Parses a hex formatted object id into a 'GI.Ggit.Structs.OId.OId'.
-}
oIdNewFromString ::
(B.CallStack.HasCallStack, MonadIO m) =>
T.Text
{- ^ /@str@/: input hex string; must be pointing at the start of
the hex sequence and have at least the number of bytes
needed for an oid encoded in hex (40 bytes). -}
-> m (Maybe OId)
{- ^ __Returns:__ a newly allocated 'GI.Ggit.Structs.OId.OId' or 'Nothing' on error. -}
oIdNewFromString str = liftIO $ do
str' <- textToCString str
result <- ggit_oid_new_from_string str'
maybeResult <- convertIfNonNull result $ \result' -> do
result'' <- (wrapBoxed OId) result'
return result''
freeMem str'
return maybeResult
#if ENABLE_OVERLOADING
#endif
-- method OId::compare
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "a", argType = TInterface (Name {namespace = "Ggit", name = "OId"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "first #GgitOId.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "b", argType = TInterface (Name {namespace = "Ggit", name = "OId"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "second #GgitOId.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TInt)
-- throws : False
-- Skip return : False
foreign import ccall "ggit_oid_compare" ggit_oid_compare ::
Ptr OId -> -- a : TInterface (Name {namespace = "Ggit", name = "OId"})
Ptr OId -> -- b : TInterface (Name {namespace = "Ggit", name = "OId"})
IO Int32
{- |
Compare two 'GI.Ggit.Structs.OId.OId' structures.
-}
oIdCompare ::
(B.CallStack.HasCallStack, MonadIO m) =>
OId
{- ^ /@a@/: first 'GI.Ggit.Structs.OId.OId'. -}
-> OId
{- ^ /@b@/: second 'GI.Ggit.Structs.OId.OId'. -}
-> m Int32
{- ^ __Returns:__ \<0, 0, >0 if a \< b, a == b, a > b. -}
oIdCompare a b = liftIO $ do
a' <- unsafeManagedPtrGetPtr a
b' <- unsafeManagedPtrGetPtr b
result <- ggit_oid_compare a' b'
touchManagedPtr a
touchManagedPtr b
return result
#if ENABLE_OVERLOADING
data OIdCompareMethodInfo
instance (signature ~ (OId -> m Int32), MonadIO m) => O.MethodInfo OIdCompareMethodInfo OId signature where
overloadedMethod _ = oIdCompare
#endif
-- method OId::copy
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "oid", argType = TInterface (Name {namespace = "Ggit", name = "OId"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitOId.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Ggit", name = "OId"}))
-- throws : False
-- Skip return : False
foreign import ccall "ggit_oid_copy" ggit_oid_copy ::
Ptr OId -> -- oid : TInterface (Name {namespace = "Ggit", name = "OId"})
IO (Ptr OId)
{- |
Copies /@oid@/ into a newly allocated 'GI.Ggit.Structs.OId.OId'.
-}
oIdCopy ::
(B.CallStack.HasCallStack, MonadIO m) =>
OId
{- ^ /@oid@/: a 'GI.Ggit.Structs.OId.OId'. -}
-> m (Maybe OId)
{- ^ __Returns:__ a newly allocated 'GI.Ggit.Structs.OId.OId'. -}
oIdCopy oid = liftIO $ do
oid' <- unsafeManagedPtrGetPtr oid
result <- ggit_oid_copy oid'
maybeResult <- convertIfNonNull result $ \result' -> do
result'' <- (wrapBoxed OId) result'
return result''
touchManagedPtr oid
return maybeResult
#if ENABLE_OVERLOADING
data OIdCopyMethodInfo
instance (signature ~ (m (Maybe OId)), MonadIO m) => O.MethodInfo OIdCopyMethodInfo OId signature where
overloadedMethod _ = oIdCopy
#endif
-- method OId::equal
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "a", argType = TInterface (Name {namespace = "Ggit", name = "OId"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitOId.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "b", argType = TInterface (Name {namespace = "Ggit", name = "OId"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitOId.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False
foreign import ccall "ggit_oid_equal" ggit_oid_equal ::
Ptr OId -> -- a : TInterface (Name {namespace = "Ggit", name = "OId"})
Ptr OId -> -- b : TInterface (Name {namespace = "Ggit", name = "OId"})
IO CInt
{- |
Compares two 'GI.Ggit.Structs.OId.OId' for equality.
-}
oIdEqual ::
(B.CallStack.HasCallStack, MonadIO m) =>
OId
{- ^ /@a@/: a 'GI.Ggit.Structs.OId.OId'. -}
-> OId
{- ^ /@b@/: a 'GI.Ggit.Structs.OId.OId'. -}
-> m Bool
{- ^ __Returns:__ 'True' if /@a@/ and /@b@/ are equal, 'False' otherwise -}
oIdEqual a b = liftIO $ do
a' <- unsafeManagedPtrGetPtr a
b' <- unsafeManagedPtrGetPtr b
result <- ggit_oid_equal a' b'
let result' = (/= 0) result
touchManagedPtr a
touchManagedPtr b
return result'
#if ENABLE_OVERLOADING
data OIdEqualMethodInfo
instance (signature ~ (OId -> m Bool), MonadIO m) => O.MethodInfo OIdEqualMethodInfo OId signature where
overloadedMethod _ = oIdEqual
#endif
-- method OId::free
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "oid", argType = TInterface (Name {namespace = "Ggit", name = "OId"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitOId.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False
foreign import ccall "ggit_oid_free" ggit_oid_free ::
Ptr OId -> -- oid : TInterface (Name {namespace = "Ggit", name = "OId"})
IO ()
{- |
Frees /@oid@/.
-}
oIdFree ::
(B.CallStack.HasCallStack, MonadIO m) =>
OId
{- ^ /@oid@/: a 'GI.Ggit.Structs.OId.OId'. -}
-> m ()
oIdFree oid = liftIO $ do
oid' <- unsafeManagedPtrGetPtr oid
ggit_oid_free oid'
touchManagedPtr oid
return ()
#if ENABLE_OVERLOADING
data OIdFreeMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.MethodInfo OIdFreeMethodInfo OId signature where
overloadedMethod _ = oIdFree
#endif
-- method OId::has_prefix
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "oid", argType = TInterface (Name {namespace = "Ggit", name = "OId"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitOId.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "prefix", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a prefix.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False
foreign import ccall "ggit_oid_has_prefix" ggit_oid_has_prefix ::
Ptr OId -> -- oid : TInterface (Name {namespace = "Ggit", name = "OId"})
CString -> -- prefix : TBasicType TUTF8
IO CInt
{- |
Check whether the object id has a given prefix. Note that the prefix is
specified in hexadecimal ASCII.
-}
oIdHasPrefix ::
(B.CallStack.HasCallStack, MonadIO m) =>
OId
{- ^ /@oid@/: a 'GI.Ggit.Structs.OId.OId'. -}
-> T.Text
{- ^ /@prefix@/: a prefix. -}
-> m Bool
{- ^ __Returns:__ 'True' if the id has the given prefix, 'False' otherwise. -}
oIdHasPrefix oid prefix = liftIO $ do
oid' <- unsafeManagedPtrGetPtr oid
prefix' <- textToCString prefix
result <- ggit_oid_has_prefix oid' prefix'
let result' = (/= 0) result
touchManagedPtr oid
freeMem prefix'
return result'
#if ENABLE_OVERLOADING
data OIdHasPrefixMethodInfo
instance (signature ~ (T.Text -> m Bool), MonadIO m) => O.MethodInfo OIdHasPrefixMethodInfo OId signature where
overloadedMethod _ = oIdHasPrefix
#endif
-- method OId::hash
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "oid", argType = TInterface (Name {namespace = "Ggit", name = "OId"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitOId.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TUInt)
-- throws : False
-- Skip return : False
foreign import ccall "ggit_oid_hash" ggit_oid_hash ::
Ptr OId -> -- oid : TInterface (Name {namespace = "Ggit", name = "OId"})
IO Word32
{- |
Computes a hash value for a git object identifier.
-}
oIdHash ::
(B.CallStack.HasCallStack, MonadIO m) =>
OId
{- ^ /@oid@/: a 'GI.Ggit.Structs.OId.OId'. -}
-> m Word32
{- ^ __Returns:__ the hash value -}
oIdHash oid = liftIO $ do
oid' <- unsafeManagedPtrGetPtr oid
result <- ggit_oid_hash oid'
touchManagedPtr oid
return result
#if ENABLE_OVERLOADING
data OIdHashMethodInfo
instance (signature ~ (m Word32), MonadIO m) => O.MethodInfo OIdHashMethodInfo OId signature where
overloadedMethod _ = oIdHash
#endif
-- method OId::is_zero
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "oid", argType = TInterface (Name {namespace = "Ggit", name = "OId"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitOId.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False
foreign import ccall "ggit_oid_is_zero" ggit_oid_is_zero ::
Ptr OId -> -- oid : TInterface (Name {namespace = "Ggit", name = "OId"})
IO CInt
{- |
Get whether the oid contains only zeros.
-}
oIdIsZero ::
(B.CallStack.HasCallStack, MonadIO m) =>
OId
{- ^ /@oid@/: a 'GI.Ggit.Structs.OId.OId'. -}
-> m Bool
{- ^ __Returns:__ 'True' if the oid contains only zeros, 'False' otherwise. -}
oIdIsZero oid = liftIO $ do
oid' <- unsafeManagedPtrGetPtr oid
result <- ggit_oid_is_zero oid'
let result' = (/= 0) result
touchManagedPtr oid
return result'
#if ENABLE_OVERLOADING
data OIdIsZeroMethodInfo
instance (signature ~ (m Bool), MonadIO m) => O.MethodInfo OIdIsZeroMethodInfo OId signature where
overloadedMethod _ = oIdIsZero
#endif
-- method OId::to_string
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "oid", argType = TInterface (Name {namespace = "Ggit", name = "OId"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitOId.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TUTF8)
-- throws : False
-- Skip return : False
foreign import ccall "ggit_oid_to_string" ggit_oid_to_string ::
Ptr OId -> -- oid : TInterface (Name {namespace = "Ggit", name = "OId"})
IO CString
{- |
Converts /@oid@/ into a readable string.
-}
oIdToString ::
(B.CallStack.HasCallStack, MonadIO m) =>
OId
{- ^ /@oid@/: a 'GI.Ggit.Structs.OId.OId'. -}
-> m (Maybe T.Text)
{- ^ __Returns:__ a newly allocated string representing /@oid@/ or 'Nothing'. -}
oIdToString oid = liftIO $ do
oid' <- unsafeManagedPtrGetPtr oid
result <- ggit_oid_to_string oid'
maybeResult <- convertIfNonNull result $ \result' -> do
result'' <- cstringToText result'
freeMem result'
return result''
touchManagedPtr oid
return maybeResult
#if ENABLE_OVERLOADING
data OIdToStringMethodInfo
instance (signature ~ (m (Maybe T.Text)), MonadIO m) => O.MethodInfo OIdToStringMethodInfo OId signature where
overloadedMethod _ = oIdToString
#endif
#if ENABLE_OVERLOADING
type family ResolveOIdMethod (t :: Symbol) (o :: *) :: * where
ResolveOIdMethod "compare" o = OIdCompareMethodInfo
ResolveOIdMethod "copy" o = OIdCopyMethodInfo
ResolveOIdMethod "equal" o = OIdEqualMethodInfo
ResolveOIdMethod "free" o = OIdFreeMethodInfo
ResolveOIdMethod "hasPrefix" o = OIdHasPrefixMethodInfo
ResolveOIdMethod "hash" o = OIdHashMethodInfo
ResolveOIdMethod "isZero" o = OIdIsZeroMethodInfo
ResolveOIdMethod "toString" o = OIdToStringMethodInfo
ResolveOIdMethod l o = O.MethodResolutionFailed l o
instance (info ~ ResolveOIdMethod t OId, O.MethodInfo info OId p) => OL.IsLabel t (OId -> 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