annotate DEPENDENCIES/generic/include/boost/geometry/multi/io/wkt/read.hpp @ 16:2665513ce2d3

Add boost headers
author Chris Cannam
date Tue, 05 Aug 2014 11:11:38 +0100
parents
children c530137014c0
rev   line source
Chris@16 1 // Boost.Geometry (aka GGL, Generic Geometry Library)
Chris@16 2
Chris@16 3 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
Chris@16 4 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
Chris@16 5 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
Chris@16 6
Chris@16 7 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
Chris@16 8 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
Chris@16 9
Chris@16 10 // Use, modification and distribution is subject to the Boost Software License,
Chris@16 11 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
Chris@16 12 // http://www.boost.org/LICENSE_1_0.txt)
Chris@16 13
Chris@16 14 #ifndef BOOST_GEOMETRY_MULTI_IO_WKT_READ_MULTI_HPP
Chris@16 15 #define BOOST_GEOMETRY_MULTI_IO_WKT_READ_MULTI_HPP
Chris@16 16
Chris@16 17 #include <string>
Chris@16 18
Chris@16 19 #include <boost/geometry/core/mutable_range.hpp>
Chris@16 20 #include <boost/geometry/multi/core/tags.hpp>
Chris@16 21 #include <boost/geometry/multi/core/point_type.hpp>
Chris@16 22 #include <boost/geometry/multi/geometries/concepts/check.hpp>
Chris@16 23 #include <boost/geometry/multi/io/wkt/detail/prefix.hpp>
Chris@16 24 #include <boost/geometry/io/wkt/read.hpp>
Chris@16 25
Chris@16 26 namespace boost { namespace geometry
Chris@16 27 {
Chris@16 28
Chris@16 29 namespace detail { namespace wkt
Chris@16 30 {
Chris@16 31
Chris@16 32 template <typename MultiGeometry, template<typename> class Parser, typename PrefixPolicy>
Chris@16 33 struct multi_parser
Chris@16 34 {
Chris@16 35 static inline void apply(std::string const& wkt, MultiGeometry& geometry)
Chris@16 36 {
Chris@16 37 traits::clear<MultiGeometry>::apply(geometry);
Chris@16 38
Chris@16 39 tokenizer tokens(wkt, boost::char_separator<char>(" ", ",()"));
Chris@16 40 tokenizer::iterator it;
Chris@16 41 if (initialize<MultiGeometry>(tokens, PrefixPolicy::apply(), wkt, it))
Chris@16 42 {
Chris@16 43 handle_open_parenthesis(it, tokens.end(), wkt);
Chris@16 44
Chris@16 45 // Parse sub-geometries
Chris@16 46 while(it != tokens.end() && *it != ")")
Chris@16 47 {
Chris@16 48 traits::resize<MultiGeometry>::apply(geometry, boost::size(geometry) + 1);
Chris@16 49 Parser
Chris@16 50 <
Chris@16 51 typename boost::range_value<MultiGeometry>::type
Chris@16 52 >::apply(it, tokens.end(), wkt, *(boost::end(geometry) - 1));
Chris@16 53 if (it != tokens.end() && *it == ",")
Chris@16 54 {
Chris@16 55 // Skip "," after multi-element is parsed
Chris@16 56 ++it;
Chris@16 57 }
Chris@16 58 }
Chris@16 59
Chris@16 60 handle_close_parenthesis(it, tokens.end(), wkt);
Chris@16 61 }
Chris@16 62
Chris@16 63 check_end(it, tokens.end(), wkt);
Chris@16 64 }
Chris@16 65 };
Chris@16 66
Chris@16 67 template <typename P>
Chris@16 68 struct noparenthesis_point_parser
Chris@16 69 {
Chris@16 70 static inline void apply(tokenizer::iterator& it, tokenizer::iterator end,
Chris@16 71 std::string const& wkt, P& point)
Chris@16 72 {
Chris@16 73 parsing_assigner<P, 0, dimension<P>::value>::apply(it, end, point, wkt);
Chris@16 74 }
Chris@16 75 };
Chris@16 76
Chris@16 77 template <typename MultiGeometry, typename PrefixPolicy>
Chris@16 78 struct multi_point_parser
Chris@16 79 {
Chris@16 80 static inline void apply(std::string const& wkt, MultiGeometry& geometry)
Chris@16 81 {
Chris@16 82 traits::clear<MultiGeometry>::apply(geometry);
Chris@16 83
Chris@16 84 tokenizer tokens(wkt, boost::char_separator<char>(" ", ",()"));
Chris@16 85 tokenizer::iterator it;
Chris@16 86
Chris@16 87 if (initialize<MultiGeometry>(tokens, PrefixPolicy::apply(), wkt, it))
Chris@16 88 {
Chris@16 89 handle_open_parenthesis(it, tokens.end(), wkt);
Chris@16 90
Chris@16 91 // If first point definition starts with "(" then parse points as (x y)
Chris@16 92 // otherwise as "x y"
Chris@16 93 bool using_brackets = (it != tokens.end() && *it == "(");
Chris@16 94
Chris@16 95 while(it != tokens.end() && *it != ")")
Chris@16 96 {
Chris@16 97 traits::resize<MultiGeometry>::apply(geometry, boost::size(geometry) + 1);
Chris@16 98
Chris@16 99 if (using_brackets)
Chris@16 100 {
Chris@16 101 point_parser
Chris@16 102 <
Chris@16 103 typename boost::range_value<MultiGeometry>::type
Chris@16 104 >::apply(it, tokens.end(), wkt, *(boost::end(geometry) - 1));
Chris@16 105 }
Chris@16 106 else
Chris@16 107 {
Chris@16 108 noparenthesis_point_parser
Chris@16 109 <
Chris@16 110 typename boost::range_value<MultiGeometry>::type
Chris@16 111 >::apply(it, tokens.end(), wkt, *(boost::end(geometry) - 1));
Chris@16 112 }
Chris@16 113
Chris@16 114 if (it != tokens.end() && *it == ",")
Chris@16 115 {
Chris@16 116 // Skip "," after point is parsed
Chris@16 117 ++it;
Chris@16 118 }
Chris@16 119 }
Chris@16 120
Chris@16 121 handle_close_parenthesis(it, tokens.end(), wkt);
Chris@16 122 }
Chris@16 123
Chris@16 124 check_end(it, tokens.end(), wkt);
Chris@16 125 }
Chris@16 126 };
Chris@16 127
Chris@16 128 }} // namespace detail::wkt
Chris@16 129
Chris@16 130 #ifndef DOXYGEN_NO_DISPATCH
Chris@16 131 namespace dispatch
Chris@16 132 {
Chris@16 133
Chris@16 134 template <typename MultiGeometry>
Chris@16 135 struct read_wkt<multi_point_tag, MultiGeometry>
Chris@16 136 : detail::wkt::multi_point_parser
Chris@16 137 <
Chris@16 138 MultiGeometry,
Chris@16 139 detail::wkt::prefix_multipoint
Chris@16 140 >
Chris@16 141 {};
Chris@16 142
Chris@16 143 template <typename MultiGeometry>
Chris@16 144 struct read_wkt<multi_linestring_tag, MultiGeometry>
Chris@16 145 : detail::wkt::multi_parser
Chris@16 146 <
Chris@16 147 MultiGeometry,
Chris@16 148 detail::wkt::linestring_parser,
Chris@16 149 detail::wkt::prefix_multilinestring
Chris@16 150 >
Chris@16 151 {};
Chris@16 152
Chris@16 153 template <typename MultiGeometry>
Chris@16 154 struct read_wkt<multi_polygon_tag, MultiGeometry>
Chris@16 155 : detail::wkt::multi_parser
Chris@16 156 <
Chris@16 157 MultiGeometry,
Chris@16 158 detail::wkt::polygon_parser,
Chris@16 159 detail::wkt::prefix_multipolygon
Chris@16 160 >
Chris@16 161 {};
Chris@16 162
Chris@16 163 } // namespace dispatch
Chris@16 164 #endif // DOXYGEN_NO_DISPATCH
Chris@16 165
Chris@16 166 }} // namespace boost::geometry
Chris@16 167
Chris@16 168 #endif // BOOST_GEOMETRY_MULTI_IO_WKT_READ_MULTI_HPP