{-# LANGUAGE TypeApplications #-} -- | Copyright : Will Thompson, Iñaki García Etxebarria and Jonas Platte -- License : LGPL-2.1 -- Maintainer : Iñaki García Etxebarria -- -- Represents a unique ID of any object. #if (MIN_VERSION_haskell_gi_overloading(1,0,0) && !defined(__HADDOCK_VERSION__)) #define ENABLE_OVERLOADING #endif module GI.Ggit.Structs.OId ( -- * Exported types OId(..) , noOId , -- * Methods -- ** Overloaded methods #method:Overloaded methods# #if defined(ENABLE_OVERLOADING) ResolveOIdMethod , #endif -- ** compare #method:compare# #if defined(ENABLE_OVERLOADING) OIdCompareMethodInfo , #endif oIdCompare , -- ** copy #method:copy# #if defined(ENABLE_OVERLOADING) OIdCopyMethodInfo , #endif oIdCopy , -- ** equal #method:equal# #if defined(ENABLE_OVERLOADING) OIdEqualMethodInfo , #endif oIdEqual , -- ** free #method:free# #if defined(ENABLE_OVERLOADING) OIdFreeMethodInfo , #endif oIdFree , -- ** hasPrefix #method:hasPrefix# #if defined(ENABLE_OVERLOADING) OIdHasPrefixMethodInfo , #endif oIdHasPrefix , -- ** hash #method:hash# #if defined(ENABLE_OVERLOADING) OIdHashMethodInfo , #endif oIdHash , -- ** isZero #method:isZero# #if defined(ENABLE_OVERLOADING) OIdIsZeroMethodInfo , #endif oIdIsZero , -- ** newFromRaw #method:newFromRaw# oIdNewFromRaw , -- ** newFromString #method:newFromString# oIdNewFromString , -- ** toString #method:toString# #if defined(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.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 -- | Memory-managed wrapper type. newtype OId = OId (ManagedPtr OId) deriving (Eq) foreign import ccall "ggit_oid_get_type" c_ggit_oid_get_type :: IO GType instance BoxedObject OId where boxedType _ = c_ggit_oid_get_type -- | Convert 'OId' to and from 'Data.GI.Base.GValue.GValue' with 'Data.GI.Base.GValue.toGValue' and 'Data.GI.Base.GValue.fromGValue'. instance B.GValue.IsGValue OId where toGValue o = do gtype <- c_ggit_oid_get_type B.ManagedPtr.withManagedPtr o (B.GValue.buildGValue gtype B.GValue.set_boxed) fromGValue gv = do ptr <- B.GValue.get_boxed gv :: IO (Ptr OId) B.ManagedPtr.newBoxed OId ptr -- | A convenience alias for `Nothing` :: `Maybe` `OId`. noOId :: Maybe OId noOId = Nothing #if defined(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 = TCArray True (-1) (-1) (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 :: Ptr Word8 -> -- raw : TCArray True (-1) (-1) (TBasicType TUInt8) IO (Ptr OId) -- | Creates a new t'GI.Ggit.Structs.OId.OId' from a raw oid. oIdNewFromRaw :: (B.CallStack.HasCallStack, MonadIO m) => ByteString -- ^ /@raw@/: the raw input bytes to be copied. -> m (Maybe OId) -- ^ __Returns:__ a newly allocated t'GI.Ggit.Structs.OId.OId' or 'P.Nothing' on error. oIdNewFromRaw raw = liftIO $ do raw' <- packZeroTerminatedByteString raw result <- ggit_oid_new_from_raw raw' maybeResult <- convertIfNonNull result $ \result' -> do result'' <- (wrapBoxed OId) result' return result'' freeMem raw' return maybeResult #if defined(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 t'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 t'GI.Ggit.Structs.OId.OId' or 'P.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 defined(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 t'GI.Ggit.Structs.OId.OId' structures. oIdCompare :: (B.CallStack.HasCallStack, MonadIO m) => OId -- ^ /@a@/: first t'GI.Ggit.Structs.OId.OId'. -> OId -- ^ /@b@/: second t'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 defined(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 t'GI.Ggit.Structs.OId.OId'. oIdCopy :: (B.CallStack.HasCallStack, MonadIO m) => OId -- ^ /@oid@/: a t'GI.Ggit.Structs.OId.OId'. -> m (Maybe OId) -- ^ __Returns:__ a newly allocated t'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 defined(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 t'GI.Ggit.Structs.OId.OId' for equality. oIdEqual :: (B.CallStack.HasCallStack, MonadIO m) => OId -- ^ /@a@/: a t'GI.Ggit.Structs.OId.OId'. -> OId -- ^ /@b@/: a t'GI.Ggit.Structs.OId.OId'. -> m Bool -- ^ __Returns:__ 'P.True' if /@a@/ and /@b@/ are equal, 'P.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 defined(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 t'GI.Ggit.Structs.OId.OId'. -> m () oIdFree oid = liftIO $ do oid' <- unsafeManagedPtrGetPtr oid ggit_oid_free oid' touchManagedPtr oid return () #if defined(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 t'GI.Ggit.Structs.OId.OId'. -> T.Text -- ^ /@prefix@/: a prefix. -> m Bool -- ^ __Returns:__ 'P.True' if the id has the given prefix, 'P.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 defined(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 t'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 defined(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 t'GI.Ggit.Structs.OId.OId'. -> m Bool -- ^ __Returns:__ 'P.True' if the oid contains only zeros, 'P.False' otherwise. oIdIsZero oid = liftIO $ do oid' <- unsafeManagedPtrGetPtr oid result <- ggit_oid_is_zero oid' let result' = (/= 0) result touchManagedPtr oid return result' #if defined(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 t'GI.Ggit.Structs.OId.OId'. -> m (Maybe T.Text) -- ^ __Returns:__ a newly allocated string representing /@oid@/ or 'P.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 defined(ENABLE_OVERLOADING) data OIdToStringMethodInfo instance (signature ~ (m (Maybe T.Text)), MonadIO m) => O.MethodInfo OIdToStringMethodInfo OId signature where overloadedMethod = oIdToString #endif #if defined(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 @info #else fromLabel _ = O.overloadedMethod @info #endif #endif