module Data.Geo.GPX.Gpx(
Gpx,
gpx,
readGpxFile,
readGpxFiles,
interactGpxIO,
interactsGpxIO,
interactGpxIO',
interactsGpxIO',
interactGpx,
interactsGpx,
interactGpx',
interactsGpx'
) where
import Text.XML.HXT.Arrow
import Control.Monad
import Data.List
import Data.Geo.GPX.GpxType
import Data.Geo.GPX.PersonType
import Data.Geo.GPX.Accessor.Value
import Data.Geo.GPX.Accessor.Version
import Data.Geo.GPX.Accessor.Creator
import Data.Geo.GPX.Accessor.Metadata
import Data.Geo.GPX.Accessor.Wpts
import Data.Geo.GPX.Accessor.Rtes
import Data.Geo.GPX.Accessor.Trks
import Data.Geo.GPX.Accessor.Extensions
import Data.Geo.GPX.Accessor.Name
import Data.Geo.GPX.Accessor.Desc
import Data.Geo.GPX.Accessor.Author
import Data.Geo.GPX.Accessor.Copyright
import Data.Geo.GPX.Accessor.Links
import Data.Geo.GPX.Accessor.Time
import Data.Geo.GPX.Accessor.Keywords
import Data.Geo.GPX.Accessor.Bounds
import Data.Geo.GPX.Accessor.Rtepts
import Data.Geo.GPX.Accessor.Trkpts
newtype Gpx = Gpx GpxType
deriving (Eq, Version, Creator, Metadata, Wpts, Rtes, Trks, Extensions, Name, Desc, Copyright, Links, Time, Keywords, Bounds, Rtepts, Trkpts)
instance Author Gpx (Maybe PersonType) where
author = author . value
setAuthor = (gpx .) . (. value) . setAuthor
gpx :: GpxType
-> Gpx
gpx = Gpx
instance Show Gpx where
show (Gpx n) = show n
instance XmlPickler Gpx where
xpickle = xpWrap (gpx, \(Gpx n) -> n) (xpElem "gpx" xpickle)
instance Value Gpx GpxType where
value (Gpx x) = x
setValue x (Gpx _) = gpx x
readGpxFile :: FilePath -> IO [Gpx]
readGpxFile = runX . xunpickleDocument (xpickle :: PU Gpx) [(a_remove_whitespace, v_1)]
readGpxFiles :: [FilePath] -> IO [Gpx]
readGpxFiles = fmap join . (mapM readGpxFile)
interactGpxIO' :: Attributes
-> FilePath
-> (Gpx -> IO Gpx)
-> Attributes
-> FilePath
-> IO ()
interactGpxIO' froma from f toa to = runX (xunpickleDocument (xpickle :: PU Gpx) froma from >>> arrIO f >>> xpickleDocument (xpickle :: PU Gpx) toa to) >> return ()
interactsGpxIO' :: Attributes
-> FilePath
-> [Gpx -> IO Gpx]
-> Attributes
-> FilePath
-> IO ()
interactsGpxIO' froma from = interactGpxIO' froma from . sumIO'
interactGpxIO :: FilePath
-> (Gpx -> IO Gpx)
-> FilePath
-> IO ()
interactGpxIO from f = interactGpxIO' [(a_remove_whitespace, v_1)] from f [(a_indent, v_1)]
interactsGpxIO :: FilePath
-> [Gpx -> IO Gpx]
-> FilePath
-> IO ()
interactsGpxIO from = interactGpxIO from . sumIO'
interactGpx' :: Attributes
-> FilePath
-> (Gpx -> Gpx)
-> Attributes
-> FilePath
-> IO ()
interactGpx' froma from f = interactGpxIO' froma from (return . f)
interactsGpx' :: Attributes
-> FilePath
-> [Gpx -> Gpx]
-> Attributes
-> FilePath
-> IO ()
interactsGpx' froma from = interactGpx' froma from . sum'
interactGpx :: FilePath
-> (Gpx -> Gpx)
-> FilePath
-> IO ()
interactGpx from f = interactGpxIO from (return . f)
interactsGpx :: FilePath
-> [Gpx -> Gpx]
-> FilePath
-> IO ()
interactsGpx from = interactGpx from . sum'
sum' :: [a -> a] -> a -> a
sum' = foldl' (.) id
sumIO' :: (Monad m) => [a -> m a] -> a -> m a
sumIO' x = foldl' (>=>) return x