{-# LINE 1 "Data/GI/Base/BasicTypes.hsc" #-}
{-# LANGUAGE ConstraintKinds, FlexibleContexts, FlexibleInstances,
DeriveDataTypeable, TypeFamilies, ScopedTypeVariables,
MultiParamTypeClasses, DataKinds, TypeOperators, UndecidableInstances,
AllowAmbiguousTypes #-}
module Data.GI.Base.BasicTypes
(
ManagedPtr(..)
, ManagedPtrNewtype(..)
, BoxedPtr(..)
, CallocPtr(..)
, UnexpectedNullPointerReturn(..)
, TypedObject(..)
, GObject
, GType(..)
, CGType
, gtypeName
, GVariant(..)
, GBoxed
, BoxedEnum
, BoxedFlags
, GParamSpec(..)
, noGParamSpec
, GArray(..)
, GPtrArray(..)
, GByteArray(..)
, GHashTable(..)
, GList(..)
, g_list_free
, GSList(..)
, g_slist_free
, IsGFlag
, PtrWrapped(..)
, GDestroyNotify
) where
import Control.Exception (Exception)
import Data.Coerce (coerce, Coercible)
import Data.IORef (IORef)
import qualified Data.Text as T
import Data.Typeable (Typeable)
import Data.Word
import Foreign.C (CString, peekCString)
import Foreign.Ptr (Ptr, FunPtr)
import Foreign.ForeignPtr (ForeignPtr)
import Data.GI.Base.CallStack (CallStack)
import {-# SOURCE #-} Data.GI.Base.Overloading (HasParentTypes)
data ManagedPtr a = ManagedPtr {
ManagedPtr a -> ForeignPtr a
managedForeignPtr :: ForeignPtr a
, ManagedPtr a -> Maybe CallStack
managedPtrAllocCallStack :: Maybe CallStack
, ManagedPtr a -> IORef (Maybe CallStack)
managedPtrIsDisowned :: IORef (Maybe CallStack)
}
instance Eq (ManagedPtr a) where
ManagedPtr a
a == :: ManagedPtr a -> ManagedPtr a -> Bool
== ManagedPtr a
b = ManagedPtr a -> ForeignPtr a
forall a. ManagedPtr a -> ForeignPtr a
managedForeignPtr ManagedPtr a
a ForeignPtr a -> ForeignPtr a -> Bool
forall a. Eq a => a -> a -> Bool
== ManagedPtr a -> ForeignPtr a
forall a. ManagedPtr a -> ForeignPtr a
managedForeignPtr ManagedPtr a
b
class Coercible a (ManagedPtr ()) => ManagedPtrNewtype a where
toManagedPtr :: a -> ManagedPtr a
instance {-# OVERLAPPABLE #-} Coercible a (ManagedPtr ()) => ManagedPtrNewtype a where
toManagedPtr :: a -> ManagedPtr a
toManagedPtr = a -> ManagedPtr a
coerce
class ManagedPtrNewtype a => BoxedPtr a where
boxedPtrCopy :: a -> IO a
boxedPtrFree :: a -> IO ()
class BoxedPtr a => CallocPtr a where
boxedPtrCalloc :: IO (Ptr a)
class HasParentTypes a => TypedObject a where
glibType :: IO GType
class (ManagedPtrNewtype a, TypedObject a) => GBoxed a
class (ManagedPtrNewtype a, TypedObject a) => GObject a
class TypedObject a => BoxedEnum a
class TypedObject a => BoxedFlags a
type CGType = Word64
{-# LINE 142 "Data/GI/Base/BasicTypes.hsc" #-}
newtype GType = GType {GType -> CGType
gtypeToCGType :: CGType}
deriving (GType -> GType -> Bool
(GType -> GType -> Bool) -> (GType -> GType -> Bool) -> Eq GType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GType -> GType -> Bool
$c/= :: GType -> GType -> Bool
== :: GType -> GType -> Bool
$c== :: GType -> GType -> Bool
Eq, Int -> GType -> ShowS
[GType] -> ShowS
GType -> String
(Int -> GType -> ShowS)
-> (GType -> String) -> ([GType] -> ShowS) -> Show GType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GType] -> ShowS
$cshowList :: [GType] -> ShowS
show :: GType -> String
$cshow :: GType -> String
showsPrec :: Int -> GType -> ShowS
$cshowsPrec :: Int -> GType -> ShowS
Show)
foreign import ccall "g_type_name" g_type_name :: GType -> IO CString
gtypeName :: GType -> IO String
gtypeName :: GType -> IO String
gtypeName GType
gtype = GType -> IO CString
g_type_name GType
gtype IO CString -> (CString -> IO String) -> IO String
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= CString -> IO String
peekCString
data UnexpectedNullPointerReturn =
UnexpectedNullPointerReturn { UnexpectedNullPointerReturn -> Text
nullPtrErrorMsg :: T.Text }
deriving (Typeable)
instance Show UnexpectedNullPointerReturn where
show :: UnexpectedNullPointerReturn -> String
show UnexpectedNullPointerReturn
r = Text -> String
T.unpack (UnexpectedNullPointerReturn -> Text
nullPtrErrorMsg UnexpectedNullPointerReturn
r)
instance Exception UnexpectedNullPointerReturn
newtype GVariant = GVariant (ManagedPtr GVariant)
newtype GParamSpec = GParamSpec (ManagedPtr GParamSpec)
noGParamSpec :: Maybe GParamSpec
noGParamSpec :: Maybe GParamSpec
noGParamSpec = Maybe GParamSpec
forall a. Maybe a
Nothing
class Enum a => IsGFlag a
data GArray a = GArray (Ptr (GArray a))
data GPtrArray a = GPtrArray (Ptr (GPtrArray a))
data GByteArray = GByteArray (Ptr GByteArray)
data GHashTable a b = GHashTable (Ptr (GHashTable a b))
data GList a = GList (Ptr (GList a))
data GSList a = GSList (Ptr (GSList a))
newtype PtrWrapped a = PtrWrapped {PtrWrapped a -> Ptr a
unwrapPtr :: Ptr a}
type GDestroyNotify a = FunPtr (Ptr a -> IO ())
foreign import ccall "g_list_free" g_list_free ::
Ptr (GList a) -> IO ()
foreign import ccall "g_slist_free" g_slist_free ::
Ptr (GSList a) -> IO ()