{-# LINE 1 "lib/CPython/Types/Set.chs" #-}
{-# LANGUAGE ForeignFunctionInterface #-}
module CPython.Types.Set
( AnySet
, Set
, FrozenSet
, setType
, frozenSetType
, toSet
, toFrozenSet
, iterableToSet
, iterableToFrozenSet
, fromSet
, size
, contains
, add
, discard
, pop
, clear
) where
import qualified Foreign.C.Types as C2HSImp
import qualified Foreign.Ptr as C2HSImp
import qualified System.IO.Unsafe as C2HSImp
import CPython.Internal
import CPython.Types.Tuple (toTuple, iterableToTuple, fromTuple)
class Object a => AnySet a
newtype Set = Set (ForeignPtr Set)
instance Object Set where
toObject :: Set -> SomeObject
toObject (Set x :: ForeignPtr Set
x) = ForeignPtr Set -> SomeObject
forall a. Object a => ForeignPtr a -> SomeObject
SomeObject ForeignPtr Set
x
fromForeignPtr :: ForeignPtr Set -> Set
fromForeignPtr = ForeignPtr Set -> Set
Set
instance Concrete Set where
concreteType :: Set -> Type
concreteType _ = Type
setType
newtype FrozenSet = FrozenSet (ForeignPtr FrozenSet)
instance Object FrozenSet where
toObject :: FrozenSet -> SomeObject
toObject (FrozenSet x :: ForeignPtr FrozenSet
x) = ForeignPtr FrozenSet -> SomeObject
forall a. Object a => ForeignPtr a -> SomeObject
SomeObject ForeignPtr FrozenSet
x
fromForeignPtr :: ForeignPtr FrozenSet -> FrozenSet
fromForeignPtr = ForeignPtr FrozenSet -> FrozenSet
FrozenSet
instance Concrete FrozenSet where
concreteType :: FrozenSet -> Type
concreteType _ = Type
frozenSetType
instance AnySet Set
instance AnySet FrozenSet
setType :: (Type)
setType =
C2HSImp.unsafePerformIO $
setType'_ >>= \res ->
peekStaticObject res >>= \res' :: Type
res' ->
Type -> IO Type
forall (m :: * -> *) a. Monad m => a -> m a
return (Type
res')
{-# LINE 71 "lib/CPython/Types/Set.chs" #-}
frozenSetType :: (Type)
frozenSetType =
C2HSImp.unsafePerformIO $
frozenSetType'_ >>= \res ->
peekStaticObject res >>= \res' ->
return (res')
{-# LINE 74 "lib/CPython/Types/Set.chs" #-}
toSet :: [SomeObject] -> IO Set
toSet xs = toTuple xs >>= iterableToSet
toFrozenSet :: [SomeObject] -> IO FrozenSet
toFrozenSet xs = toTuple xs >>= iterableToFrozenSet
iterableToSet :: Object obj => (obj) -> IO ((Set))
iterableToSet :: obj -> IO Set
iterableToSet a1 :: obj
a1 =
obj -> (Ptr () -> IO Set) -> IO Set
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject obj
a1 ((Ptr () -> IO Set) -> IO Set) -> (Ptr () -> IO Set) -> IO Set
forall a b. (a -> b) -> a -> b
$ \a1' :: Ptr ()
a1' ->
Ptr () -> IO (Ptr ())
iterableToSet'_ Ptr ()
a1' IO (Ptr ()) -> (Ptr () -> IO Set) -> IO Set
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res :: Ptr ()
res ->
Ptr () -> IO Set
forall obj a. Object obj => Ptr a -> IO obj
stealObject Ptr ()
res IO Set -> (Set -> IO Set) -> IO Set
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res' :: Set
res' ->
Set -> IO Set
forall (m :: * -> *) a. Monad m => a -> m a
return (Set
res')
{-# LINE 88 "lib/CPython/Types/Set.chs" #-}
iterableToFrozenSet :: Object obj => (obj) -> IO ((FrozenSet))
iterableToFrozenSet :: obj -> IO FrozenSet
iterableToFrozenSet a1 :: obj
a1 =
obj -> (Ptr () -> IO FrozenSet) -> IO FrozenSet
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject obj
a1 ((Ptr () -> IO FrozenSet) -> IO FrozenSet)
-> (Ptr () -> IO FrozenSet) -> IO FrozenSet
forall a b. (a -> b) -> a -> b
$ \a1' :: Ptr ()
a1' ->
Ptr () -> IO (Ptr ())
iterableToFrozenSet'_ Ptr ()
a1' IO (Ptr ()) -> (Ptr () -> IO FrozenSet) -> IO FrozenSet
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res :: Ptr ()
res ->
Ptr () -> IO FrozenSet
forall obj a. Object obj => Ptr a -> IO obj
stealObject Ptr ()
res IO FrozenSet -> (FrozenSet -> IO FrozenSet) -> IO FrozenSet
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res' :: FrozenSet
res' ->
FrozenSet -> IO FrozenSet
forall (m :: * -> *) a. Monad m => a -> m a
return (FrozenSet
res')
{-# LINE 96 "lib/CPython/Types/Set.chs" #-}
fromSet :: AnySet set => set -> IO [SomeObject]
fromSet set = iterableToTuple set >>= fromTuple
size :: AnySet set => (set) -> IO ((Integer))
size :: set -> IO Integer
size a1 :: set
a1 =
set -> (Ptr () -> IO Integer) -> IO Integer
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject set
a1 ((Ptr () -> IO Integer) -> IO Integer)
-> (Ptr () -> IO Integer) -> IO Integer
forall a b. (a -> b) -> a -> b
$ \a1' :: Ptr ()
a1' ->
Ptr () -> IO CLong
size'_ Ptr ()
a1' IO CLong -> (CLong -> IO Integer) -> IO Integer
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res :: CLong
res ->
CLong -> IO Integer
forall a. Integral a => a -> IO Integer
checkIntReturn CLong
res IO Integer -> (Integer -> IO Integer) -> IO Integer
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res' :: Integer
res' ->
Integer -> IO Integer
forall (m :: * -> *) a. Monad m => a -> m a
return (Integer
res')
{-# LINE 105 "lib/CPython/Types/Set.chs" #-}
contains :: (AnySet set, Object key) => (set) -> (key) -> IO ((Bool))
contains :: set -> key -> IO Bool
contains a1 :: set
a1 a2 :: key
a2 =
set -> (Ptr () -> IO Bool) -> IO Bool
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject set
a1 ((Ptr () -> IO Bool) -> IO Bool) -> (Ptr () -> IO Bool) -> IO Bool
forall a b. (a -> b) -> a -> b
$ \a1' :: Ptr ()
a1' ->
key -> (Ptr () -> IO Bool) -> IO Bool
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject key
a2 ((Ptr () -> IO Bool) -> IO Bool) -> (Ptr () -> IO Bool) -> IO Bool
forall a b. (a -> b) -> a -> b
$ \a2' :: Ptr ()
a2' ->
Ptr () -> Ptr () -> IO CInt
contains'_ Ptr ()
a1' Ptr ()
a2' IO CInt -> (CInt -> IO Bool) -> IO Bool
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res :: CInt
res ->
CInt -> IO Bool
checkBoolReturn CInt
res IO Bool -> (Bool -> IO Bool) -> IO Bool
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res' :: Bool
res' ->
Bool -> IO Bool
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool
res')
{-# LINE 115 "lib/CPython/Types/Set.chs" #-}
add :: (AnySet set, Object key) => set -> key -> IO ()
add :: set -> key -> IO ()
add = set -> key -> IO ()
forall set key. (AnySet set, Object key) => set -> key -> IO ()
c_add
c_add :: (AnySet set, Object key) => (set) -> (key) -> IO ((()))
c_add :: set -> key -> IO ()
c_add a1 :: set
a1 a2 :: key
a2 =
set -> (Ptr () -> IO ()) -> IO ()
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject set
a1 ((Ptr () -> IO ()) -> IO ()) -> (Ptr () -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \a1' :: Ptr ()
a1' ->
key -> (Ptr () -> IO ()) -> IO ()
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject key
a2 ((Ptr () -> IO ()) -> IO ()) -> (Ptr () -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \a2' :: Ptr ()
a2' ->
Ptr () -> Ptr () -> IO CInt
c_add'_ Ptr ()
a1' Ptr ()
a2' IO CInt -> (CInt -> IO ()) -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res :: CInt
res ->
CInt -> IO ()
checkStatusCode CInt
res IO () -> (() -> IO ()) -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res' :: ()
res' ->
() -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return (()
res')
{-# LINE 131 "lib/CPython/Types/Set.chs" #-}
discard :: Object key => (Set) -> (key) -> IO ((Bool))
discard :: Set -> key -> IO Bool
discard a1 :: Set
a1 a2 :: key
a2 =
Set -> (Ptr () -> IO Bool) -> IO Bool
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject Set
a1 ((Ptr () -> IO Bool) -> IO Bool) -> (Ptr () -> IO Bool) -> IO Bool
forall a b. (a -> b) -> a -> b
$ \a1' :: Ptr ()
a1' ->
key -> (Ptr () -> IO Bool) -> IO Bool
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject key
a2 ((Ptr () -> IO Bool) -> IO Bool) -> (Ptr () -> IO Bool) -> IO Bool
forall a b. (a -> b) -> a -> b
$ \a2' :: Ptr ()
a2' ->
Ptr () -> Ptr () -> IO CInt
discard'_ Ptr ()
a1' Ptr ()
a2' IO CInt -> (CInt -> IO Bool) -> IO Bool
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res :: CInt
res ->
CInt -> IO Bool
checkBoolReturn CInt
res IO Bool -> (Bool -> IO Bool) -> IO Bool
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res' :: Bool
res' ->
Bool -> IO Bool
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool
res')
{-# LINE 142 "lib/CPython/Types/Set.chs" #-}
pop :: (Set) -> IO ((SomeObject))
pop :: Set -> IO SomeObject
pop a1 :: Set
a1 =
Set -> (Ptr () -> IO SomeObject) -> IO SomeObject
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject Set
a1 ((Ptr () -> IO SomeObject) -> IO SomeObject)
-> (Ptr () -> IO SomeObject) -> IO SomeObject
forall a b. (a -> b) -> a -> b
$ \a1' :: Ptr ()
a1' ->
Ptr () -> IO (Ptr ())
pop'_ Ptr ()
a1' IO (Ptr ()) -> (Ptr () -> IO SomeObject) -> IO SomeObject
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res :: Ptr ()
res ->
Ptr () -> IO SomeObject
forall obj a. Object obj => Ptr a -> IO obj
stealObject Ptr ()
res IO SomeObject -> (SomeObject -> IO SomeObject) -> IO SomeObject
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res' :: SomeObject
res' ->
SomeObject -> IO SomeObject
forall (m :: * -> *) a. Monad m => a -> m a
return (SomeObject
res')
{-# LINE 148 "lib/CPython/Types/Set.chs" #-}
clear :: (Set) -> IO ((()))
clear a1 =
withObject a1 $ \a1' ->
clear'_ a1' >>= \res ->
checkStatusCode res >>= \res' ->
return (res')
{-# LINE 153 "lib/CPython/Types/Set.chs" #-}
foreign import ccall unsafe "CPython/Types/Set.chs.h hscpython_PySet_Type"
setType'_ :: (IO (C2HSImp.Ptr ()))
foreign import ccall unsafe "CPython/Types/Set.chs.h hscpython_PyFrozenSet_Type"
frozenSetType'_ :: (IO (C2HSImp.Ptr ()))
foreign import ccall safe "CPython/Types/Set.chs.h PySet_New"
iterableToSet'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))
foreign import ccall safe "CPython/Types/Set.chs.h PyFrozenSet_New"
iterableToFrozenSet'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))
foreign import ccall safe "CPython/Types/Set.chs.h PySet_Size"
size'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CLong))
foreign import ccall safe "CPython/Types/Set.chs.h PySet_Contains"
contains'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt)))
foreign import ccall safe "CPython/Types/Set.chs.h PySet_Add"
c_add'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt)))
foreign import ccall safe "CPython/Types/Set.chs.h PySet_Discard"
discard'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt)))
foreign import ccall safe "CPython/Types/Set.chs.h PySet_Pop"
pop'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))
foreign import ccall safe "CPython/Types/Set.chs.h PySet_Clear"
clear'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt))