module Data.Geo.OSM.OSM
(
OSM
, osm
, readOsmFile
, readOsmFiles
, interactOSMIO
, interactsOSMIO
, interactOSMIO'
, interactsOSMIO'
, interactOSM
, interactsOSM
, interactOSM'
, interactsOSM'
) where
import Prelude hiding (mapM, foldr)
import Text.XML.HXT.Core
import Control.Monad hiding (mapM)
import Data.Foldable
import Data.Traversable
import Data.Geo.OSM.Children
import Data.Geo.OSM.Bound
import Data.Geo.OSM.Bounds
import Data.Geo.OSM.BoundOption
import Data.Lens.Common
import Control.Comonad.Trans.Store
import Data.Geo.OSM.Lens.VersionL
import Data.Geo.OSM.Lens.GeneratorL
import Data.Geo.OSM.Lens.BoundsL
import Data.Geo.OSM.Lens.ChildrenL
import Data.Monoid
data OSM =
OSM String (Maybe String) (Maybe (Either Bound Bounds)) Children
deriving Eq
instance XmlPickler OSM where
xpickle =
xpElem "osm" (xpWrap (\(version', generator', bound', nwr') -> osm version' generator' bound' nwr', \(OSM version' generator' bound' nwr') -> (version', generator', bound', nwr'))
(xp4Tuple (xpAttr "version" xpText)
(xpOption (xpAttr "generator" xpText))
(xpOption (xpAlt (either (const 0) (const 1)) [xpWrap (Left, \(Left b) -> b) xpickle, xpWrap (Right, \(Right b) -> b) xpickle]))
xpickle))
instance Show OSM where
show =
showPickled []
instance VersionL OSM String where
versionL =
Lens $ \(OSM version generator bounds children) -> store (\version -> OSM version generator bounds children) version
instance BoundsL OSM where
boundsL =
Lens $ \(OSM version generator bounds children) -> store (\bounds -> OSM version generator (foldBoundOption (Just . Left) (Just . Right) Nothing bounds) children) $
case bounds of
Nothing -> optionEmptyBound
Just (Left b) -> optionBound b
Just (Right b) -> optionBounds b
instance GeneratorL OSM where
generatorL =
Lens $ \(OSM version generator bounds children) -> store (\generator -> OSM version generator bounds children) generator
instance ChildrenL OSM where
childrenL =
Lens $ \(OSM version generator bounds children) -> store (\children -> OSM version generator bounds children) children
osm ::
String
-> Maybe String
-> Maybe (Either Bound Bounds)
-> Children
-> OSM
osm =
OSM
readOsmFile ::
FilePath
-> IO [OSM]
readOsmFile =
runX . xunpickleDocument (xpickle :: PU OSM) ([withRemoveWS yes, withFileMimeType v_1])
readOsmFiles ::
[FilePath]
-> IO [OSM]
readOsmFiles =
fmap join . mapM readOsmFile
interactOSMIO' ::
(OSM -> IO OSM)
-> SysConfigList
-> FilePath
-> SysConfigList
-> FilePath
-> IO ()
interactOSMIO' f froma from toa to =
runX (xunpickleDocument (xpickle :: PU OSM) froma from >>> arrIO f >>> xpickleDocument (xpickle :: PU OSM) toa to) >> return ()
interactsOSMIO' ::
Foldable t =>
t (OSM -> IO OSM)
-> SysConfigList
-> FilePath
-> SysConfigList
-> FilePath
-> IO ()
interactsOSMIO' =
interactOSMIO' . sumM
interactOSMIO ::
(OSM -> IO OSM)
-> FilePath
-> FilePath
-> IO ()
interactOSMIO f from =
interactOSMIO' f [withRemoveWS yes, withFileMimeType v_1] from [withIndent yes, withFileMimeType v_1]
interactsOSMIO ::
Foldable t =>
t (OSM -> IO OSM)
-> FilePath
-> FilePath
-> IO ()
interactsOSMIO =
interactOSMIO . sumM
interactOSM' ::
(OSM -> OSM)
-> SysConfigList
-> FilePath
-> SysConfigList
-> FilePath
-> IO ()
interactOSM' f =
interactOSMIO' (return . f)
interactsOSM' ::
Foldable t =>
t (OSM -> OSM)
-> SysConfigList
-> FilePath
-> SysConfigList
-> FilePath
-> IO ()
interactsOSM' =
interactOSM' . sum'
interactOSM ::
(OSM -> OSM)
-> FilePath
-> FilePath
-> IO ()
interactOSM f =
interactOSMIO (return . f)
interactsOSM ::
Foldable t =>
t (OSM -> OSM)
-> FilePath
-> FilePath
-> IO ()
interactsOSM =
interactOSM . sum'
sum' ::
Foldable t =>
t (a -> a)
-> a
-> a
sum' =
appEndo . foldMap Endo
sumM ::
(Monad m, Foldable t) =>
t (a -> m a)
-> a
-> m a
sumM =
foldr (>=>) return