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

Structure used for scatter\/gather data input.
You generally pass in an array of @/GInputVectors/@
and the operation will store the read data starting in the
first buffer, switching to the next as needed.

/Since: 2.22/
-}

#define ENABLE_OVERLOADING \
       (!defined(__HADDOCK_VERSION__))

module GI.Gio.Structs.InputVector
    ( 

-- * Exported types
    InputVector(..)                         ,
    newZeroInputVector                      ,
    noInputVector                           ,


 -- * Properties
-- ** buffer #attr:buffer#
{- | Pointer to a buffer where data will be written.
-}
    clearInputVectorBuffer                  ,
    getInputVectorBuffer                    ,
#if ENABLE_OVERLOADING
    inputVector_buffer                      ,
#endif
    setInputVectorBuffer                    ,


-- ** size #attr:size#
{- | the available size in /@buffer@/.
-}
    getInputVectorSize                      ,
#if ENABLE_OVERLOADING
    inputVector_size                        ,
#endif
    setInputVectorSize                      ,




    ) 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.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.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map
import qualified Foreign.Ptr as FP


-- | Memory-managed wrapper type.
newtype InputVector = InputVector (ManagedPtr InputVector)
instance WrappedPtr InputVector where
    wrappedPtrCalloc :: IO (Ptr InputVector)
wrappedPtrCalloc = Int -> IO (Ptr InputVector)
forall a. Int -> IO (Ptr a)
callocBytes 16
    wrappedPtrCopy :: InputVector -> IO InputVector
wrappedPtrCopy = \p :: InputVector
p -> InputVector
-> (Ptr InputVector -> IO InputVector) -> IO InputVector
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr InputVector
p (Int -> Ptr InputVector -> IO (Ptr InputVector)
forall a. WrappedPtr a => Int -> Ptr a -> IO (Ptr a)
copyBytes 16 (Ptr InputVector -> IO (Ptr InputVector))
-> (Ptr InputVector -> IO InputVector)
-> Ptr InputVector
-> IO InputVector
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> (ManagedPtr InputVector -> InputVector)
-> Ptr InputVector -> IO InputVector
forall a.
(HasCallStack, WrappedPtr a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
wrapPtr ManagedPtr InputVector -> InputVector
InputVector)
    wrappedPtrFree :: Maybe (FunPtr (Ptr InputVector -> IO ()))
wrappedPtrFree = FunPtr (Ptr InputVector -> IO ())
-> Maybe (FunPtr (Ptr InputVector -> IO ()))
forall a. a -> Maybe a
Just FunPtr (Ptr InputVector -> IO ())
forall a. FunPtr (Ptr a -> IO ())
ptr_to_g_free

-- | Construct a `InputVector` struct initialized to zero.
newZeroInputVector :: MonadIO m => m InputVector
newZeroInputVector :: m InputVector
newZeroInputVector = IO InputVector -> m InputVector
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO InputVector -> m InputVector)
-> IO InputVector -> m InputVector
forall a b. (a -> b) -> a -> b
$ IO (Ptr InputVector)
forall a. WrappedPtr a => IO (Ptr a)
wrappedPtrCalloc IO (Ptr InputVector)
-> (Ptr InputVector -> IO InputVector) -> IO InputVector
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (ManagedPtr InputVector -> InputVector)
-> Ptr InputVector -> IO InputVector
forall a.
(HasCallStack, WrappedPtr a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
wrapPtr ManagedPtr InputVector -> InputVector
InputVector

instance tag ~ 'AttrSet => Constructible InputVector tag where
    new :: (ManagedPtr InputVector -> InputVector)
-> [AttrOp InputVector tag] -> m InputVector
new _ attrs :: [AttrOp InputVector tag]
attrs = do
        InputVector
o <- m InputVector
forall (m :: * -> *). MonadIO m => m InputVector
newZeroInputVector
        InputVector -> [AttrOp InputVector 'AttrSet] -> m ()
forall o (m :: * -> *).
MonadIO m =>
o -> [AttrOp o 'AttrSet] -> m ()
GI.Attributes.set InputVector
o [AttrOp InputVector tag]
[AttrOp InputVector 'AttrSet]
attrs
        InputVector -> m InputVector
forall (m :: * -> *) a. Monad m => a -> m a
return InputVector
o


-- | A convenience alias for `Nothing` :: `Maybe` `InputVector`.
noInputVector :: Maybe InputVector
noInputVector :: Maybe InputVector
noInputVector = Maybe InputVector
forall a. Maybe a
Nothing

{- |
Get the value of the “@buffer@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.get' inputVector #buffer
@
-}
getInputVectorBuffer :: MonadIO m => InputVector -> m (Ptr ())
getInputVectorBuffer :: InputVector -> m (Ptr ())
getInputVectorBuffer s :: InputVector
s = IO (Ptr ()) -> m (Ptr ())
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Ptr ()) -> m (Ptr ())) -> IO (Ptr ()) -> m (Ptr ())
forall a b. (a -> b) -> a -> b
$ InputVector -> (Ptr InputVector -> IO (Ptr ())) -> IO (Ptr ())
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr InputVector
s ((Ptr InputVector -> IO (Ptr ())) -> IO (Ptr ()))
-> (Ptr InputVector -> IO (Ptr ())) -> IO (Ptr ())
forall a b. (a -> b) -> a -> b
$ \ptr :: Ptr InputVector
ptr -> do
    Ptr ()
val <- Ptr (Ptr ()) -> IO (Ptr ())
forall a. Storable a => Ptr a -> IO a
peek (Ptr InputVector
ptr Ptr InputVector -> Int -> Ptr (Ptr ())
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 0) :: IO (Ptr ())
    Ptr () -> IO (Ptr ())
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr ()
val

{- |
Set the value of the “@buffer@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.set' inputVector [ #buffer 'Data.GI.Base.Attributes.:=' value ]
@
-}
setInputVectorBuffer :: MonadIO m => InputVector -> Ptr () -> m ()
setInputVectorBuffer :: InputVector -> Ptr () -> m ()
setInputVectorBuffer s :: InputVector
s val :: Ptr ()
val = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ InputVector -> (Ptr InputVector -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr InputVector
s ((Ptr InputVector -> IO ()) -> IO ())
-> (Ptr InputVector -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \ptr :: Ptr InputVector
ptr -> do
    Ptr (Ptr ()) -> Ptr () -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (Ptr InputVector
ptr Ptr InputVector -> Int -> Ptr (Ptr ())
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 0) (Ptr ()
val :: Ptr ())

{- |
Set the value of the “@buffer@” field to `Nothing`.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.clear' #buffer
@
-}
clearInputVectorBuffer :: MonadIO m => InputVector -> m ()
clearInputVectorBuffer :: InputVector -> m ()
clearInputVectorBuffer s :: InputVector
s = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ InputVector -> (Ptr InputVector -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr InputVector
s ((Ptr InputVector -> IO ()) -> IO ())
-> (Ptr InputVector -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \ptr :: Ptr InputVector
ptr -> do
    Ptr (Ptr ()) -> Ptr () -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (Ptr InputVector
ptr Ptr InputVector -> Int -> Ptr (Ptr ())
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 0) (Ptr ()
forall a. Ptr a
FP.nullPtr :: Ptr ())

#if ENABLE_OVERLOADING
data InputVectorBufferFieldInfo
instance AttrInfo InputVectorBufferFieldInfo where
    type AttrAllowedOps InputVectorBufferFieldInfo = '[ 'AttrSet, 'AttrGet, 'AttrClear]
    type AttrSetTypeConstraint InputVectorBufferFieldInfo = (~) (Ptr ())
    type AttrBaseTypeConstraint InputVectorBufferFieldInfo = (~) InputVector
    type AttrGetType InputVectorBufferFieldInfo = Ptr ()
    type AttrLabel InputVectorBufferFieldInfo = "buffer"
    type AttrOrigin InputVectorBufferFieldInfo = InputVector
    attrGet _ = getInputVectorBuffer
    attrSet _ = setInputVectorBuffer
    attrConstruct = undefined
    attrClear _ = clearInputVectorBuffer

inputVector_buffer :: AttrLabelProxy "buffer"
inputVector_buffer = AttrLabelProxy

#endif


{- |
Get the value of the “@size@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.get' inputVector #size
@
-}
getInputVectorSize :: MonadIO m => InputVector -> m Word64
getInputVectorSize :: InputVector -> m Word64
getInputVectorSize s :: InputVector
s = IO Word64 -> m Word64
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Word64 -> m Word64) -> IO Word64 -> m Word64
forall a b. (a -> b) -> a -> b
$ InputVector -> (Ptr InputVector -> IO Word64) -> IO Word64
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr InputVector
s ((Ptr InputVector -> IO Word64) -> IO Word64)
-> (Ptr InputVector -> IO Word64) -> IO Word64
forall a b. (a -> b) -> a -> b
$ \ptr :: Ptr InputVector
ptr -> do
    Word64
val <- Ptr Word64 -> IO Word64
forall a. Storable a => Ptr a -> IO a
peek (Ptr InputVector
ptr Ptr InputVector -> Int -> Ptr Word64
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 8) :: IO Word64
    Word64 -> IO Word64
forall (m :: * -> *) a. Monad m => a -> m a
return Word64
val

{- |
Set the value of the “@size@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.set' inputVector [ #size 'Data.GI.Base.Attributes.:=' value ]
@
-}
setInputVectorSize :: MonadIO m => InputVector -> Word64 -> m ()
setInputVectorSize :: InputVector -> Word64 -> m ()
setInputVectorSize s :: InputVector
s val :: Word64
val = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ InputVector -> (Ptr InputVector -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr InputVector
s ((Ptr InputVector -> IO ()) -> IO ())
-> (Ptr InputVector -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \ptr :: Ptr InputVector
ptr -> do
    Ptr Word64 -> Word64 -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (Ptr InputVector
ptr Ptr InputVector -> Int -> Ptr Word64
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 8) (Word64
val :: Word64)

#if ENABLE_OVERLOADING
data InputVectorSizeFieldInfo
instance AttrInfo InputVectorSizeFieldInfo where
    type AttrAllowedOps InputVectorSizeFieldInfo = '[ 'AttrSet, 'AttrGet]
    type AttrSetTypeConstraint InputVectorSizeFieldInfo = (~) Word64
    type AttrBaseTypeConstraint InputVectorSizeFieldInfo = (~) InputVector
    type AttrGetType InputVectorSizeFieldInfo = Word64
    type AttrLabel InputVectorSizeFieldInfo = "size"
    type AttrOrigin InputVectorSizeFieldInfo = InputVector
    attrGet _ = getInputVectorSize
    attrSet _ = setInputVectorSize
    attrConstruct = undefined
    attrClear _ = undefined

inputVector_size :: AttrLabelProxy "size"
inputVector_size = AttrLabelProxy

#endif



#if ENABLE_OVERLOADING
instance O.HasAttributeList InputVector
type instance O.AttributeList InputVector = InputVectorAttributeList
type InputVectorAttributeList = ('[ '("buffer", InputVectorBufferFieldInfo), '("size", InputVectorSizeFieldInfo)] :: [(Symbol, *)])
#endif

#if ENABLE_OVERLOADING
type family ResolveInputVectorMethod (t :: Symbol) (o :: *) :: * where
    ResolveInputVectorMethod l o = O.MethodResolutionFailed l o

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

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