Osmium  0.1
include/osmium/osm/relation.hpp
Go to the documentation of this file.
00001 #ifndef OSMIUM_OSM_RELATION_HPP
00002 #define OSMIUM_OSM_RELATION_HPP
00003 
00004 /*
00005 
00006 Copyright 2011 Jochen Topf <jochen@topf.org> and others (see README).
00007 
00008 This file is part of Osmium (https://github.com/joto/osmium).
00009 
00010 Osmium is free software: you can redistribute it and/or modify it under the
00011 terms of the GNU Lesser General Public License or (at your option) the GNU
00012 General Public License as published by the Free Software Foundation, either
00013 version 3 of the Licenses, or (at your option) any later version.
00014 
00015 Osmium is distributed in the hope that it will be useful, but WITHOUT ANY
00016 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
00017 PARTICULAR PURPOSE. See the GNU Lesser General Public License and the GNU
00018 General Public License for more details.
00019 
00020 You should have received a copy of the Licenses along with Osmium. If not, see
00021 <http://www.gnu.org/licenses/>.
00022 
00023 */
00024 
00025 #include <boost/operators.hpp>
00026 
00027 #include <osmium/osm/object.hpp>
00028 #include <osmium/osm/relation_member_list.hpp>
00029 
00030 namespace Osmium {
00031 
00032     namespace OSM {
00033 
00034         class Relation : public Object, boost::less_than_comparable<Relation> {
00035 
00036         public:
00037 
00038             Relation() : Object(), m_members() {
00039 #ifdef OSMIUM_WITH_JAVASCRIPT
00040                 v8::HandleScope handle_scope;
00041                 js_object_instance = v8::Persistent<v8::Object>::New(JavascriptTemplate::get<JavascriptTemplate>().create_instance(this));
00042 #endif // OSMIUM_WITH_JAVASCRIPT
00043             }
00044 
00045             Relation(const Relation &r) : Object(r) {
00046                 m_members = r.members();
00047 #ifdef OSMIUM_WITH_JAVASCRIPT
00048                 v8::HandleScope handle_scope;
00049                 js_object_instance = v8::Persistent<v8::Object>::New(JavascriptTemplate::get<JavascriptTemplate>().create_instance(this));
00050 #endif // OSMIUM_WITH_JAVASCRIPT
00051             }
00052 
00053             const RelationMemberList& members() const {
00054                 return m_members;
00055             }
00056 
00057             osm_object_type_t get_type() const {
00058                 return RELATION;
00059             }
00060 
00061             void add_member(const char type, osm_object_id_t ref, const char *role) {
00062                 m_members.add_member(type, ref, role);
00063             }
00064 
00065             const RelationMember *get_member(osm_sequence_id_t index) const {
00066                 if (index < m_members.size()) {
00067                     return &m_members[index];
00068                 }
00069                 return NULL;
00070             }
00071 
00072 #ifdef OSMIUM_WITH_JAVASCRIPT
00073             v8::Handle<v8::Value> js_members() const {
00074                 return members().js_instance();
00075             }
00076 
00077             struct JavascriptTemplate : public Osmium::OSM::Object::JavascriptTemplate {
00078 
00079                 JavascriptTemplate() : Osmium::OSM::Object::JavascriptTemplate() {
00080                     js_template->SetAccessor(v8::String::NewSymbol("members"), accessor_getter<Relation, &Relation::js_members>);
00081                 }
00082 
00083             };
00084 #endif // OSMIUM_WITH_JAVASCRIPT
00085 
00091             friend bool operator<(const Relation& lhs, const Relation& rhs) {
00092                 if (lhs.id() == rhs.id()) {
00093                     return lhs.version() < rhs.version();
00094                 } else {
00095                     return abs(lhs.id()) < abs(rhs.id());
00096                 }
00097             }
00098 
00102             friend bool operator<(const shared_ptr<Relation const>& lhs, const shared_ptr<Relation const>& rhs) {
00103                 return *lhs < *rhs;
00104             }
00105 
00106         private:
00107 
00108             RelationMemberList m_members;
00109 
00110         }; // class Relation
00111 
00112     } // namespace OSM
00113 
00114 } // namespace Osmium
00115 
00116 #endif // OSMIUM_OSM_RELATION_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines