{-# 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 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 x) = SomeObject x
fromForeignPtr = Set
instance Concrete Set where
concreteType _ = setType
newtype FrozenSet = FrozenSet (ForeignPtr FrozenSet)
instance Object FrozenSet where
toObject (FrozenSet x) = SomeObject x
fromForeignPtr = FrozenSet
instance Concrete FrozenSet where
concreteType _ = frozenSetType
instance AnySet Set
instance AnySet FrozenSet
setType :: (Type)
setType =
unsafePerformIO $
let {res = setType'_} in
peekStaticObject res >>= \res' ->
return (res')
{-# LINE 71 "lib/CPython/Types/Set.chs" #-}
frozenSetType :: (Type)
frozenSetType =
unsafePerformIO $
let {res = frozenSetType'_} in
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 a1 =
withObject a1 $ \a1' ->
iterableToSet'_ a1' >>= \res ->
stealObject res >>= \res' ->
return (res')
{-# LINE 88 "lib/CPython/Types/Set.chs" #-}
iterableToFrozenSet :: Object obj => (obj) -> IO ((FrozenSet))
iterableToFrozenSet a1 =
withObject a1 $ \a1' ->
iterableToFrozenSet'_ a1' >>= \res ->
stealObject res >>= \res' ->
return (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 a1 =
withObject a1 $ \a1' ->
size'_ a1' >>= \res ->
checkIntReturn res >>= \res' ->
return (res')
{-# LINE 105 "lib/CPython/Types/Set.chs" #-}
contains :: (AnySet set, Object key) => (set) -> (key) -> IO ((Bool))
contains a1 a2 =
withObject a1 $ \a1' ->
withObject a2 $ \a2' ->
contains'_ a1' a2' >>= \res ->
checkBoolReturn res >>= \res' ->
return (res')
{-# LINE 115 "lib/CPython/Types/Set.chs" #-}
add :: (AnySet set, Object key) => set -> key -> IO ()
add = c_add
c_add :: (AnySet set, Object key) => (set) -> (key) -> IO ((()))
c_add a1 a2 =
withObject a1 $ \a1' ->
withObject a2 $ \a2' ->
c_add'_ a1' a2' >>= \res ->
checkStatusCode res >>= \res' ->
return (res')
{-# LINE 131 "lib/CPython/Types/Set.chs" #-}
discard :: Object key => (Set) -> (key) -> IO ((Bool))
discard a1 a2 =
withObject a1 $ \a1' ->
withObject a2 $ \a2' ->
discard'_ a1' a2' >>= \res ->
checkBoolReturn res >>= \res' ->
return (res')
{-# LINE 142 "lib/CPython/Types/Set.chs" #-}
pop :: (Set) -> IO ((SomeObject))
pop a1 =
withObject a1 $ \a1' ->
pop'_ a1' >>= \res ->
stealObject res >>= \res' ->
return (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'_ :: (Ptr ())
foreign import ccall unsafe "CPython/Types/Set.chs.h hscpython_PyFrozenSet_Type"
frozenSetType'_ :: (Ptr ())
foreign import ccall safe "CPython/Types/Set.chs.h PySet_New"
iterableToSet'_ :: ((Ptr ()) -> (IO (Ptr ())))
foreign import ccall safe "CPython/Types/Set.chs.h PyFrozenSet_New"
iterableToFrozenSet'_ :: ((Ptr ()) -> (IO (Ptr ())))
foreign import ccall safe "CPython/Types/Set.chs.h PySet_Size"
size'_ :: ((Ptr ()) -> (IO CLong))
foreign import ccall safe "CPython/Types/Set.chs.h PySet_Contains"
contains'_ :: ((Ptr ()) -> ((Ptr ()) -> (IO CInt)))
foreign import ccall safe "CPython/Types/Set.chs.h PySet_Add"
c_add'_ :: ((Ptr ()) -> ((Ptr ()) -> (IO CInt)))
foreign import ccall safe "CPython/Types/Set.chs.h PySet_Discard"
discard'_ :: ((Ptr ()) -> ((Ptr ()) -> (IO CInt)))
foreign import ccall safe "CPython/Types/Set.chs.h PySet_Pop"
pop'_ :: ((Ptr ()) -> (IO (Ptr ())))
foreign import ccall safe "CPython/Types/Set.chs.h PySet_Clear"
clear'_ :: ((Ptr ()) -> (IO CInt))