{-# LINE 1 "Data/GI/Base/BasicTypes.hsc" #-}
{-# LANGUAGE ConstraintKinds, FlexibleContexts, FlexibleInstances,
DeriveDataTypeable, TypeFamilies, ScopedTypeVariables #-}
{-# LANGUAGE DataKinds, TypeOperators, UndecidableInstances #-}
{-# LANGUAGE AllowAmbiguousTypes #-}
module Data.GI.Base.BasicTypes
(
ManagedPtr(..)
, ManagedPtrNewtype
, BoxedObject(..)
, BoxedEnum(..)
, BoxedFlags(..)
, WrappedPtr(..)
, UnexpectedNullPointerReturn(..)
, GObject(..)
, GType(..)
, CGType
, gtypeName
, GVariant(..)
, 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 (Coercible)
import Data.IORef (IORef)
import Data.Proxy (Proxy)
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
a :: ManagedPtr a
a == :: ManagedPtr a -> ManagedPtr a -> Bool
== b :: 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
type ManagedPtrNewtype a = Coercible a (ManagedPtr ())
class ManagedPtrNewtype a => BoxedObject a where
boxedType :: a -> IO GType
class BoxedEnum a where
boxedEnumType :: a -> IO GType
class BoxedFlags a where
boxedFlagsType :: Proxy a -> IO GType
class ManagedPtrNewtype a => WrappedPtr a where
wrappedPtrCalloc :: IO (Ptr a)
wrappedPtrCopy :: a -> IO a
wrappedPtrFree :: Maybe (GDestroyNotify a)
class (ManagedPtrNewtype a, HasParentTypes a) => GObject a where
gobjectType :: IO GType
type CGType = Word64
{-# LINE 122 "Data/GI/Base/BasicTypes.hsc" #-}
newtype GType = GType {GType -> CGType
gtypeToCGType :: CGType}
foreign import ccall "g_type_name" g_type_name :: GType -> IO CString
gtypeName :: GType -> IO String
gtypeName :: GType -> IO String
gtypeName gtype :: 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 r :: 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 ()