{- | Copyright : Will Thompson, Iñaki García Etxebarria and Jonas Platte License : LGPL-2.1 Maintainer : Iñaki García Etxebarria (garetxe@gmail.com) The 'GI.GLib.Structs.Sequence.Sequence' struct is an opaque data type representing a [sequence][glib-Sequences] data type. -} module GI.GLib.Structs.Sequence ( -- * Exported types Sequence(..) , noSequence , -- * Methods -- ** free #method:free# #ifdef ENABLE_OVERLOADING SequenceFreeMethodInfo , #endif sequenceFree , -- ** get #method:get# sequenceGet , -- ** getLength #method:getLength# #ifdef ENABLE_OVERLOADING SequenceGetLengthMethodInfo , #endif sequenceGetLength , -- ** isEmpty #method:isEmpty# #ifdef ENABLE_OVERLOADING SequenceIsEmptyMethodInfo , #endif sequenceIsEmpty , -- ** move #method:move# sequenceMove , -- ** moveRange #method:moveRange# sequenceMoveRange , -- ** remove #method:remove# sequenceRemove , -- ** removeRange #method:removeRange# sequenceRemoveRange , -- ** set #method:set# sequenceSet , -- ** swap #method:swap# sequenceSwap , ) 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.GLib.Structs.SequenceIter as GLib.SequenceIter newtype Sequence = Sequence (ManagedPtr Sequence) -- XXX Wrapping a foreign struct/union with no known destructor or size, leak? instance WrappedPtr Sequence where wrappedPtrCalloc = return nullPtr wrappedPtrCopy = return wrappedPtrFree = Nothing noSequence :: Maybe Sequence noSequence = Nothing #ifdef ENABLE_OVERLOADING instance O.HasAttributeList Sequence type instance O.AttributeList Sequence = SequenceAttributeList type SequenceAttributeList = ('[ ] :: [(Symbol, *)]) #endif -- method Sequence::free -- method type : OrdinaryMethod -- Args : [Arg {argCName = "seq", argType = TInterface (Name {namespace = "GLib", name = "Sequence"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GSequence", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}] -- Lengths : [] -- returnType : Nothing -- throws : False -- Skip return : False foreign import ccall "g_sequence_free" g_sequence_free :: Ptr Sequence -> -- seq : TInterface (Name {namespace = "GLib", name = "Sequence"}) IO () {- | Frees the memory allocated for /@seq@/. If /@seq@/ has a data destroy function associated with it, that function is called on all items in /@seq@/. @since 2.14 -} sequenceFree :: (B.CallStack.HasCallStack, MonadIO m) => Sequence {- ^ /@seq@/: a 'GI.GLib.Structs.Sequence.Sequence' -} -> m () sequenceFree seq = liftIO $ do seq' <- unsafeManagedPtrGetPtr seq g_sequence_free seq' touchManagedPtr seq return () #ifdef ENABLE_OVERLOADING data SequenceFreeMethodInfo instance (signature ~ (m ()), MonadIO m) => O.MethodInfo SequenceFreeMethodInfo Sequence signature where overloadedMethod _ = sequenceFree #endif -- method Sequence::get_length -- method type : OrdinaryMethod -- Args : [Arg {argCName = "seq", argType = TInterface (Name {namespace = "GLib", name = "Sequence"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GSequence", 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 "g_sequence_get_length" g_sequence_get_length :: Ptr Sequence -> -- seq : TInterface (Name {namespace = "GLib", name = "Sequence"}) IO Int32 {- | Returns the length of /@seq@/. Note that this method is O(h) where \`h\' is the height of the tree. It is thus more efficient to use 'GI.GLib.Structs.Sequence.sequenceIsEmpty' when comparing the length to zero. @since 2.14 -} sequenceGetLength :: (B.CallStack.HasCallStack, MonadIO m) => Sequence {- ^ /@seq@/: a 'GI.GLib.Structs.Sequence.Sequence' -} -> m Int32 {- ^ __Returns:__ the length of /@seq@/ -} sequenceGetLength seq = liftIO $ do seq' <- unsafeManagedPtrGetPtr seq result <- g_sequence_get_length seq' touchManagedPtr seq return result #ifdef ENABLE_OVERLOADING data SequenceGetLengthMethodInfo instance (signature ~ (m Int32), MonadIO m) => O.MethodInfo SequenceGetLengthMethodInfo Sequence signature where overloadedMethod _ = sequenceGetLength #endif -- method Sequence::is_empty -- method type : OrdinaryMethod -- Args : [Arg {argCName = "seq", argType = TInterface (Name {namespace = "GLib", name = "Sequence"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GSequence", 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 "g_sequence_is_empty" g_sequence_is_empty :: Ptr Sequence -> -- seq : TInterface (Name {namespace = "GLib", name = "Sequence"}) IO CInt {- | Returns 'True' if the sequence contains zero items. This function is functionally identical to checking the result of 'GI.GLib.Structs.Sequence.sequenceGetLength' being equal to zero. However this function is implemented in O(1) running time. @since 2.48 -} sequenceIsEmpty :: (B.CallStack.HasCallStack, MonadIO m) => Sequence {- ^ /@seq@/: a 'GI.GLib.Structs.Sequence.Sequence' -} -> m Bool {- ^ __Returns:__ 'True' if the sequence is empty, otherwise 'False'. -} sequenceIsEmpty seq = liftIO $ do seq' <- unsafeManagedPtrGetPtr seq result <- g_sequence_is_empty seq' let result' = (/= 0) result touchManagedPtr seq return result' #ifdef ENABLE_OVERLOADING data SequenceIsEmptyMethodInfo instance (signature ~ (m Bool), MonadIO m) => O.MethodInfo SequenceIsEmptyMethodInfo Sequence signature where overloadedMethod _ = sequenceIsEmpty #endif -- method Sequence::get -- method type : MemberFunction -- Args : [Arg {argCName = "iter", argType = TInterface (Name {namespace = "GLib", name = "SequenceIter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GSequenceIter", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}] -- Lengths : [] -- returnType : Just (TBasicType TPtr) -- throws : False -- Skip return : False foreign import ccall "g_sequence_get" g_sequence_get :: Ptr GLib.SequenceIter.SequenceIter -> -- iter : TInterface (Name {namespace = "GLib", name = "SequenceIter"}) IO (Ptr ()) {- | Returns the data that /@iter@/ points to. @since 2.14 -} sequenceGet :: (B.CallStack.HasCallStack, MonadIO m) => GLib.SequenceIter.SequenceIter {- ^ /@iter@/: a 'GI.GLib.Structs.SequenceIter.SequenceIter' -} -> m (Ptr ()) {- ^ __Returns:__ the data that /@iter@/ points to -} sequenceGet iter = liftIO $ do iter' <- unsafeManagedPtrGetPtr iter result <- g_sequence_get iter' touchManagedPtr iter return result #ifdef ENABLE_OVERLOADING #endif -- method Sequence::move -- method type : MemberFunction -- Args : [Arg {argCName = "src", argType = TInterface (Name {namespace = "GLib", name = "SequenceIter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GSequenceIter pointing to the item to move", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "dest", argType = TInterface (Name {namespace = "GLib", name = "SequenceIter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GSequenceIter pointing to the position to which\n the item is moved", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}] -- Lengths : [] -- returnType : Nothing -- throws : False -- Skip return : False foreign import ccall "g_sequence_move" g_sequence_move :: Ptr GLib.SequenceIter.SequenceIter -> -- src : TInterface (Name {namespace = "GLib", name = "SequenceIter"}) Ptr GLib.SequenceIter.SequenceIter -> -- dest : TInterface (Name {namespace = "GLib", name = "SequenceIter"}) IO () {- | Moves the item pointed to by /@src@/ to the position indicated by /@dest@/. After calling this function /@dest@/ will point to the position immediately after /@src@/. It is allowed for /@src@/ and /@dest@/ to point into different sequences. @since 2.14 -} sequenceMove :: (B.CallStack.HasCallStack, MonadIO m) => GLib.SequenceIter.SequenceIter {- ^ /@src@/: a 'GI.GLib.Structs.SequenceIter.SequenceIter' pointing to the item to move -} -> GLib.SequenceIter.SequenceIter {- ^ /@dest@/: a 'GI.GLib.Structs.SequenceIter.SequenceIter' pointing to the position to which the item is moved -} -> m () sequenceMove src dest = liftIO $ do src' <- unsafeManagedPtrGetPtr src dest' <- unsafeManagedPtrGetPtr dest g_sequence_move src' dest' touchManagedPtr src touchManagedPtr dest return () #ifdef ENABLE_OVERLOADING #endif -- method Sequence::move_range -- method type : MemberFunction -- Args : [Arg {argCName = "dest", argType = TInterface (Name {namespace = "GLib", name = "SequenceIter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GSequenceIter", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "begin", argType = TInterface (Name {namespace = "GLib", name = "SequenceIter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GSequenceIter", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "end", argType = TInterface (Name {namespace = "GLib", name = "SequenceIter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GSequenceIter", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}] -- Lengths : [] -- returnType : Nothing -- throws : False -- Skip return : False foreign import ccall "g_sequence_move_range" g_sequence_move_range :: Ptr GLib.SequenceIter.SequenceIter -> -- dest : TInterface (Name {namespace = "GLib", name = "SequenceIter"}) Ptr GLib.SequenceIter.SequenceIter -> -- begin : TInterface (Name {namespace = "GLib", name = "SequenceIter"}) Ptr GLib.SequenceIter.SequenceIter -> -- end : TInterface (Name {namespace = "GLib", name = "SequenceIter"}) IO () {- | Inserts the (/@begin@/, /@end@/) range at the destination pointed to by ptr. The /@begin@/ and /@end@/ iters must point into the same sequence. It is allowed for /@dest@/ to point to a different sequence than the one pointed into by /@begin@/ and /@end@/. If /@dest@/ is NULL, the range indicated by /@begin@/ and /@end@/ is removed from the sequence. If /@dest@/ iter points to a place within the (/@begin@/, /@end@/) range, the range does not move. @since 2.14 -} sequenceMoveRange :: (B.CallStack.HasCallStack, MonadIO m) => GLib.SequenceIter.SequenceIter {- ^ /@dest@/: a 'GI.GLib.Structs.SequenceIter.SequenceIter' -} -> GLib.SequenceIter.SequenceIter {- ^ /@begin@/: a 'GI.GLib.Structs.SequenceIter.SequenceIter' -} -> GLib.SequenceIter.SequenceIter {- ^ /@end@/: a 'GI.GLib.Structs.SequenceIter.SequenceIter' -} -> m () sequenceMoveRange dest begin end = liftIO $ do dest' <- unsafeManagedPtrGetPtr dest begin' <- unsafeManagedPtrGetPtr begin end' <- unsafeManagedPtrGetPtr end g_sequence_move_range dest' begin' end' touchManagedPtr dest touchManagedPtr begin touchManagedPtr end return () #ifdef ENABLE_OVERLOADING #endif -- method Sequence::remove -- method type : MemberFunction -- Args : [Arg {argCName = "iter", argType = TInterface (Name {namespace = "GLib", name = "SequenceIter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GSequenceIter", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}] -- Lengths : [] -- returnType : Nothing -- throws : False -- Skip return : False foreign import ccall "g_sequence_remove" g_sequence_remove :: Ptr GLib.SequenceIter.SequenceIter -> -- iter : TInterface (Name {namespace = "GLib", name = "SequenceIter"}) IO () {- | Removes the item pointed to by /@iter@/. It is an error to pass the end iterator to this function. If the sequence has a data destroy function associated with it, this function is called on the data for the removed item. @since 2.14 -} sequenceRemove :: (B.CallStack.HasCallStack, MonadIO m) => GLib.SequenceIter.SequenceIter {- ^ /@iter@/: a 'GI.GLib.Structs.SequenceIter.SequenceIter' -} -> m () sequenceRemove iter = liftIO $ do iter' <- unsafeManagedPtrGetPtr iter g_sequence_remove iter' touchManagedPtr iter return () #ifdef ENABLE_OVERLOADING #endif -- method Sequence::remove_range -- method type : MemberFunction -- Args : [Arg {argCName = "begin", argType = TInterface (Name {namespace = "GLib", name = "SequenceIter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GSequenceIter", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "end", argType = TInterface (Name {namespace = "GLib", name = "SequenceIter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GSequenceIter", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}] -- Lengths : [] -- returnType : Nothing -- throws : False -- Skip return : False foreign import ccall "g_sequence_remove_range" g_sequence_remove_range :: Ptr GLib.SequenceIter.SequenceIter -> -- begin : TInterface (Name {namespace = "GLib", name = "SequenceIter"}) Ptr GLib.SequenceIter.SequenceIter -> -- end : TInterface (Name {namespace = "GLib", name = "SequenceIter"}) IO () {- | Removes all items in the (/@begin@/, /@end@/) range. If the sequence has a data destroy function associated with it, this function is called on the data for the removed items. @since 2.14 -} sequenceRemoveRange :: (B.CallStack.HasCallStack, MonadIO m) => GLib.SequenceIter.SequenceIter {- ^ /@begin@/: a 'GI.GLib.Structs.SequenceIter.SequenceIter' -} -> GLib.SequenceIter.SequenceIter {- ^ /@end@/: a 'GI.GLib.Structs.SequenceIter.SequenceIter' -} -> m () sequenceRemoveRange begin end = liftIO $ do begin' <- unsafeManagedPtrGetPtr begin end' <- unsafeManagedPtrGetPtr end g_sequence_remove_range begin' end' touchManagedPtr begin touchManagedPtr end return () #ifdef ENABLE_OVERLOADING #endif -- method Sequence::set -- method type : MemberFunction -- Args : [Arg {argCName = "iter", argType = TInterface (Name {namespace = "GLib", name = "SequenceIter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GSequenceIter", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "data", argType = TBasicType TPtr, direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "new data for the item", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}] -- Lengths : [] -- returnType : Nothing -- throws : False -- Skip return : False foreign import ccall "g_sequence_set" g_sequence_set :: Ptr GLib.SequenceIter.SequenceIter -> -- iter : TInterface (Name {namespace = "GLib", name = "SequenceIter"}) Ptr () -> -- data : TBasicType TPtr IO () {- | Changes the data for the item pointed to by /@iter@/ to be /@data@/. If the sequence has a data destroy function associated with it, that function is called on the existing data that /@iter@/ pointed to. @since 2.14 -} sequenceSet :: (B.CallStack.HasCallStack, MonadIO m) => GLib.SequenceIter.SequenceIter {- ^ /@iter@/: a 'GI.GLib.Structs.SequenceIter.SequenceIter' -} -> Ptr () {- ^ /@data@/: new data for the item -} -> m () sequenceSet iter data_ = liftIO $ do iter' <- unsafeManagedPtrGetPtr iter g_sequence_set iter' data_ touchManagedPtr iter return () #ifdef ENABLE_OVERLOADING #endif -- method Sequence::swap -- method type : MemberFunction -- Args : [Arg {argCName = "a", argType = TInterface (Name {namespace = "GLib", name = "SequenceIter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GSequenceIter", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "b", argType = TInterface (Name {namespace = "GLib", name = "SequenceIter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GSequenceIter", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}] -- Lengths : [] -- returnType : Nothing -- throws : False -- Skip return : False foreign import ccall "g_sequence_swap" g_sequence_swap :: Ptr GLib.SequenceIter.SequenceIter -> -- a : TInterface (Name {namespace = "GLib", name = "SequenceIter"}) Ptr GLib.SequenceIter.SequenceIter -> -- b : TInterface (Name {namespace = "GLib", name = "SequenceIter"}) IO () {- | Swaps the items pointed to by /@a@/ and /@b@/. It is allowed for /@a@/ and /@b@/ to point into difference sequences. @since 2.14 -} sequenceSwap :: (B.CallStack.HasCallStack, MonadIO m) => GLib.SequenceIter.SequenceIter {- ^ /@a@/: a 'GI.GLib.Structs.SequenceIter.SequenceIter' -} -> GLib.SequenceIter.SequenceIter {- ^ /@b@/: a 'GI.GLib.Structs.SequenceIter.SequenceIter' -} -> m () sequenceSwap a b = liftIO $ do a' <- unsafeManagedPtrGetPtr a b' <- unsafeManagedPtrGetPtr b g_sequence_swap a' b' touchManagedPtr a touchManagedPtr b return () #ifdef ENABLE_OVERLOADING #endif #ifdef ENABLE_OVERLOADING type family ResolveSequenceMethod (t :: Symbol) (o :: *) :: * where ResolveSequenceMethod "free" o = SequenceFreeMethodInfo ResolveSequenceMethod "isEmpty" o = SequenceIsEmptyMethodInfo ResolveSequenceMethod "getLength" o = SequenceGetLengthMethodInfo ResolveSequenceMethod l o = O.MethodResolutionFailed l o instance (info ~ ResolveSequenceMethod t Sequence, O.MethodInfo info Sequence p) => O.IsLabelProxy t (Sequence -> p) where fromLabelProxy _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info) #if MIN_VERSION_base(4,9,0) instance (info ~ ResolveSequenceMethod t Sequence, O.MethodInfo info Sequence p) => O.IsLabel t (Sequence -> 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