/home/martin/workspace/OpenStreetNav/src/elements/Relation.cpp
Go to the documentation of this file.
00001 /*
00002  * Relation.cpp
00003  *
00004  *  Created on: Nov 5, 2011
00005  *      Author: martin
00006  */
00007 
00008 #include "Relation.h"
00009 #include "../osmdb/osmdb.h"
00010 #include "Node.h"
00011 #include "Way.h"
00012 
00013 namespace osm
00014 {
00015 
00016 Relation::Relation()
00017 {
00018 }
00019 
00020 Relation::Relation(int64_t id):
00021     id(id)
00022 {
00023 }
00024 
00025 Relation::~Relation()
00026 {
00027 }
00028 
00029 osm::ObjectType Relation::get_type() const
00030 {
00031     return ObjectType::Relation;
00032 }
00033 
00034 bool Relation::operator==(const Relation& r) const
00035 {
00036     return r.id == id && tags == r.tags &&
00037            util::multimap_eq < decltype(deref_eq_by_id(members.begin()->second, members.begin()->second)) > (members, r.members);
00038 }
00039 
00040 bool Relation::operator!=(const Relation& r) const
00041 {
00042     return !(*this == r);
00043 }
00044 
00045 boost::property_tree::ptree Relation::get_description()
00046 {
00047     boost::property_tree::ptree ret;
00048     boost::property_tree::ptree rel;
00049     rel.data() = util::to_str(id);
00050     boost::property_tree::ptree tags_desc;
00051     for (auto it = tags.begin(); it != tags.end(); ++it)
00052     {
00053         tags_desc.push_back(*it);
00054     }
00055     rel.put_child("tags", tags_desc);
00056     boost::property_tree::ptree mmbrs;
00057     for (auto it = members.begin(); it != members.end(); ++it)
00058     {
00059         boost::property_tree::ptree mem;
00060         mem.put("role", it->first);
00061         mem.push_back(it->second->get_description().front());
00062         mmbrs.add_child("member", mem);
00063     }
00064     rel.put_child("members", mmbrs);
00065     ret.put_child("relation", rel);
00066     return ret;
00067 }
00068 
00069 void Relation::fill(osmdb::PropertiesSelection& db)
00070 {
00071     tags = db.get_relation_tags(id);
00072     auto m = db.get_node_members(id);
00073     for (auto it = m.begin(); it != m.end(); ++it)
00074     {
00075         members.insert(std::pair<std::string, std::shared_ptr<osm::Element> >(it->first, std::shared_ptr < osm::Element > (new osm::Node(it->second))));
00076     }
00077     m = db.get_way_members(id);
00078     for (auto it = m.begin(); it != m.end(); ++it)
00079     {
00080         members.insert(std::pair<std::string, std::shared_ptr<osm::Element> >(it->first, std::shared_ptr < osm::Element > (new osm::Way(it->second))));
00081     }
00082     m = db.get_relation_members(id);
00083     for (auto it = m.begin(); it != m.end(); ++it)
00084     {
00085         members.insert(std::pair<std::string, std::shared_ptr<osm::Element> >(it->first, std::shared_ptr < osm::Element > (new osm::Relation(it->second))));
00086     }
00087     for (auto it = members.begin(); it != members.end(); ++it)
00088     {
00089         it->second->fill(db);
00090     }
00091 }
00092 
00093 void Relation::add_to_relation(osmdb::ElementImporter& db, int64_t relation, const std::string& role)
00094 {
00095     db.insert_member_relation(relation, role, id);
00096 }
00097 
00098 void Relation::add_node(const std::string& role, const osm::Node& nd)
00099 {
00100     add_member_ptr(role, new osm::Node(nd));
00101 }
00102 
00103 void Relation::add_way(const std::string& role, const osm::Way& w)
00104 {
00105     add_member_ptr(role, new osm::Way(w));
00106 }
00107 
00108 void Relation::add_rel(const std::string& role, const osm::Relation& r)
00109 {
00110     add_member_ptr(role, new osm::Relation(r));
00111 }
00112 
00113 int64_t Relation::get_id() const
00114 {
00115     return id;
00116 }
00117 
00118 void Relation::add_member_ptr(const std::string& role, osm::Element* ptr)
00119 {
00120     members.insert(std::pair<std::string, std::shared_ptr<osm::Element> >(role, std::shared_ptr<osm::Element>(ptr)));
00121 }
00122 
00123 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines