    -- GENERATED by C->Haskell Compiler, version 0.13.5 (gtk2hs branch) "Bin IO", 13 Nov 2004 (Haskell)
    -- Edit the ORIGNAL .chs file instead!

    {-# LINE 1 "./Media/Streaming/GStreamer/Core/Structure.chs" #-}
    --  GIMP Toolkit (GTK) Binding for Haskell: binding to gstreamer -*-haskell-*-
    --
    --  Author : Peter Gavin
    --  Created: 1-Apr-2007
    --
    --  Copyright (c) 2007 Peter Gavin
    --
    --  This library is free software: you can redistribute it and/or
    --  modify it under the terms of the GNU Lesser General Public License
    --  as published by the Free Software Foundation, either version 3 of
    --  the License, or (at your option) any later version.
    --
    --  This library is distributed in the hope that it will be useful,
    --  but WITHOUT ANY WARRANTY; without even the implied warranty of
    --  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    --  Lesser General Public License for more details.
    --
    --  You should have received a copy of the GNU Lesser General Public
    --  License along with this program.  If not, see
    --  <http://www.gnu.org/licenses/>.
    --
    --  GStreamer, the C library which this Haskell library depends on, is
    --  available under LGPL Version 2. The documentation included with
    --  this library is based on the original GStreamer documentation.
    --
    -- | Maintainer  : gtk2hs-devel@lists.sourceforge.net
    --   Stability   : alpha
    --   Portability : portable (depends on GHC)
    module Media.Streaming.GStreamer.Core.Structure (
      Structure,
      structureEmpty,
      structureToString,
      structureFromString,
      structureName,
      structureHasName,
      structureGetBool,
      structureGetInt,
      structureGetFourCC,
      structureGetDouble,
      structureGetString,
      structureGetDate,
      structureGetClockTime,
      structureGetFraction,

      StructureM,
      structureCreate,
      structureModify,
      structureSetNameM,
      structureRemoveFieldM,
      structureSetBoolM,
      structureSetIntM,
      structureSetFourCCM,
      structureSetDoubleM,
      structureSetStringM,
      structureSetDateM,
      structureSetClockTimeM,
      structureSetFractionM,
      structureFixateFieldNearestIntM,
      structureFixateFieldNearestDoubleM,
      structureFixateFieldNearestFractionM,
      structureFixateFieldBoolM
      ) where

    import Data.Ratio ( (%)
                      , numerator
                      , denominator )
    import Control.Monad (liftM)
    import Media.Streaming.GStreamer.Core.Types
    {-# LINE 68 "./Media/Streaming/GStreamer/Core/Structure.chs" #-}
    import System.Glib.UTFString
    import System.Glib.FFI
    import System.Glib.GTypeConstants
    import System.Glib.GDateTime
    {-# LINE 72 "./Media/Streaming/GStreamer/Core/Structure.chs" #-}
    import System.Glib.GType
    {-# LINE 73 "./Media/Streaming/GStreamer/Core/Structure.chs" #-}
    import System.Glib.GValue
    {-# LINE 74 "./Media/Streaming/GStreamer/Core/Structure.chs" #-}
    import System.Glib.GValueTypes
    {-# LINE 75 "./Media/Streaming/GStreamer/Core/Structure.chs" #-}

    {-# LINE 77 "./Media/Streaming/GStreamer/Core/Structure.chs" #-}

    structureEmpty :: String
                   -> Structure
    structureEmpty name =
        unsafePerformIO $
            withUTFString name gst_structure_empty_new >>=
                takeStructure

    structureToString :: Structure
                      -> String
    structureToString structure =
        unsafePerformIO $
            (\(Structure arg1) -> withForeignPtr arg1 $ \argPtr1 ->gst_structure_to_string argPtr1) structure >>=
                readUTFString

    structureFromString :: String
                        -> (Maybe Structure, Int)
    structureFromString string =
        unsafePerformIO $
            withUTFString string $ \cString ->
                alloca $ \endPtr ->
                    do structure <- gst_structure_from_string cString endPtr >>=
                                        maybePeek takeStructure
                       end <- peek endPtr
                       offset <- g_utf8_pointer_to_offset cString end
                       return (structure, fromIntegral offset)

    structureName :: Structure
                  -> String
    structureName structure =
        unsafePerformIO $
            (\(Structure arg1) -> withForeignPtr arg1 $ \argPtr1 ->gst_structure_get_name argPtr1) structure >>=
                peekUTFString

    structureHasName :: Structure
                     -> String
                     -> Bool
    structureHasName structure name =
        toBool $ unsafePerformIO $
            withUTFString name $
                 (\(Structure arg1) arg2 -> withForeignPtr arg1 $ \argPtr1 ->gst_structure_has_name argPtr1 arg2) structure

    marshalStructureGet :: Storable a
                        => (Structure -> CString -> Ptr a -> IO (CInt))
                        -> (a -> IO b)
                        -> Structure
                        -> String
                        -> Maybe b
    marshalStructureGet getAction convert structure fieldname =
        unsafePerformIO $
            alloca $ \ptr ->
                withUTFString fieldname $ \cFieldname ->
                    do result <- getAction structure cFieldname ptr
                       if toBool result
                           then liftM Just $ peek (castPtr ptr) >>= convert
                           else return Nothing

    structureGetBool :: Structure
                     -> String
                     -> Maybe Bool
    structureGetBool =
        marshalStructureGet (\(Structure arg1) arg2 arg3 -> withForeignPtr arg1 $ \argPtr1 ->gst_structure_get_boolean argPtr1 arg2 arg3) $
            return . toBool

    structureGetInt :: Structure
                    -> String
                    -> Maybe Int
    structureGetInt =
        marshalStructureGet (\(Structure arg1) arg2 arg3 -> withForeignPtr arg1 $ \argPtr1 ->gst_structure_get_int argPtr1 arg2 arg3) $
            return . fromIntegral

    structureGetFourCC :: Structure
                       -> String
                       -> Maybe FourCC
    structureGetFourCC =
        marshalStructureGet (\(Structure arg1) arg2 arg3 -> withForeignPtr arg1 $ \argPtr1 ->gst_structure_get_fourcc argPtr1 arg2 arg3) $
            return . fromIntegral

    structureGetDouble :: Structure
                       -> String
                       -> Maybe Double
    structureGetDouble =
        marshalStructureGet (\(Structure arg1) arg2 arg3 -> withForeignPtr arg1 $ \argPtr1 ->gst_structure_get_double argPtr1 arg2 arg3) $
            return . realToFrac

    structureGetString :: Structure
                       -> String
                       -> Maybe String
    structureGetString structure fieldname =
        unsafePerformIO $
            (withUTFString fieldname $ (\(Structure arg1) arg2 -> withForeignPtr arg1 $ \argPtr1 ->gst_structure_get_string argPtr1 arg2) structure) >>=
                maybePeek peekUTFString

    structureGetDate :: Structure
                     -> String
                     -> Maybe GDate
    structureGetDate =
        marshalStructureGet (\(Structure arg1) arg2 arg3 -> withForeignPtr arg1 $ \argPtr1 ->gst_structure_get_date argPtr1 arg2 arg3) $
            peek . castPtr

    structureGetClockTime :: Structure
                          -> String
                          -> Maybe ClockTime
    structureGetClockTime =
        marshalStructureGet (\(Structure arg1) arg2 arg3 -> withForeignPtr arg1 $ \argPtr1 ->gst_structure_get_clock_time argPtr1 arg2 arg3) $
            return . fromIntegral

    structureGetFraction :: Structure
                         -> String
                         -> Maybe Fraction
    structureGetFraction structure fieldname =
        unsafePerformIO $
            alloca $ \numPtr -> alloca $ \denPtr ->
                withUTFString fieldname $ \cFieldname ->
                    do result <- (\(Structure arg1) arg2 arg3 arg4 -> withForeignPtr arg1 $ \argPtr1 ->gst_structure_get_fraction argPtr1 arg2 arg3 arg4) structure cFieldname numPtr denPtr
                       if toBool result
                           then do num <- peek numPtr
                                   den <- peek denPtr
                                   return $ Just $ (fromIntegral num) % (fromIntegral den)
                           else return Nothing

    marshalStructureModify :: IO (Ptr Structure)
                           -> StructureM a
                           -> (Structure, a)
    marshalStructureModify mkStructure (StructureM action) =
        unsafePerformIO $
            do ptr <- mkStructure
               structure <- liftM Structure $ newForeignPtr_ ptr
               result <- action structure
               structure' <- takeStructure ptr
               return (structure', result)

    structureCreate :: String
                    -> StructureM a
                    -> (Structure, a)
    structureCreate name action =
        marshalStructureModify
            (withUTFString name gst_structure_empty_new)
            action

    structureModify :: Structure
                    -> StructureM a
                    -> (Structure, a)
    structureModify structure action =
        marshalStructureModify
            ((\(Structure arg1) -> withForeignPtr arg1 $ \argPtr1 ->gst_structure_copy argPtr1) structure)
            action

    structureSetNameM :: String
                      -> StructureM ()
    structureSetNameM name =
        StructureM $ \structure ->
            withUTFString name $ (\(Structure arg1) arg2 -> withForeignPtr arg1 $ \argPtr1 ->gst_structure_set_name argPtr1 arg2) structure

    structureRemoveFieldM :: String
                          -> StructureM ()
    structureRemoveFieldM name =
        StructureM $ \structure ->
            withUTFString name $ (\(Structure arg1) arg2 -> withForeignPtr arg1 $ \argPtr1 ->gst_structure_remove_field argPtr1 arg2) structure

    marshalStructureSetM :: GType
                         -> (GValue -> a -> IO ())
                         -> String
                         -> a
                         -> StructureM ()
    marshalStructureSetM valueType setGValue fieldname value =
        StructureM $ \structure ->
            withUTFString fieldname $ \cFieldname ->
            allocaGValue $ \gValue ->
                do valueInit gValue valueType
                   setGValue gValue value
                   (\(Structure arg1) arg2 (GValue arg3) -> withForeignPtr arg1 $ \argPtr1 ->gst_structure_set_value argPtr1 arg2 arg3) structure cFieldname gValue

    structureSetBoolM :: String
                      -> Bool
                      -> StructureM ()
    structureSetBoolM =
        marshalStructureSetM bool valueSetBool

    structureSetIntM :: String
                     -> Int
                     -> StructureM ()
    structureSetIntM =
        marshalStructureSetM int valueSetInt

    structureSetFourCCM :: String
                        -> FourCC
                        -> StructureM ()
    structureSetFourCCM =
        marshalStructureSetM fourcc $ \gValue fourcc ->
            (\(GValue arg1) arg2 -> gst_value_set_fourcc arg1 arg2) gValue $ fromIntegral fourcc

    structureSetDoubleM :: String
                        -> Double
                        -> StructureM ()
    structureSetDoubleM =
        marshalStructureSetM double valueSetDouble

    structureSetStringM :: String
                        -> String
                        -> StructureM ()
    structureSetStringM =
        marshalStructureSetM string valueSetString

    structureSetDateM :: String
                      -> GDate
                      -> StructureM ()
    structureSetDateM =
        marshalStructureSetM date $ \gValue date ->
            with date $ ((\(GValue arg1) arg2 -> gst_value_set_date arg1 arg2) gValue) . castPtr

    structureSetClockTimeM :: String
                           -> ClockTime
                           -> StructureM ()
    structureSetClockTimeM =
        marshalStructureSetM uint64 $ \gValue clockTime ->
            (\(GValue arg1) arg2 -> g_value_set_uint64 arg1 arg2) gValue $ fromIntegral clockTime

    structureSetFractionM :: String
                          -> Fraction
                          -> StructureM ()
    structureSetFractionM =
        marshalStructureSetM fraction $ \gValue fraction ->
            (\(GValue arg1) arg2 arg3 -> gst_value_set_fraction arg1 arg2 arg3) gValue
                                          (fromIntegral $ numerator fraction)
                                          (fromIntegral $ denominator fraction)

    marshalStructureFixateM :: (Structure -> CString -> a -> IO (CInt))
                            -> String
                            -> a
                            -> StructureM Bool
    marshalStructureFixateM fixate fieldname target =
        StructureM $ \structure ->
            withUTFString fieldname $ \cFieldname ->
                liftM toBool $
                    fixate structure cFieldname target

    structureFixateFieldNearestIntM :: String
                                    -> Int
                                    -> StructureM Bool
    structureFixateFieldNearestIntM =
        marshalStructureFixateM $ \structure cFieldname target ->
            (\(Structure arg1) arg2 arg3 -> withForeignPtr arg1 $ \argPtr1 ->gst_structure_fixate_field_nearest_int argPtr1 arg2 arg3)
    {-# LINE 320 "./Media/Streaming/GStreamer/Core/Structure.chs" #-}
                structure
                cFieldname
                (fromIntegral target)

    structureFixateFieldNearestDoubleM :: String
                                       -> Double
                                       -> StructureM Bool
    structureFixateFieldNearestDoubleM =
        marshalStructureFixateM $ \structure cFieldname target ->
            (\(Structure arg1) arg2 arg3 -> withForeignPtr arg1 $ \argPtr1 ->gst_structure_fixate_field_nearest_double argPtr1 arg2 arg3)
    {-# LINE 330 "./Media/Streaming/GStreamer/Core/Structure.chs" #-}
                structure
                cFieldname
                (realToFrac target)

    structureFixateFieldNearestFractionM :: String
                                         -> Fraction
                                         -> StructureM Bool
    structureFixateFieldNearestFractionM =
        marshalStructureFixateM $ \structure cFieldname target ->
                    (\(Structure arg1) arg2 arg3 arg4 -> withForeignPtr arg1 $ \argPtr1 ->gst_structure_fixate_field_nearest_fraction argPtr1 arg2 arg3 arg4)
    {-# LINE 340 "./Media/Streaming/GStreamer/Core/Structure.chs" #-}
                        structure
                        cFieldname
                        (fromIntegral $ numerator target)
                        (fromIntegral $ denominator target)

    structureFixateFieldBoolM :: String
                              -> Bool
                              -> StructureM Bool
    structureFixateFieldBoolM =
        marshalStructureFixateM $ \structure cFieldname target ->
                    (\(Structure arg1) arg2 arg3 -> withForeignPtr arg1 $ \argPtr1 ->gst_structure_fixate_field_boolean argPtr1 arg2 arg3)
    {-# LINE 351 "./Media/Streaming/GStreamer/Core/Structure.chs" #-}
                        structure
                        cFieldname
                        (fromBool target)

    fourcc = gst_fourcc_get_type
    {-# LINE 357 "./Media/Streaming/GStreamer/Core/Structure.chs" #-}
    date = gst_date_get_type
    fraction = gst_fraction_get_type

    foreign import ccall safe "gst_structure_empty_new"
      gst_structure_empty_new :: ((Ptr CChar) -> (IO (Ptr Structure)))

    foreign import ccall safe "gst_structure_to_string"
      gst_structure_to_string :: ((Ptr Structure) -> (IO (Ptr CChar)))

    foreign import ccall safe "gst_structure_from_string"
      gst_structure_from_string :: ((Ptr CChar) -> ((Ptr (Ptr CChar)) -> (IO (Ptr Structure))))

    foreign import ccall safe "g_utf8_pointer_to_offset"
      g_utf8_pointer_to_offset :: ((Ptr CChar) -> ((Ptr CChar) -> (IO CLong)))

    foreign import ccall safe "gst_structure_get_name"
      gst_structure_get_name :: ((Ptr Structure) -> (IO (Ptr CChar)))

    foreign import ccall safe "gst_structure_has_name"
      gst_structure_has_name :: ((Ptr Structure) -> ((Ptr CChar) -> (IO CInt)))

    foreign import ccall safe "gst_structure_get_boolean"
      gst_structure_get_boolean :: ((Ptr Structure) -> ((Ptr CChar) -> ((Ptr CInt) -> (IO CInt))))

    foreign import ccall safe "gst_structure_get_int"
      gst_structure_get_int :: ((Ptr Structure) -> ((Ptr CChar) -> ((Ptr CInt) -> (IO CInt))))

    foreign import ccall safe "gst_structure_get_fourcc"
      gst_structure_get_fourcc :: ((Ptr Structure) -> ((Ptr CChar) -> ((Ptr CUInt) -> (IO CInt))))

    foreign import ccall safe "gst_structure_get_double"
      gst_structure_get_double :: ((Ptr Structure) -> ((Ptr CChar) -> ((Ptr CDouble) -> (IO CInt))))

    foreign import ccall safe "gst_structure_get_string"
      gst_structure_get_string :: ((Ptr Structure) -> ((Ptr CChar) -> (IO (Ptr CChar))))

    foreign import ccall safe "gst_structure_get_date"
      gst_structure_get_date :: ((Ptr Structure) -> ((Ptr CChar) -> ((Ptr (Ptr ())) -> (IO CInt))))

    foreign import ccall safe "gst_structure_get_clock_time"
      gst_structure_get_clock_time :: ((Ptr Structure) -> ((Ptr CChar) -> ((Ptr CULLong) -> (IO CInt))))

    foreign import ccall safe "gst_structure_get_fraction"
      gst_structure_get_fraction :: ((Ptr Structure) -> ((Ptr CChar) -> ((Ptr CInt) -> ((Ptr CInt) -> (IO CInt)))))

    foreign import ccall safe "gst_structure_copy"
      gst_structure_copy :: ((Ptr Structure) -> (IO (Ptr Structure)))

    foreign import ccall safe "gst_structure_set_name"
      gst_structure_set_name :: ((Ptr Structure) -> ((Ptr CChar) -> (IO ())))

    foreign import ccall safe "gst_structure_remove_field"
      gst_structure_remove_field :: ((Ptr Structure) -> ((Ptr CChar) -> (IO ())))

    foreign import ccall safe "gst_structure_set_value"
      gst_structure_set_value :: ((Ptr Structure) -> ((Ptr CChar) -> ((Ptr GValue) -> (IO ()))))

    foreign import ccall safe "gst_value_set_fourcc"
      gst_value_set_fourcc :: ((Ptr GValue) -> (CUInt -> (IO ())))

    foreign import ccall safe "gst_value_set_date"
      gst_value_set_date :: ((Ptr GValue) -> ((Ptr ()) -> (IO ())))

    foreign import ccall safe "g_value_set_uint64"
      g_value_set_uint64 :: ((Ptr GValue) -> (CULLong -> (IO ())))

    foreign import ccall safe "gst_value_set_fraction"
      gst_value_set_fraction :: ((Ptr GValue) -> (CInt -> (CInt -> (IO ()))))

    foreign import ccall safe "gst_structure_fixate_field_nearest_int"
      gst_structure_fixate_field_nearest_int :: ((Ptr Structure) -> ((Ptr CChar) -> (CInt -> (IO CInt))))

    foreign import ccall safe "gst_structure_fixate_field_nearest_double"
      gst_structure_fixate_field_nearest_double :: ((Ptr Structure) -> ((Ptr CChar) -> (CDouble -> (IO CInt))))

    foreign import ccall safe "gst_structure_fixate_field_nearest_fraction"
      gst_structure_fixate_field_nearest_fraction :: ((Ptr Structure) -> ((Ptr CChar) -> (CInt -> (CInt -> (IO CInt)))))

    foreign import ccall safe "gst_structure_fixate_field_boolean"
      gst_structure_fixate_field_boolean :: ((Ptr Structure) -> ((Ptr CChar) -> (CInt -> (IO CInt))))

    foreign import ccall safe "gst_fourcc_get_type"
      gst_fourcc_get_type :: CUInt

    foreign import ccall safe "gst_date_get_type"
      gst_date_get_type :: CUInt

    foreign import ccall safe "gst_fraction_get_type"
      gst_fraction_get_type :: CUInt