1 /***************************************************************************
2 * Copyright (C) 2016 by pgRouting developers *
3 * project@pgrouting.org *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License t &or more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20
21
22 #include <boost/lexical_cast.hpp>
23 #include <string>
24 #include "osm_elements/Relation.h"
25
26 namespace osm2pgr {
27
28
Relation(const char ** atts)29 Relation::Relation(const char **atts) :
30 Element(atts) { }
31
32
33
34 int64_t
add_member(const char ** atts)35 Relation::add_member(const char **atts) {
36 #if 0
37 std::cout << " --> " << __PRETTY_FUNCTION__ << "\n";
38 #endif
39 auto **attribut = atts;
40 std::string type;
41 int64_t osm_id(0);
42 std::string role;
43 while (*attribut != NULL) {
44 std::string key = *attribut++;
45 std::string value = *attribut++;
46 /*
47 * currently only adding way
48 */
49 if (key == "type") {
50 if (value != "way") return -1;
51 }
52 if (key == "ref") {
53 osm_id = boost::lexical_cast<int64_t>(value);
54 }
55 if (key == "role") {
56 role = value;
57 }
58 }
59 m_WayRefs.push_back(osm_id);
60 #if 0
61 std::cout << "members" << members_str() << "\n";
62 std::cout << " <-- " << __PRETTY_FUNCTION__ << "\n";
63 #endif
64 return osm_id;
65 }
66
67 std::string
members_str() const68 Relation::members_str() const {
69 std::string way_list("");
70 for (const auto &way_ref : m_WayRefs) {
71 way_list += boost::lexical_cast<std::string>(way_ref)
72 /*
73 * currently only adding way
74 */
75 + "=>\"type=>way\",";
76 }
77 way_list[way_list.size() -1] = ' ';
78
79 return way_list;
80 }
81
operator <<(std::ostream & os,const Relation & r)82 std::ostream& operator<<(std::ostream &os, const Relation &r) {
83 os << r.members_str();
84 return os;
85 }
86
87 } // end namespace osm2pgr
88
89