Osmium
0.1
|
00001 #ifndef OSMIUM_OSM_NODE_HPP 00002 #define OSMIUM_OSM_NODE_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/position.hpp> 00028 00033 #include <osmium/osm/object.hpp> 00034 00035 namespace Osmium { 00036 00037 namespace OSM { 00038 00039 class Node : public Object, boost::less_than_comparable<Node> { 00040 00041 static const int max_length_coordinate = 12 + 1; 00042 00043 Position m_position; 00044 00045 public: 00046 00047 Node() : Object(), m_position() { 00048 #ifdef OSMIUM_WITH_JAVASCRIPT 00049 v8::HandleScope handle_scope; 00050 js_object_instance = v8::Persistent<v8::Object>::New(JavascriptTemplate::get<JavascriptTemplate>().create_instance(this)); 00051 #endif // OSMIUM_WITH_JAVASCRIPT 00052 } 00053 00054 const Position position() const { 00055 return m_position; 00056 } 00057 00058 Node& position(Position position) { 00059 m_position = position; 00060 return *this; 00061 } 00062 00063 osm_object_type_t get_type() const { 00064 return NODE; 00065 } 00066 00067 void set_x(double x) { 00068 m_position.lon(x); 00069 } 00070 00071 void set_y(double y) { 00072 m_position.lat(y); 00073 } 00074 00075 double get_lon() const { 00076 return m_position.lon(); 00077 } 00078 00079 double get_lat() const { 00080 return m_position.lat(); 00081 } 00082 00083 #ifdef OSMIUM_WITH_JAVASCRIPT 00084 v8::Handle<v8::Value> js_get_geom() const; 00085 00086 struct JavascriptTemplate : public Osmium::OSM::Object::JavascriptTemplate { 00087 00088 JavascriptTemplate() : Osmium::OSM::Object::JavascriptTemplate() { 00089 js_template->SetAccessor(v8::String::NewSymbol("geom"), accessor_getter<Node, &Node::js_get_geom>); 00090 } 00091 00092 }; 00093 #endif // OSMIUM_WITH_JAVASCRIPT 00094 00100 friend bool operator<(const Node& lhs, const Node& rhs) { 00101 if (lhs.id() == rhs.id()) { 00102 return lhs.version() < rhs.version(); 00103 } else { 00104 return abs(lhs.id()) < abs(rhs.id()); 00105 } 00106 } 00107 00111 friend bool operator<(const shared_ptr<Node const>& lhs, const shared_ptr<Node const>& rhs) { 00112 return *lhs < *rhs; 00113 } 00114 00115 }; // class Node 00116 00117 } // namespace OSM 00118 00119 } // namespace Osmium 00120 00121 #endif // OSMIUM_OSM_NODE_HPP