{-# LANGUAGE TypeApplications #-}
#if (MIN_VERSION_haskell_gi_overloading(1,0,0) && !defined(__HADDOCK_VERSION__))
#define ENABLE_OVERLOADING
#endif
module GI.Json.Objects.Path
(
Path(..) ,
IsPath ,
toPath ,
#if defined(ENABLE_OVERLOADING)
ResolvePathMethod ,
#endif
#if defined(ENABLE_OVERLOADING)
PathCompileMethodInfo ,
#endif
pathCompile ,
#if defined(ENABLE_OVERLOADING)
PathMatchMethodInfo ,
#endif
pathMatch ,
pathNew ,
pathQuery ,
) 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.GArray as B.GArray
import qualified Data.GI.Base.GClosure as B.GClosure
import qualified Data.GI.Base.GError as B.GError
import qualified Data.GI.Base.GHashTable as B.GHT
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.Coerce as Coerce
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
import qualified GHC.Records as R
import qualified GI.GObject.Objects.Object as GObject.Object
import {-# SOURCE #-} qualified GI.Json.Structs.Node as Json.Node
newtype Path = Path (SP.ManagedPtr Path)
deriving (Path -> Path -> Bool
(Path -> Path -> Bool) -> (Path -> Path -> Bool) -> Eq Path
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Path -> Path -> Bool
== :: Path -> Path -> Bool
$c/= :: Path -> Path -> Bool
/= :: Path -> Path -> Bool
Eq)
instance SP.ManagedPtrNewtype Path where
toManagedPtr :: Path -> ManagedPtr Path
toManagedPtr (Path ManagedPtr Path
p) = ManagedPtr Path
p
foreign import ccall "json_path_get_type"
c_json_path_get_type :: IO B.Types.GType
instance B.Types.TypedObject Path where
glibType :: IO GType
glibType = IO GType
c_json_path_get_type
instance B.Types.GObject Path
class (SP.GObject o, O.IsDescendantOf Path o) => IsPath o
instance (SP.GObject o, O.IsDescendantOf Path o) => IsPath o
instance O.HasParentTypes Path
type instance O.ParentTypes Path = '[GObject.Object.Object]
toPath :: (MIO.MonadIO m, IsPath o) => o -> m Path
toPath :: forall (m :: * -> *) o. (MonadIO m, IsPath o) => o -> m Path
toPath = IO Path -> m Path
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
MIO.liftIO (IO Path -> m Path) -> (o -> IO Path) -> o -> m Path
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ManagedPtr Path -> Path) -> o -> IO Path
forall o o'.
(HasCallStack, ManagedPtrNewtype o, TypedObject o,
ManagedPtrNewtype o', TypedObject o') =>
(ManagedPtr o' -> o') -> o -> IO o'
B.ManagedPtr.unsafeCastTo ManagedPtr Path -> Path
Path
instance B.GValue.IsGValue (Maybe Path) where
gvalueGType_ :: IO GType
gvalueGType_ = IO GType
c_json_path_get_type
gvalueSet_ :: Ptr GValue -> Maybe Path -> IO ()
gvalueSet_ Ptr GValue
gv Maybe Path
P.Nothing = Ptr GValue -> Ptr Path -> IO ()
forall a. GObject a => Ptr GValue -> Ptr a -> IO ()
B.GValue.set_object Ptr GValue
gv (Ptr Path
forall a. Ptr a
FP.nullPtr :: FP.Ptr Path)
gvalueSet_ Ptr GValue
gv (P.Just Path
obj) = Path -> (Ptr Path -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
B.ManagedPtr.withManagedPtr Path
obj (Ptr GValue -> Ptr Path -> IO ()
forall a. GObject a => Ptr GValue -> Ptr a -> IO ()
B.GValue.set_object Ptr GValue
gv)
gvalueGet_ :: Ptr GValue -> IO (Maybe Path)
gvalueGet_ Ptr GValue
gv = do
Ptr Path
ptr <- Ptr GValue -> IO (Ptr Path)
forall a. GObject a => Ptr GValue -> IO (Ptr a)
B.GValue.get_object Ptr GValue
gv :: IO (FP.Ptr Path)
if Ptr Path
ptr Ptr Path -> Ptr Path -> Bool
forall a. Eq a => a -> a -> Bool
/= Ptr Path
forall a. Ptr a
FP.nullPtr
then Path -> Maybe Path
forall a. a -> Maybe a
P.Just (Path -> Maybe Path) -> IO Path -> IO (Maybe Path)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (ManagedPtr Path -> Path) -> Ptr Path -> IO Path
forall a b.
(HasCallStack, GObject a, GObject b) =>
(ManagedPtr a -> a) -> Ptr b -> IO a
B.ManagedPtr.newObject ManagedPtr Path -> Path
Path Ptr Path
ptr
else Maybe Path -> IO (Maybe Path)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Path
forall a. Maybe a
P.Nothing
#if defined(ENABLE_OVERLOADING)
type family ResolvePathMethod (t :: Symbol) (o :: *) :: * where
ResolvePathMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
ResolvePathMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
ResolvePathMethod "compile" o = PathCompileMethodInfo
ResolvePathMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
ResolvePathMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
ResolvePathMethod "getv" o = GObject.Object.ObjectGetvMethodInfo
ResolvePathMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
ResolvePathMethod "match" o = PathMatchMethodInfo
ResolvePathMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
ResolvePathMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
ResolvePathMethod "ref" o = GObject.Object.ObjectRefMethodInfo
ResolvePathMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
ResolvePathMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
ResolvePathMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
ResolvePathMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
ResolvePathMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
ResolvePathMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
ResolvePathMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
ResolvePathMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
ResolvePathMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
ResolvePathMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
ResolvePathMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
ResolvePathMethod "setDataFull" o = GObject.Object.ObjectSetDataFullMethodInfo
ResolvePathMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
ResolvePathMethod l o = O.MethodResolutionFailed l o
instance (info ~ ResolvePathMethod t Path, O.OverloadedMethod info Path p) => OL.IsLabel t (Path -> p) where
#if MIN_VERSION_base(4,10,0)
fromLabel = O.overloadedMethod @info
#else
fromLabel _ = O.overloadedMethod @info
#endif
#if MIN_VERSION_base(4,13,0)
instance (info ~ ResolvePathMethod t Path, O.OverloadedMethod info Path p, R.HasField t Path p) => R.HasField t Path p where
getField = O.overloadedMethod @info
#endif
instance (info ~ ResolvePathMethod t Path, O.OverloadedMethodInfo info Path) => OL.IsLabel t (O.MethodProxy info Path) where
#if MIN_VERSION_base(4,10,0)
fromLabel = O.MethodProxy
#else
fromLabel _ = O.MethodProxy
#endif
#endif
#if defined(ENABLE_OVERLOADING)
instance O.HasAttributeList Path
type instance O.AttributeList Path = PathAttributeList
type PathAttributeList = ('[ ] :: [(Symbol, *)])
#endif
#if defined(ENABLE_OVERLOADING)
#endif
#if defined(ENABLE_OVERLOADING)
type instance O.SignalList Path = PathSignalList
type PathSignalList = ('[ '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])
#endif
foreign import ccall "json_path_new" json_path_new ::
IO (Ptr Path)
pathNew ::
(B.CallStack.HasCallStack, MonadIO m) =>
m Path
pathNew :: forall (m :: * -> *). (HasCallStack, MonadIO m) => m Path
pathNew = IO Path -> m Path
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Path -> m Path) -> IO Path -> m Path
forall a b. (a -> b) -> a -> b
$ do
Ptr Path
result <- IO (Ptr Path)
json_path_new
Text -> Ptr Path -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"pathNew" Ptr Path
result
Path
result' <- ((ManagedPtr Path -> Path) -> Ptr Path -> IO Path
forall a b.
(HasCallStack, GObject a, GObject b) =>
(ManagedPtr a -> a) -> Ptr b -> IO a
wrapObject ManagedPtr Path -> Path
Path) Ptr Path
result
Path -> IO Path
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Path
result'
#if defined(ENABLE_OVERLOADING)
#endif
foreign import ccall "json_path_compile" json_path_compile ::
Ptr Path ->
CString ->
Ptr (Ptr GError) ->
IO CInt
pathCompile ::
(B.CallStack.HasCallStack, MonadIO m, IsPath a) =>
a
-> T.Text
-> m ()
pathCompile :: forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsPath a) =>
a -> Text -> m ()
pathCompile a
path Text
expression = IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
Ptr Path
path' <- a -> IO (Ptr Path)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
path
CString
expression' <- Text -> IO CString
textToCString Text
expression
IO () -> IO () -> IO ()
forall a b. IO a -> IO b -> IO a
onException (do
CInt
_ <- (Ptr (Ptr GError) -> IO CInt) -> IO CInt
forall a. (Ptr (Ptr GError) -> IO a) -> IO a
propagateGError ((Ptr (Ptr GError) -> IO CInt) -> IO CInt)
-> (Ptr (Ptr GError) -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ Ptr Path -> CString -> Ptr (Ptr GError) -> IO CInt
json_path_compile Ptr Path
path' CString
expression'
a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
path
CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
expression'
() -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
) (do
CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
expression'
)
#if defined(ENABLE_OVERLOADING)
data PathCompileMethodInfo
instance (signature ~ (T.Text -> m ()), MonadIO m, IsPath a) => O.OverloadedMethod PathCompileMethodInfo a signature where
overloadedMethod = pathCompile
instance O.OverloadedMethodInfo PathCompileMethodInfo a where
overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
O.resolvedSymbolName = "GI.Json.Objects.Path.pathCompile",
O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-json-1.0.3/docs/GI-Json-Objects-Path.html#v:pathCompile"
})
#endif
foreign import ccall "json_path_match" json_path_match ::
Ptr Path ->
Ptr Json.Node.Node ->
IO (Ptr Json.Node.Node)
pathMatch ::
(B.CallStack.HasCallStack, MonadIO m, IsPath a) =>
a
-> Json.Node.Node
-> m Json.Node.Node
pathMatch :: forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsPath a) =>
a -> Node -> m Node
pathMatch a
path Node
root = IO Node -> m Node
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Node -> m Node) -> IO Node -> m Node
forall a b. (a -> b) -> a -> b
$ do
Ptr Path
path' <- a -> IO (Ptr Path)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
path
Ptr Node
root' <- Node -> IO (Ptr Node)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Node
root
Ptr Node
result <- Ptr Path -> Ptr Node -> IO (Ptr Node)
json_path_match Ptr Path
path' Ptr Node
root'
Text -> Ptr Node -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"pathMatch" Ptr Node
result
Node
result' <- ((ManagedPtr Node -> Node) -> Ptr Node -> IO Node
forall a.
(HasCallStack, GBoxed a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
wrapBoxed ManagedPtr Node -> Node
Json.Node.Node) Ptr Node
result
a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
path
Node -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Node
root
Node -> IO Node
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Node
result'
#if defined(ENABLE_OVERLOADING)
data PathMatchMethodInfo
instance (signature ~ (Json.Node.Node -> m Json.Node.Node), MonadIO m, IsPath a) => O.OverloadedMethod PathMatchMethodInfo a signature where
overloadedMethod = pathMatch
instance O.OverloadedMethodInfo PathMatchMethodInfo a where
overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
O.resolvedSymbolName = "GI.Json.Objects.Path.pathMatch",
O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-json-1.0.3/docs/GI-Json-Objects-Path.html#v:pathMatch"
})
#endif
foreign import ccall "json_path_query" json_path_query ::
CString ->
Ptr Json.Node.Node ->
Ptr (Ptr GError) ->
IO (Ptr Json.Node.Node)
pathQuery ::
(B.CallStack.HasCallStack, MonadIO m) =>
T.Text
-> Json.Node.Node
-> m Json.Node.Node
pathQuery :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
Text -> Node -> m Node
pathQuery Text
expression Node
root = IO Node -> m Node
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Node -> m Node) -> IO Node -> m Node
forall a b. (a -> b) -> a -> b
$ do
CString
expression' <- Text -> IO CString
textToCString Text
expression
Ptr Node
root' <- Node -> IO (Ptr Node)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Node
root
IO Node -> IO () -> IO Node
forall a b. IO a -> IO b -> IO a
onException (do
Ptr Node
result <- (Ptr (Ptr GError) -> IO (Ptr Node)) -> IO (Ptr Node)
forall a. (Ptr (Ptr GError) -> IO a) -> IO a
propagateGError ((Ptr (Ptr GError) -> IO (Ptr Node)) -> IO (Ptr Node))
-> (Ptr (Ptr GError) -> IO (Ptr Node)) -> IO (Ptr Node)
forall a b. (a -> b) -> a -> b
$ CString -> Ptr Node -> Ptr (Ptr GError) -> IO (Ptr Node)
json_path_query CString
expression' Ptr Node
root'
Text -> Ptr Node -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"pathQuery" Ptr Node
result
Node
result' <- ((ManagedPtr Node -> Node) -> Ptr Node -> IO Node
forall a.
(HasCallStack, GBoxed a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
wrapBoxed ManagedPtr Node -> Node
Json.Node.Node) Ptr Node
result
Node -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Node
root
CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
expression'
Node -> IO Node
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Node
result'
) (do
CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
expression'
)
#if defined(ENABLE_OVERLOADING)
#endif