{- |
Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
License    : LGPL-2.1
Maintainer : Iñaki García Etxebarria (garetxe@gmail.com)

A parse context is used to parse a stream of bytes that
you expect to contain marked-up text.

See g_markup_parse_context_new(), #GMarkupParser, and so
on for more details.
-}

module GI.GLib.Structs.MarkupParseContext
    ( 

-- * Exported types
    MarkupParseContext(..)                  ,
    noMarkupParseContext                    ,


 -- * Methods
-- ** markupParseContextEndParse
    markupParseContextEndParse              ,


-- ** markupParseContextFree
    markupParseContextFree                  ,


-- ** markupParseContextGetElement
    markupParseContextGetElement            ,


-- ** markupParseContextNew
    markupParseContextNew                   ,


-- ** markupParseContextParse
    markupParseContextParse                 ,


-- ** markupParseContextPush
    markupParseContextPush                  ,


-- ** markupParseContextRef
    markupParseContextRef                   ,


-- ** markupParseContextUnref
    markupParseContextUnref                 ,




    ) where

import Prelude ()
import Data.GI.Base.ShortPrelude

import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map

import GI.GLib.Types
import GI.GLib.Callbacks

newtype MarkupParseContext = MarkupParseContext (ForeignPtr MarkupParseContext)
foreign import ccall "g_markup_parse_context_get_type" c_g_markup_parse_context_get_type :: 
    IO GType

instance BoxedObject MarkupParseContext where
    boxedType _ = c_g_markup_parse_context_get_type

noMarkupParseContext :: Maybe MarkupParseContext
noMarkupParseContext = Nothing

-- method MarkupParseContext::new
-- method type : Constructor
-- Args : [Arg {argName = "parser", argType = TInterface "GLib" "MarkupParser", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "flags", argType = TInterface "GLib" "MarkupParseFlags", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "user_data", argType = TBasicType TVoid, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "user_data_dnotify", argType = TInterface "GLib" "DestroyNotify", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeAsync, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "parser", argType = TInterface "GLib" "MarkupParser", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "flags", argType = TInterface "GLib" "MarkupParseFlags", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "user_data", argType = TBasicType TVoid, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "user_data_dnotify", argType = TInterface "GLib" "DestroyNotify", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeAsync, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "GLib" "MarkupParseContext"
-- throws : False
-- Skip return : False

foreign import ccall "g_markup_parse_context_new" g_markup_parse_context_new :: 
    Ptr MarkupParser ->                     -- parser : TInterface "GLib" "MarkupParser"
    CUInt ->                                -- flags : TInterface "GLib" "MarkupParseFlags"
    Ptr () ->                               -- user_data : TBasicType TVoid
    FunPtr DestroyNotifyC ->                -- user_data_dnotify : TInterface "GLib" "DestroyNotify"
    IO (Ptr MarkupParseContext)


markupParseContextNew ::
    (MonadIO m) =>
    MarkupParser ->                         -- parser
    [MarkupParseFlags] ->                   -- flags
    Ptr () ->                               -- user_data
    DestroyNotify ->                        -- user_data_dnotify
    m MarkupParseContext
markupParseContextNew parser flags user_data user_data_dnotify = liftIO $ do
    let parser' = unsafeManagedPtrGetPtr parser
    let flags' = gflagsToWord flags
    ptruser_data_dnotify <- callocMem :: IO (Ptr (FunPtr DestroyNotifyC))
    user_data_dnotify' <- mkDestroyNotify (destroyNotifyWrapper (Just ptruser_data_dnotify) user_data_dnotify)
    poke ptruser_data_dnotify user_data_dnotify'
    result <- g_markup_parse_context_new parser' flags' user_data user_data_dnotify'
    checkUnexpectedReturnNULL "g_markup_parse_context_new" result
    result' <- (wrapBoxed MarkupParseContext) result
    touchManagedPtr parser
    return result'

-- method MarkupParseContext::end_parse
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "GLib" "MarkupParseContext", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "GLib" "MarkupParseContext", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TBoolean
-- throws : True
-- Skip return : False

foreign import ccall "g_markup_parse_context_end_parse" g_markup_parse_context_end_parse :: 
    Ptr MarkupParseContext ->               -- _obj : TInterface "GLib" "MarkupParseContext"
    Ptr (Ptr GError) ->                     -- error
    IO CInt


markupParseContextEndParse ::
    (MonadIO m) =>
    MarkupParseContext ->                   -- _obj
    m ()
markupParseContextEndParse _obj = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    onException (do
        _ <- propagateGError $ g_markup_parse_context_end_parse _obj'
        touchManagedPtr _obj
        return ()
     ) (do
        return ()
     )

-- method MarkupParseContext::free
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "GLib" "MarkupParseContext", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "GLib" "MarkupParseContext", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "g_markup_parse_context_free" g_markup_parse_context_free :: 
    Ptr MarkupParseContext ->               -- _obj : TInterface "GLib" "MarkupParseContext"
    IO ()


markupParseContextFree ::
    (MonadIO m) =>
    MarkupParseContext ->                   -- _obj
    m ()
markupParseContextFree _obj = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    g_markup_parse_context_free _obj'
    touchManagedPtr _obj
    return ()

-- method MarkupParseContext::get_element
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "GLib" "MarkupParseContext", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "GLib" "MarkupParseContext", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TUTF8
-- throws : False
-- Skip return : False

foreign import ccall "g_markup_parse_context_get_element" g_markup_parse_context_get_element :: 
    Ptr MarkupParseContext ->               -- _obj : TInterface "GLib" "MarkupParseContext"
    IO CString


markupParseContextGetElement ::
    (MonadIO m) =>
    MarkupParseContext ->                   -- _obj
    m T.Text
markupParseContextGetElement _obj = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    result <- g_markup_parse_context_get_element _obj'
    checkUnexpectedReturnNULL "g_markup_parse_context_get_element" result
    result' <- cstringToText result
    touchManagedPtr _obj
    return result'

-- method MarkupParseContext::parse
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "GLib" "MarkupParseContext", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "text", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "text_len", argType = TBasicType TInt64, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "GLib" "MarkupParseContext", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "text", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "text_len", argType = TBasicType TInt64, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TBoolean
-- throws : True
-- Skip return : False

foreign import ccall "g_markup_parse_context_parse" g_markup_parse_context_parse :: 
    Ptr MarkupParseContext ->               -- _obj : TInterface "GLib" "MarkupParseContext"
    CString ->                              -- text : TBasicType TUTF8
    Int64 ->                                -- text_len : TBasicType TInt64
    Ptr (Ptr GError) ->                     -- error
    IO CInt


markupParseContextParse ::
    (MonadIO m) =>
    MarkupParseContext ->                   -- _obj
    T.Text ->                               -- text
    Int64 ->                                -- text_len
    m ()
markupParseContextParse _obj text text_len = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    text' <- textToCString text
    onException (do
        _ <- propagateGError $ g_markup_parse_context_parse _obj' text' text_len
        touchManagedPtr _obj
        freeMem text'
        return ()
     ) (do
        freeMem text'
     )

-- method MarkupParseContext::push
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "GLib" "MarkupParseContext", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "parser", argType = TInterface "GLib" "MarkupParser", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "user_data", argType = TBasicType TVoid, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "GLib" "MarkupParseContext", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "parser", argType = TInterface "GLib" "MarkupParser", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "user_data", argType = TBasicType TVoid, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "g_markup_parse_context_push" g_markup_parse_context_push :: 
    Ptr MarkupParseContext ->               -- _obj : TInterface "GLib" "MarkupParseContext"
    Ptr MarkupParser ->                     -- parser : TInterface "GLib" "MarkupParser"
    Ptr () ->                               -- user_data : TBasicType TVoid
    IO ()


markupParseContextPush ::
    (MonadIO m) =>
    MarkupParseContext ->                   -- _obj
    MarkupParser ->                         -- parser
    Ptr () ->                               -- user_data
    m ()
markupParseContextPush _obj parser user_data = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    let parser' = unsafeManagedPtrGetPtr parser
    g_markup_parse_context_push _obj' parser' user_data
    touchManagedPtr _obj
    touchManagedPtr parser
    return ()

-- method MarkupParseContext::ref
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "GLib" "MarkupParseContext", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "GLib" "MarkupParseContext", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "GLib" "MarkupParseContext"
-- throws : False
-- Skip return : False

foreign import ccall "g_markup_parse_context_ref" g_markup_parse_context_ref :: 
    Ptr MarkupParseContext ->               -- _obj : TInterface "GLib" "MarkupParseContext"
    IO (Ptr MarkupParseContext)


markupParseContextRef ::
    (MonadIO m) =>
    MarkupParseContext ->                   -- _obj
    m MarkupParseContext
markupParseContextRef _obj = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    result <- g_markup_parse_context_ref _obj'
    checkUnexpectedReturnNULL "g_markup_parse_context_ref" result
    result' <- (wrapBoxed MarkupParseContext) result
    touchManagedPtr _obj
    return result'

-- method MarkupParseContext::unref
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "GLib" "MarkupParseContext", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "GLib" "MarkupParseContext", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "g_markup_parse_context_unref" g_markup_parse_context_unref :: 
    Ptr MarkupParseContext ->               -- _obj : TInterface "GLib" "MarkupParseContext"
    IO ()


markupParseContextUnref ::
    (MonadIO m) =>
    MarkupParseContext ->                   -- _obj
    m ()
markupParseContextUnref _obj = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    g_markup_parse_context_unref _obj'
    touchManagedPtr _obj
    return ()