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

TODO
-}

module GI.GIRepository.Structs.Typelib
    ( 

-- * Exported types
    Typelib(..)                             ,
    noTypelib                               ,


 -- * Methods
-- ** free #method:free#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    TypelibFreeMethodInfo                   ,
#endif
    typelibFree                             ,


-- ** getNamespace #method:getNamespace#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    TypelibGetNamespaceMethodInfo           ,
#endif
    typelibGetNamespace                     ,


-- ** symbol #method:symbol#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    TypelibSymbolMethodInfo                 ,
#endif
    typelibSymbol                           ,




    ) 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.ManagedPtr as B.ManagedPtr
import qualified Data.GI.Base.GError as B.GError
import qualified Data.GI.Base.GVariant as B.GVariant
import qualified Data.GI.Base.GParamSpec as B.GParamSpec
import qualified Data.GI.Base.CallStack as B.CallStack
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


newtype Typelib = Typelib (ManagedPtr Typelib)
-- XXX Wrapping a foreign struct/union with no known destructor or size, leak?
instance WrappedPtr Typelib where
    wrappedPtrCalloc = return nullPtr
    wrappedPtrCopy = return
    wrappedPtrFree = Nothing

noTypelib :: Maybe Typelib
noTypelib = Nothing


#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
instance O.HasAttributeList Typelib
type instance O.AttributeList Typelib = TypelibAttributeList
type TypelibAttributeList = ('[ ] :: [(Symbol, *)])
#endif

-- method Typelib::free
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "typelib", argType = TInterface (Name {namespace = "GIRepository", name = "Typelib"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Nothing, sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "g_typelib_free" g_typelib_free :: 
    Ptr Typelib ->                          -- typelib : TInterface (Name {namespace = "GIRepository", name = "Typelib"})
    IO ()

{- |
/No description available in the introspection data./
-}
typelibFree ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Typelib
    -> m ()
typelibFree typelib = liftIO $ do
    typelib' <- unsafeManagedPtrGetPtr typelib
    g_typelib_free typelib'
    touchManagedPtr typelib
    return ()

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data TypelibFreeMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.MethodInfo TypelibFreeMethodInfo Typelib signature where
    overloadedMethod _ = typelibFree

#endif

-- method Typelib::get_namespace
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "typelib", argType = TInterface (Name {namespace = "GIRepository", name = "Typelib"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Nothing, sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TUTF8)
-- throws : False
-- Skip return : False

foreign import ccall "g_typelib_get_namespace" g_typelib_get_namespace :: 
    Ptr Typelib ->                          -- typelib : TInterface (Name {namespace = "GIRepository", name = "Typelib"})
    IO CString

{- |
/No description available in the introspection data./
-}
typelibGetNamespace ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Typelib
    -> m T.Text
typelibGetNamespace typelib = liftIO $ do
    typelib' <- unsafeManagedPtrGetPtr typelib
    result <- g_typelib_get_namespace typelib'
    checkUnexpectedReturnNULL "typelibGetNamespace" result
    result' <- cstringToText result
    touchManagedPtr typelib
    return result'

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data TypelibGetNamespaceMethodInfo
instance (signature ~ (m T.Text), MonadIO m) => O.MethodInfo TypelibGetNamespaceMethodInfo Typelib signature where
    overloadedMethod _ = typelibGetNamespace

#endif

-- method Typelib::symbol
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "typelib", argType = TInterface (Name {namespace = "GIRepository", name = "Typelib"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Nothing, sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "symbol_name", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Nothing, sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "symbol", argType = TBasicType TPtr, direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Nothing, sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "g_typelib_symbol" g_typelib_symbol :: 
    Ptr Typelib ->                          -- typelib : TInterface (Name {namespace = "GIRepository", name = "Typelib"})
    CString ->                              -- symbol_name : TBasicType TUTF8
    Ptr () ->                               -- symbol : TBasicType TPtr
    IO CInt

{- |
/No description available in the introspection data./
-}
typelibSymbol ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Typelib
    -> T.Text
    -> Ptr ()
    -> m Bool
typelibSymbol typelib symbolName symbol = liftIO $ do
    typelib' <- unsafeManagedPtrGetPtr typelib
    symbolName' <- textToCString symbolName
    result <- g_typelib_symbol typelib' symbolName' symbol
    let result' = (/= 0) result
    touchManagedPtr typelib
    freeMem symbolName'
    return result'

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data TypelibSymbolMethodInfo
instance (signature ~ (T.Text -> Ptr () -> m Bool), MonadIO m) => O.MethodInfo TypelibSymbolMethodInfo Typelib signature where
    overloadedMethod _ = typelibSymbol

#endif

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
type family ResolveTypelibMethod (t :: Symbol) (o :: *) :: * where
    ResolveTypelibMethod "free" o = TypelibFreeMethodInfo
    ResolveTypelibMethod "symbol" o = TypelibSymbolMethodInfo
    ResolveTypelibMethod "getNamespace" o = TypelibGetNamespaceMethodInfo
    ResolveTypelibMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveTypelibMethod t Typelib, O.MethodInfo info Typelib p) => O.IsLabelProxy t (Typelib -> p) where
    fromLabelProxy _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)

#if MIN_VERSION_base(4,9,0)
instance (info ~ ResolveTypelibMethod t Typelib, O.MethodInfo info Typelib p) => O.IsLabel t (Typelib -> p) where
#if MIN_VERSION_base(4,10,0)
    fromLabel = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#else
    fromLabel _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#endif
#endif

#endif