{- |
Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
License    : LGPL-2.1
Maintainer : Iñaki García Etxebarria (garetxe@gmail.com)

Represents the line of a diff.
-}

module GI.Ggit.Structs.DiffLine
    ( 

-- * Exported types
    DiffLine(..)                            ,
    noDiffLine                              ,


 -- * Methods
-- ** getContent #method:getContent#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    DiffLineGetContentMethodInfo            ,
#endif
    diffLineGetContent                      ,


-- ** getContentOffset #method:getContentOffset#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    DiffLineGetContentOffsetMethodInfo      ,
#endif
    diffLineGetContentOffset                ,


-- ** getNewLineno #method:getNewLineno#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    DiffLineGetNewLinenoMethodInfo          ,
#endif
    diffLineGetNewLineno                    ,


-- ** getOldLineno #method:getOldLineno#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    DiffLineGetOldLinenoMethodInfo          ,
#endif
    diffLineGetOldLineno                    ,


-- ** getOrigin #method:getOrigin#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    DiffLineGetOriginMethodInfo             ,
#endif
    diffLineGetOrigin                       ,


-- ** getText #method:getText#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    DiffLineGetTextMethodInfo               ,
#endif
    diffLineGetText                         ,


-- ** ref #method:ref#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    DiffLineRefMethodInfo                   ,
#endif
    diffLineRef                             ,


-- ** unref #method:unref#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    DiffLineUnrefMethodInfo                 ,
#endif
    diffLineUnref                           ,




    ) 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.GError as B.GError
import qualified Data.GI.Base.GVariant as B.GVariant
import qualified Data.GI.Base.GParamSpec as B.GParamSpec
import qualified Data.GI.Base.CallStack as B.CallStack
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 {-# SOURCE #-} qualified GI.Ggit.Enums as Ggit.Enums

newtype DiffLine = DiffLine (ManagedPtr DiffLine)
foreign import ccall "ggit_diff_line_get_type" c_ggit_diff_line_get_type :: 
    IO GType

instance BoxedObject DiffLine where
    boxedType _ = c_ggit_diff_line_get_type

noDiffLine :: Maybe DiffLine
noDiffLine = Nothing


#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
instance O.HasAttributeList DiffLine
type instance O.AttributeList DiffLine = DiffLineAttributeList
type DiffLineAttributeList = ('[ ] :: [(Symbol, *)])
#endif

-- method DiffLine::get_content
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "line", argType = TInterface (Name {namespace = "Ggit", name = "DiffLine"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitDiffLine.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "length", argType = TBasicType TUInt64, direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the number of returned bytes.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferEverything}]
-- Lengths : [Arg {argCName = "length", argType = TBasicType TUInt64, direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the number of returned bytes.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferEverything}]
-- returnType : Just (TCArray False (-1) 1 (TBasicType TUInt8))
-- throws : False
-- Skip return : False

foreign import ccall "ggit_diff_line_get_content" ggit_diff_line_get_content :: 
    Ptr DiffLine ->                         -- line : TInterface (Name {namespace = "Ggit", name = "DiffLine"})
    Ptr Word64 ->                           -- length : TBasicType TUInt64
    IO (Ptr Word8)

{- |
Gets the content in bytes.
-}
diffLineGetContent ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    DiffLine
    {- ^ /@line@/: a 'GI.Ggit.Structs.DiffLine.DiffLine'. -}
    -> m ByteString
    {- ^ __Returns:__ the content in bytes. -}
diffLineGetContent line = liftIO $ do
    line' <- unsafeManagedPtrGetPtr line
    length_ <- allocMem :: IO (Ptr Word64)
    result <- ggit_diff_line_get_content line' length_
    length_' <- peek length_
    checkUnexpectedReturnNULL "diffLineGetContent" result
    result' <- (unpackByteStringWithLength length_') result
    touchManagedPtr line
    freeMem length_
    return result'

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data DiffLineGetContentMethodInfo
instance (signature ~ (m ByteString), MonadIO m) => O.MethodInfo DiffLineGetContentMethodInfo DiffLine signature where
    overloadedMethod _ = diffLineGetContent

#endif

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

foreign import ccall "ggit_diff_line_get_content_offset" ggit_diff_line_get_content_offset :: 
    Ptr DiffLine ->                         -- line : TInterface (Name {namespace = "Ggit", name = "DiffLine"})
    IO Int64

{- |
Gets the content offset.
-}
diffLineGetContentOffset ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    DiffLine
    {- ^ /@line@/: a 'GI.Ggit.Structs.DiffLine.DiffLine'. -}
    -> m Int64
    {- ^ __Returns:__ the content offset. -}
diffLineGetContentOffset line = liftIO $ do
    line' <- unsafeManagedPtrGetPtr line
    result <- ggit_diff_line_get_content_offset line'
    touchManagedPtr line
    return result

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data DiffLineGetContentOffsetMethodInfo
instance (signature ~ (m Int64), MonadIO m) => O.MethodInfo DiffLineGetContentOffsetMethodInfo DiffLine signature where
    overloadedMethod _ = diffLineGetContentOffset

#endif

-- method DiffLine::get_new_lineno
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "line", argType = TInterface (Name {namespace = "Ggit", name = "DiffLine"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitDiffLine.", 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_diff_line_get_new_lineno" ggit_diff_line_get_new_lineno :: 
    Ptr DiffLine ->                         -- line : TInterface (Name {namespace = "Ggit", name = "DiffLine"})
    IO Int32

{- |
Gets the Line number in new file or -1 for deleted line.
-}
diffLineGetNewLineno ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    DiffLine
    {- ^ /@line@/: a 'GI.Ggit.Structs.DiffLine.DiffLine'. -}
    -> m Int32
    {- ^ __Returns:__ the line\'s old number of lines. -}
diffLineGetNewLineno line = liftIO $ do
    line' <- unsafeManagedPtrGetPtr line
    result <- ggit_diff_line_get_new_lineno line'
    touchManagedPtr line
    return result

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data DiffLineGetNewLinenoMethodInfo
instance (signature ~ (m Int32), MonadIO m) => O.MethodInfo DiffLineGetNewLinenoMethodInfo DiffLine signature where
    overloadedMethod _ = diffLineGetNewLineno

#endif

-- method DiffLine::get_old_lineno
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "line", argType = TInterface (Name {namespace = "Ggit", name = "DiffLine"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitDiffLine.", 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_diff_line_get_old_lineno" ggit_diff_line_get_old_lineno :: 
    Ptr DiffLine ->                         -- line : TInterface (Name {namespace = "Ggit", name = "DiffLine"})
    IO Int32

{- |
Gets the line number in old file or -1 for added line.
-}
diffLineGetOldLineno ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    DiffLine
    {- ^ /@line@/: a 'GI.Ggit.Structs.DiffLine.DiffLine'. -}
    -> m Int32
    {- ^ __Returns:__ the line\'s old line number. -}
diffLineGetOldLineno line = liftIO $ do
    line' <- unsafeManagedPtrGetPtr line
    result <- ggit_diff_line_get_old_lineno line'
    touchManagedPtr line
    return result

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data DiffLineGetOldLinenoMethodInfo
instance (signature ~ (m Int32), MonadIO m) => O.MethodInfo DiffLineGetOldLinenoMethodInfo DiffLine signature where
    overloadedMethod _ = diffLineGetOldLineno

#endif

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

foreign import ccall "ggit_diff_line_get_origin" ggit_diff_line_get_origin :: 
    Ptr DiffLine ->                         -- line : TInterface (Name {namespace = "Ggit", name = "DiffLine"})
    IO CUInt

{- |
Gets the 'GI.Ggit.Enums.DiffLineType' value.
-}
diffLineGetOrigin ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    DiffLine
    {- ^ /@line@/: a 'GI.Ggit.Structs.DiffLine.DiffLine'. -}
    -> m Ggit.Enums.DiffLineType
    {- ^ __Returns:__ the 'GI.Ggit.Enums.DiffLineType' value. -}
diffLineGetOrigin line = liftIO $ do
    line' <- unsafeManagedPtrGetPtr line
    result <- ggit_diff_line_get_origin line'
    let result' = (toEnum . fromIntegral) result
    touchManagedPtr line
    return result'

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data DiffLineGetOriginMethodInfo
instance (signature ~ (m Ggit.Enums.DiffLineType), MonadIO m) => O.MethodInfo DiffLineGetOriginMethodInfo DiffLine signature where
    overloadedMethod _ = diffLineGetOrigin

#endif

-- method DiffLine::get_text
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "line", argType = TInterface (Name {namespace = "Ggit", name = "DiffLine"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitDiffLine.", 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_diff_line_get_text" ggit_diff_line_get_text :: 
    Ptr DiffLine ->                         -- line : TInterface (Name {namespace = "Ggit", name = "DiffLine"})
    IO CString

{- |
Get the content of the diff line as UTF-8 encoded text.
-}
diffLineGetText ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    DiffLine
    {- ^ /@line@/: a 'GI.Ggit.Structs.DiffLine.DiffLine'. -}
    -> m T.Text
    {- ^ __Returns:__ the content in utf-8 encoding. -}
diffLineGetText line = liftIO $ do
    line' <- unsafeManagedPtrGetPtr line
    result <- ggit_diff_line_get_text line'
    checkUnexpectedReturnNULL "diffLineGetText" result
    result' <- cstringToText result
    touchManagedPtr line
    return result'

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data DiffLineGetTextMethodInfo
instance (signature ~ (m T.Text), MonadIO m) => O.MethodInfo DiffLineGetTextMethodInfo DiffLine signature where
    overloadedMethod _ = diffLineGetText

#endif

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

foreign import ccall "ggit_diff_line_ref" ggit_diff_line_ref :: 
    Ptr DiffLine ->                         -- line : TInterface (Name {namespace = "Ggit", name = "DiffLine"})
    IO (Ptr DiffLine)

{- |
Atomically increments the reference count of /@line@/ by one.
This function is MT-safe and may be called from any thread.
-}
diffLineRef ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    DiffLine
    {- ^ /@line@/: a 'GI.Ggit.Structs.DiffLine.DiffLine'. -}
    -> m DiffLine
    {- ^ __Returns:__ a 'GI.Ggit.Structs.DiffLine.DiffLine'. -}
diffLineRef line = liftIO $ do
    line' <- unsafeManagedPtrGetPtr line
    result <- ggit_diff_line_ref line'
    checkUnexpectedReturnNULL "diffLineRef" result
    result' <- (wrapBoxed DiffLine) result
    touchManagedPtr line
    return result'

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data DiffLineRefMethodInfo
instance (signature ~ (m DiffLine), MonadIO m) => O.MethodInfo DiffLineRefMethodInfo DiffLine signature where
    overloadedMethod _ = diffLineRef

#endif

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

foreign import ccall "ggit_diff_line_unref" ggit_diff_line_unref :: 
    Ptr DiffLine ->                         -- line : TInterface (Name {namespace = "Ggit", name = "DiffLine"})
    IO ()

{- |
Atomically decrements the reference count of /@line@/ by one.
If the reference count drops to 0, /@line@/ is freed.
-}
diffLineUnref ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    DiffLine
    {- ^ /@line@/: a 'GI.Ggit.Structs.DiffLine.DiffLine'. -}
    -> m ()
diffLineUnref line = liftIO $ do
    line' <- unsafeManagedPtrGetPtr line
    ggit_diff_line_unref line'
    touchManagedPtr line
    return ()

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data DiffLineUnrefMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.MethodInfo DiffLineUnrefMethodInfo DiffLine signature where
    overloadedMethod _ = diffLineUnref

#endif

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
type family ResolveDiffLineMethod (t :: Symbol) (o :: *) :: * where
    ResolveDiffLineMethod "ref" o = DiffLineRefMethodInfo
    ResolveDiffLineMethod "unref" o = DiffLineUnrefMethodInfo
    ResolveDiffLineMethod "getContent" o = DiffLineGetContentMethodInfo
    ResolveDiffLineMethod "getContentOffset" o = DiffLineGetContentOffsetMethodInfo
    ResolveDiffLineMethod "getNewLineno" o = DiffLineGetNewLinenoMethodInfo
    ResolveDiffLineMethod "getOldLineno" o = DiffLineGetOldLinenoMethodInfo
    ResolveDiffLineMethod "getOrigin" o = DiffLineGetOriginMethodInfo
    ResolveDiffLineMethod "getText" o = DiffLineGetTextMethodInfo
    ResolveDiffLineMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveDiffLineMethod t DiffLine, O.MethodInfo info DiffLine p) => O.IsLabelProxy t (DiffLine -> p) where
    fromLabelProxy _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)

#if MIN_VERSION_base(4,9,0)
instance (info ~ ResolveDiffLineMethod t DiffLine, O.MethodInfo info DiffLine p) => O.IsLabel t (DiffLine -> 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

#endif