{-# LANGUAGE TypeApplications #-}


-- | Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
-- License    : LGPL-2.1
-- Maintainer : Iñaki García Etxebarria
-- 
-- Reprensents a git reference specification.

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

module GI.Ggit.Structs.RefSpec
    ( 

-- * Exported types
    RefSpec(..)                             ,


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

#if defined(ENABLE_OVERLOADING)
    ResolveRefSpecMethod                    ,
#endif


-- ** getDestination #method:getDestination#

#if defined(ENABLE_OVERLOADING)
    RefSpecGetDestinationMethodInfo         ,
#endif
    refSpecGetDestination                   ,


-- ** getSource #method:getSource#

#if defined(ENABLE_OVERLOADING)
    RefSpecGetSourceMethodInfo              ,
#endif
    refSpecGetSource                        ,


-- ** isForced #method:isForced#

#if defined(ENABLE_OVERLOADING)
    RefSpecIsForcedMethodInfo               ,
#endif
    refSpecIsForced                         ,


-- ** ref #method:ref#

#if defined(ENABLE_OVERLOADING)
    RefSpecRefMethodInfo                    ,
#endif
    refSpecRef                              ,


-- ** unref #method:unref#

#if defined(ENABLE_OVERLOADING)
    RefSpecUnrefMethodInfo                  ,
#endif
    refSpecUnref                            ,




    ) 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


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

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

foreign import ccall "ggit_ref_spec_get_type" c_ggit_ref_spec_get_type :: 
    IO GType

type instance O.ParentTypes RefSpec = '[]
instance O.HasParentTypes RefSpec

instance B.Types.TypedObject RefSpec where
    glibType :: IO GType
glibType = IO GType
c_ggit_ref_spec_get_type

instance B.Types.GBoxed RefSpec

-- | Convert 'RefSpec' to and from 'Data.GI.Base.GValue.GValue' with 'Data.GI.Base.GValue.toGValue' and 'Data.GI.Base.GValue.fromGValue'.
instance B.GValue.IsGValue RefSpec where
    toGValue :: RefSpec -> IO GValue
toGValue RefSpec
o = do
        GType
gtype <- IO GType
c_ggit_ref_spec_get_type
        RefSpec -> (Ptr RefSpec -> IO GValue) -> IO GValue
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
B.ManagedPtr.withManagedPtr RefSpec
o (GType
-> (GValue -> Ptr RefSpec -> IO ()) -> Ptr RefSpec -> IO GValue
forall a. GType -> (GValue -> a -> IO ()) -> a -> IO GValue
B.GValue.buildGValue GType
gtype GValue -> Ptr RefSpec -> IO ()
forall a. GValue -> Ptr a -> IO ()
B.GValue.set_boxed)
        
    fromGValue :: GValue -> IO RefSpec
fromGValue GValue
gv = do
        Ptr RefSpec
ptr <- GValue -> IO (Ptr RefSpec)
forall b. GValue -> IO (Ptr b)
B.GValue.get_boxed GValue
gv :: IO (Ptr RefSpec)
        (ManagedPtr RefSpec -> RefSpec) -> Ptr RefSpec -> IO RefSpec
forall a.
(HasCallStack, GBoxed a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
B.ManagedPtr.newBoxed ManagedPtr RefSpec -> RefSpec
RefSpec Ptr RefSpec
ptr
        
    


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

-- method RefSpec::get_destination
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "refspec"
--           , argType =
--               TInterface Name { namespace = "Ggit" , name = "RefSpec" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GgitRefSpec." , 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_ref_spec_get_destination" ggit_ref_spec_get_destination :: 
    Ptr RefSpec ->                          -- refspec : TInterface (Name {namespace = "Ggit", name = "RefSpec"})
    IO CString

-- | Gets the /@refspec@/\'s destination.
refSpecGetDestination ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    RefSpec
    -- ^ /@refspec@/: a t'GI.Ggit.Structs.RefSpec.RefSpec'.
    -> m (Maybe T.Text)
    -- ^ __Returns:__ the refspec\'s destination or 'P.Nothing'.
refSpecGetDestination :: RefSpec -> m (Maybe Text)
refSpecGetDestination RefSpec
refspec = 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
$ do
    Ptr RefSpec
refspec' <- RefSpec -> IO (Ptr RefSpec)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr RefSpec
refspec
    CString
result <- Ptr RefSpec -> IO CString
ggit_ref_spec_get_destination Ptr RefSpec
refspec'
    Maybe Text
maybeResult <- CString -> (CString -> IO Text) -> IO (Maybe Text)
forall a b. Ptr a -> (Ptr a -> IO b) -> IO (Maybe b)
convertIfNonNull CString
result ((CString -> IO Text) -> IO (Maybe Text))
-> (CString -> IO Text) -> IO (Maybe Text)
forall a b. (a -> b) -> a -> b
$ \CString
result' -> do
        Text
result'' <- HasCallStack => CString -> IO Text
CString -> IO Text
cstringToText CString
result'
        Text -> IO Text
forall (m :: * -> *) a. Monad m => a -> m a
return Text
result''
    RefSpec -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr RefSpec
refspec
    Maybe Text -> IO (Maybe Text)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Text
maybeResult

#if defined(ENABLE_OVERLOADING)
data RefSpecGetDestinationMethodInfo
instance (signature ~ (m (Maybe T.Text)), MonadIO m) => O.MethodInfo RefSpecGetDestinationMethodInfo RefSpec signature where
    overloadedMethod = refSpecGetDestination

#endif

-- method RefSpec::get_source
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "refspec"
--           , argType =
--               TInterface Name { namespace = "Ggit" , name = "RefSpec" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GgitRefSpec." , 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_ref_spec_get_source" ggit_ref_spec_get_source :: 
    Ptr RefSpec ->                          -- refspec : TInterface (Name {namespace = "Ggit", name = "RefSpec"})
    IO CString

-- | Gets the /@refspec@/\'s source.
refSpecGetSource ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    RefSpec
    -- ^ /@refspec@/: a t'GI.Ggit.Structs.RefSpec.RefSpec'.
    -> m (Maybe T.Text)
    -- ^ __Returns:__ the refspec\'s source or 'P.Nothing'.
refSpecGetSource :: RefSpec -> m (Maybe Text)
refSpecGetSource RefSpec
refspec = 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
$ do
    Ptr RefSpec
refspec' <- RefSpec -> IO (Ptr RefSpec)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr RefSpec
refspec
    CString
result <- Ptr RefSpec -> IO CString
ggit_ref_spec_get_source Ptr RefSpec
refspec'
    Maybe Text
maybeResult <- CString -> (CString -> IO Text) -> IO (Maybe Text)
forall a b. Ptr a -> (Ptr a -> IO b) -> IO (Maybe b)
convertIfNonNull CString
result ((CString -> IO Text) -> IO (Maybe Text))
-> (CString -> IO Text) -> IO (Maybe Text)
forall a b. (a -> b) -> a -> b
$ \CString
result' -> do
        Text
result'' <- HasCallStack => CString -> IO Text
CString -> IO Text
cstringToText CString
result'
        Text -> IO Text
forall (m :: * -> *) a. Monad m => a -> m a
return Text
result''
    RefSpec -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr RefSpec
refspec
    Maybe Text -> IO (Maybe Text)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Text
maybeResult

#if defined(ENABLE_OVERLOADING)
data RefSpecGetSourceMethodInfo
instance (signature ~ (m (Maybe T.Text)), MonadIO m) => O.MethodInfo RefSpecGetSourceMethodInfo RefSpec signature where
    overloadedMethod = refSpecGetSource

#endif

-- method RefSpec::is_forced
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "refspec"
--           , argType =
--               TInterface Name { namespace = "Ggit" , name = "RefSpec" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GgitRefSpec." , 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_ref_spec_is_forced" ggit_ref_spec_is_forced :: 
    Ptr RefSpec ->                          -- refspec : TInterface (Name {namespace = "Ggit", name = "RefSpec"})
    IO CInt

-- | Whether updating is done forcefully.
refSpecIsForced ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    RefSpec
    -- ^ /@refspec@/: a t'GI.Ggit.Structs.RefSpec.RefSpec'.
    -> m Bool
    -- ^ __Returns:__ if updating is done forcefully.
refSpecIsForced :: RefSpec -> m Bool
refSpecIsForced RefSpec
refspec = IO Bool -> m Bool
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Bool -> m Bool) -> IO Bool -> m Bool
forall a b. (a -> b) -> a -> b
$ do
    Ptr RefSpec
refspec' <- RefSpec -> IO (Ptr RefSpec)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr RefSpec
refspec
    CInt
result <- Ptr RefSpec -> IO CInt
ggit_ref_spec_is_forced Ptr RefSpec
refspec'
    let result' :: Bool
result' = (CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
/= CInt
0) CInt
result
    RefSpec -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr RefSpec
refspec
    Bool -> IO Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
result'

#if defined(ENABLE_OVERLOADING)
data RefSpecIsForcedMethodInfo
instance (signature ~ (m Bool), MonadIO m) => O.MethodInfo RefSpecIsForcedMethodInfo RefSpec signature where
    overloadedMethod = refSpecIsForced

#endif

-- method RefSpec::ref
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "refspec"
--           , argType =
--               TInterface Name { namespace = "Ggit" , name = "RefSpec" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GgitRefSpec." , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TInterface Name { namespace = "Ggit" , name = "RefSpec" })
-- throws : False
-- Skip return : False

foreign import ccall "ggit_ref_spec_ref" ggit_ref_spec_ref :: 
    Ptr RefSpec ->                          -- refspec : TInterface (Name {namespace = "Ggit", name = "RefSpec"})
    IO (Ptr RefSpec)

-- | Atomically increments the reference count of /@refspec@/ by one.
-- This function is MT-safe and may be called from any thread.
refSpecRef ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    RefSpec
    -- ^ /@refspec@/: a t'GI.Ggit.Structs.RefSpec.RefSpec'.
    -> m (Maybe RefSpec)
    -- ^ __Returns:__ a t'GI.Ggit.Structs.RefSpec.RefSpec' or 'P.Nothing'.
refSpecRef :: RefSpec -> m (Maybe RefSpec)
refSpecRef RefSpec
refspec = IO (Maybe RefSpec) -> m (Maybe RefSpec)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe RefSpec) -> m (Maybe RefSpec))
-> IO (Maybe RefSpec) -> m (Maybe RefSpec)
forall a b. (a -> b) -> a -> b
$ do
    Ptr RefSpec
refspec' <- RefSpec -> IO (Ptr RefSpec)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr RefSpec
refspec
    Ptr RefSpec
result <- Ptr RefSpec -> IO (Ptr RefSpec)
ggit_ref_spec_ref Ptr RefSpec
refspec'
    Maybe RefSpec
maybeResult <- Ptr RefSpec -> (Ptr RefSpec -> IO RefSpec) -> IO (Maybe RefSpec)
forall a b. Ptr a -> (Ptr a -> IO b) -> IO (Maybe b)
convertIfNonNull Ptr RefSpec
result ((Ptr RefSpec -> IO RefSpec) -> IO (Maybe RefSpec))
-> (Ptr RefSpec -> IO RefSpec) -> IO (Maybe RefSpec)
forall a b. (a -> b) -> a -> b
$ \Ptr RefSpec
result' -> do
        RefSpec
result'' <- ((ManagedPtr RefSpec -> RefSpec) -> Ptr RefSpec -> IO RefSpec
forall a.
(HasCallStack, GBoxed a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
newBoxed ManagedPtr RefSpec -> RefSpec
RefSpec) Ptr RefSpec
result'
        RefSpec -> IO RefSpec
forall (m :: * -> *) a. Monad m => a -> m a
return RefSpec
result''
    RefSpec -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr RefSpec
refspec
    Maybe RefSpec -> IO (Maybe RefSpec)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe RefSpec
maybeResult

#if defined(ENABLE_OVERLOADING)
data RefSpecRefMethodInfo
instance (signature ~ (m (Maybe RefSpec)), MonadIO m) => O.MethodInfo RefSpecRefMethodInfo RefSpec signature where
    overloadedMethod = refSpecRef

#endif

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

foreign import ccall "ggit_ref_spec_unref" ggit_ref_spec_unref :: 
    Ptr RefSpec ->                          -- refspec : TInterface (Name {namespace = "Ggit", name = "RefSpec"})
    IO ()

-- | Atomically decrements the reference count of /@refspec@/ by one.
-- If the reference count drops to 0, /@refspec@/ is freed.
refSpecUnref ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    RefSpec
    -- ^ /@refspec@/: a t'GI.Ggit.Structs.RefSpec.RefSpec'.
    -> m ()
refSpecUnref :: RefSpec -> m ()
refSpecUnref RefSpec
refspec = 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 RefSpec
refspec' <- RefSpec -> IO (Ptr RefSpec)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr RefSpec
refspec
    Ptr RefSpec -> IO ()
ggit_ref_spec_unref Ptr RefSpec
refspec'
    RefSpec -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr RefSpec
refspec
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

#if defined(ENABLE_OVERLOADING)
data RefSpecUnrefMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.MethodInfo RefSpecUnrefMethodInfo RefSpec signature where
    overloadedMethod = refSpecUnref

#endif

#if defined(ENABLE_OVERLOADING)
type family ResolveRefSpecMethod (t :: Symbol) (o :: *) :: * where
    ResolveRefSpecMethod "isForced" o = RefSpecIsForcedMethodInfo
    ResolveRefSpecMethod "ref" o = RefSpecRefMethodInfo
    ResolveRefSpecMethod "unref" o = RefSpecUnrefMethodInfo
    ResolveRefSpecMethod "getDestination" o = RefSpecGetDestinationMethodInfo
    ResolveRefSpecMethod "getSource" o = RefSpecGetSourceMethodInfo
    ResolveRefSpecMethod l o = O.MethodResolutionFailed l o

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

#endif