{-# LANGUAGE TypeApplications #-}
#if (MIN_VERSION_haskell_gi_overloading(1,0,0) && !defined(__HADDOCK_VERSION__))
#define ENABLE_OVERLOADING
#endif
module GI.GLib.Structs.Dir
(
Dir(..) ,
#if defined(ENABLE_OVERLOADING)
ResolveDirMethod ,
#endif
#if defined(ENABLE_OVERLOADING)
DirCloseMethodInfo ,
#endif
dirClose ,
dirMakeTmp ,
#if defined(ENABLE_OVERLOADING)
DirReadNameMethodInfo ,
#endif
dirReadName ,
#if defined(ENABLE_OVERLOADING)
DirRewindMethodInfo ,
#endif
dirRewind ,
) 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.BasicTypes as B.Types
import qualified Data.GI.Base.ManagedPtr as B.ManagedPtr
import qualified Data.GI.Base.GClosure as B.GClosure
import qualified Data.GI.Base.GError as B.GError
import qualified Data.GI.Base.GVariant as B.GVariant
import qualified Data.GI.Base.GValue as B.GValue
import qualified Data.GI.Base.GParamSpec as B.GParamSpec
import qualified Data.GI.Base.CallStack as B.CallStack
import qualified Data.GI.Base.Properties as B.Properties
import qualified Data.GI.Base.Signals as B.Signals
import qualified Control.Monad.IO.Class as MIO
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 qualified GHC.OverloadedLabels as OL
newtype Dir = Dir (SP.ManagedPtr Dir)
deriving (Dir -> Dir -> Bool
(Dir -> Dir -> Bool) -> (Dir -> Dir -> Bool) -> Eq Dir
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Dir -> Dir -> Bool
$c/= :: Dir -> Dir -> Bool
== :: Dir -> Dir -> Bool
$c== :: Dir -> Dir -> Bool
Eq)
instance SP.ManagedPtrNewtype Dir where
toManagedPtr :: Dir -> ManagedPtr Dir
toManagedPtr (Dir ManagedPtr Dir
p) = ManagedPtr Dir
p
instance BoxedPtr Dir where
boxedPtrCopy :: Dir -> IO Dir
boxedPtrCopy = Dir -> IO Dir
forall (m :: * -> *) a. Monad m => a -> m a
return
boxedPtrFree :: Dir -> IO ()
boxedPtrFree = \Dir
_x -> () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
#if defined(ENABLE_OVERLOADING)
instance O.HasAttributeList Dir
type instance O.AttributeList Dir = DirAttributeList
type DirAttributeList = ('[ ] :: [(Symbol, *)])
#endif
foreign import ccall "g_dir_close" g_dir_close ::
Ptr Dir ->
IO ()
dirClose ::
(B.CallStack.HasCallStack, MonadIO m) =>
Dir
-> m ()
dirClose :: Dir -> m ()
dirClose Dir
dir = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
Ptr Dir
dir' <- Dir -> IO (Ptr Dir)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Dir
dir
Ptr Dir -> IO ()
g_dir_close Ptr Dir
dir'
Dir -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Dir
dir
() -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
#if defined(ENABLE_OVERLOADING)
data DirCloseMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.MethodInfo DirCloseMethodInfo Dir signature where
overloadedMethod = dirClose
#endif
foreign import ccall "g_dir_read_name" g_dir_read_name ::
Ptr Dir ->
IO CString
dirReadName ::
(B.CallStack.HasCallStack, MonadIO m) =>
Dir
-> m [Char]
dirReadName :: Dir -> m [Char]
dirReadName Dir
dir = IO [Char] -> m [Char]
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO [Char] -> m [Char]) -> IO [Char] -> m [Char]
forall a b. (a -> b) -> a -> b
$ do
Ptr Dir
dir' <- Dir -> IO (Ptr Dir)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Dir
dir
CString
result <- Ptr Dir -> IO CString
g_dir_read_name Ptr Dir
dir'
Text -> CString -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"dirReadName" CString
result
[Char]
result' <- HasCallStack => CString -> IO [Char]
CString -> IO [Char]
cstringToString CString
result
Dir -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Dir
dir
[Char] -> IO [Char]
forall (m :: * -> *) a. Monad m => a -> m a
return [Char]
result'
#if defined(ENABLE_OVERLOADING)
data DirReadNameMethodInfo
instance (signature ~ (m [Char]), MonadIO m) => O.MethodInfo DirReadNameMethodInfo Dir signature where
overloadedMethod = dirReadName
#endif
foreign import ccall "g_dir_rewind" g_dir_rewind ::
Ptr Dir ->
IO ()
dirRewind ::
(B.CallStack.HasCallStack, MonadIO m) =>
Dir
-> m ()
dirRewind :: Dir -> m ()
dirRewind Dir
dir = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
Ptr Dir
dir' <- Dir -> IO (Ptr Dir)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Dir
dir
Ptr Dir -> IO ()
g_dir_rewind Ptr Dir
dir'
Dir -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Dir
dir
() -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
#if defined(ENABLE_OVERLOADING)
data DirRewindMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.MethodInfo DirRewindMethodInfo Dir signature where
overloadedMethod = dirRewind
#endif
foreign import ccall "g_dir_make_tmp" g_dir_make_tmp ::
CString ->
Ptr (Ptr GError) ->
IO CString
dirMakeTmp ::
(B.CallStack.HasCallStack, MonadIO m) =>
Maybe ([Char])
-> m [Char]
dirMakeTmp :: Maybe [Char] -> m [Char]
dirMakeTmp Maybe [Char]
tmpl = IO [Char] -> m [Char]
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO [Char] -> m [Char]) -> IO [Char] -> m [Char]
forall a b. (a -> b) -> a -> b
$ do
CString
maybeTmpl <- case Maybe [Char]
tmpl of
Maybe [Char]
Nothing -> CString -> IO CString
forall (m :: * -> *) a. Monad m => a -> m a
return CString
forall a. Ptr a
nullPtr
Just [Char]
jTmpl -> do
CString
jTmpl' <- [Char] -> IO CString
stringToCString [Char]
jTmpl
CString -> IO CString
forall (m :: * -> *) a. Monad m => a -> m a
return CString
jTmpl'
IO [Char] -> IO () -> IO [Char]
forall a b. IO a -> IO b -> IO a
onException (do
CString
result <- (Ptr (Ptr GError) -> IO CString) -> IO CString
forall a. (Ptr (Ptr GError) -> IO a) -> IO a
propagateGError ((Ptr (Ptr GError) -> IO CString) -> IO CString)
-> (Ptr (Ptr GError) -> IO CString) -> IO CString
forall a b. (a -> b) -> a -> b
$ CString -> Ptr (Ptr GError) -> IO CString
g_dir_make_tmp CString
maybeTmpl
Text -> CString -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"dirMakeTmp" CString
result
[Char]
result' <- HasCallStack => CString -> IO [Char]
CString -> IO [Char]
cstringToString CString
result
CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
result
CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
maybeTmpl
[Char] -> IO [Char]
forall (m :: * -> *) a. Monad m => a -> m a
return [Char]
result'
) (do
CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
maybeTmpl
)
#if defined(ENABLE_OVERLOADING)
#endif
#if defined(ENABLE_OVERLOADING)
type family ResolveDirMethod (t :: Symbol) (o :: *) :: * where
ResolveDirMethod "close" o = DirCloseMethodInfo
ResolveDirMethod "readName" o = DirReadNameMethodInfo
ResolveDirMethod "rewind" o = DirRewindMethodInfo
ResolveDirMethod l o = O.MethodResolutionFailed l o
instance (info ~ ResolveDirMethod t Dir, O.MethodInfo info Dir p) => OL.IsLabel t (Dir -> p) where
#if MIN_VERSION_base(4,10,0)
fromLabel = O.overloadedMethod @info
#else
fromLabel _ = O.overloadedMethod @info
#endif
#endif