~ubuntu-branches/ubuntu/saucy/merkaartor/saucy

« back to all changes in this revision

Viewing changes to include/builtin-ggl/ggl/algorithms/parse.hpp

Tags: upstream-0.15.3+svn20934
ImportĀ upstreamĀ versionĀ 0.15.3+svn20934

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Generic Geometry Library
 
2
//
 
3
// Copyright Bruno Lalande 2008, 2009
 
4
// Copyright Barend Gehrels 1995-2009, Geodan Holding B.V. Amsterdam, the Netherlands.
 
5
// Use, modification and distribution is subject to the Boost Software License,
 
6
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
 
7
// http://www.boost.org/LICENSE_1_0.txt)
 
8
 
 
9
#ifndef GGL_ALGORITHMS_PARSE_HPP
 
10
#define GGL_ALGORITHMS_PARSE_HPP
 
11
 
 
12
#include <string>
 
13
 
 
14
#include <boost/concept/requires.hpp>
 
15
 
 
16
#include <ggl/core/tags.hpp>
 
17
#include <ggl/core/concepts/point_concept.hpp>
 
18
#include <ggl/strategies/strategies.hpp>
 
19
 
 
20
// TODO: remove used EXTENSION here (result should be part of parsing strategy)
 
21
#include <ggl/extensions/gis/latlong/strategies/dms_parser.hpp>
 
22
 
 
23
/*!
 
24
\defgroup parse parse and assign string values
 
25
*/
 
26
 
 
27
namespace ggl
 
28
{
 
29
 
 
30
#ifndef DOXYGEN_NO_DETAIL
 
31
namespace detail
 
32
{
 
33
 
 
34
} // namespace detail
 
35
#endif // DOXYGEN_NO_DETAIL
 
36
 
 
37
 
 
38
#ifndef DOXYGEN_NO_DISPATCH
 
39
namespace dispatch
 
40
{
 
41
template <typename Tag, typename G>
 
42
struct parsing
 
43
{
 
44
};
 
45
 
 
46
template <typename P>
 
47
struct parsing<point_tag, P>
 
48
{
 
49
    template <typename S>
 
50
    static inline void parse(P& point, std::string const& c1, std::string const& c2, S const& strategy)
 
51
    {
 
52
        assert_dimension<P, 2>();
 
53
        dms_result r1 = strategy(c1.c_str());
 
54
        dms_result r2 = strategy(c2.c_str());
 
55
 
 
56
        if (0 == r1.axis())
 
57
            set<0>(point, r1);
 
58
        else
 
59
            set<1>(point, r1);
 
60
 
 
61
        if (0 == r2.axis())
 
62
            set<0>(point, r2);
 
63
        else
 
64
            set<1>(point, r2);
 
65
    }
 
66
 
 
67
    static inline void parse(P& point, std::string const& c1, std::string const& c2)
 
68
    {
 
69
        // strategy-parser corresponding to degree/radian
 
70
        typename strategy_parse
 
71
            <
 
72
            typename cs_tag<P>::type,
 
73
            typename coordinate_system<P>::type
 
74
            >::type strategy;
 
75
 
 
76
        parse(point, c1, c2, strategy);
 
77
    }
 
78
};
 
79
 
 
80
} // namespace dispatch
 
81
#endif // DOXYGEN_NO_DISPATCH
 
82
 
 
83
 
 
84
/*!
 
85
    \brief parse two strings to a spherical/geographic point, using W/E/N/S
 
86
    \ingroup parse
 
87
 */
 
88
template <typename G>
 
89
inline void parse(G& geometry, const std::string& c1, const std::string& c2)
 
90
{
 
91
    dispatch::parsing<typename tag<G>::type, G>::parse(geometry, c1, c2);
 
92
}
 
93
 
 
94
/*!
 
95
    \brief parse two strings to a spherical/geographic point, using a specified strategy
 
96
    \details user can use N/E/S/O or N/O/Z/W or other formats
 
97
    \ingroup parse
 
98
 */
 
99
template <typename G, typename S>
 
100
inline void parse(G& geometry, const std::string& c1, const std::string& c2, S const& strategy)
 
101
{
 
102
    dispatch::parsing<typename tag<G>::type, G>::parse(geometry, c1, c2, strategy);
 
103
}
 
104
 
 
105
// There will be a parsing function with three arguments (ANGLE,ANGLE,RADIUS)
 
106
 
 
107
template <typename G>
 
108
inline G parse(const std::string& c1, const std::string& c2)
 
109
{
 
110
    G geometry;
 
111
    dispatch::parsing<typename tag<G>::type, G>::parse(geometry, c1, c2);
 
112
    return geometry;
 
113
}
 
114
 
 
115
} // namespace ggl
 
116
 
 
117
#endif // GGL_ALGORITHMS_PARSE_HPP