Osmium
0.1
|
00001 #ifndef OSMIUM_HANDLER_ENDTIME_HPP 00002 #define OSMIUM_HANDLER_ENDTIME_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 namespace Osmium { 00026 00027 namespace Handler { 00028 00034 template <class THandler> 00035 class EndTime : public Base { 00036 00037 public: 00038 00039 EndTime(THandler* handler) : Base(), m_handler(handler) { 00040 } 00041 00042 void init(Osmium::OSM::Meta& meta) { 00043 m_handler->init(meta); 00044 } 00045 00046 void before_nodes() { 00047 m_handler->before_nodes(); 00048 } 00049 00050 void node(const shared_ptr<Osmium::OSM::Node>& node) { 00051 if (m_last_node) { 00052 if (node->id() == m_last_node->id()) { 00053 m_last_node->endtime(node->timestamp()); 00054 } 00055 m_handler->node(m_last_node); 00056 } 00057 m_last_node = node; 00058 } 00059 00060 void after_nodes() { 00061 if (m_last_node) { 00062 m_handler->node(m_last_node); 00063 m_last_node.reset(); 00064 } 00065 m_handler->after_nodes(); 00066 } 00067 00068 void before_ways() { 00069 m_handler->before_ways(); 00070 } 00071 00072 void way(const shared_ptr<Osmium::OSM::Way>& way) { 00073 if (m_last_way) { 00074 if (way->id() == m_last_way->id()) { 00075 m_last_way->endtime(way->timestamp()); 00076 } 00077 m_handler->way(m_last_way); 00078 } 00079 m_last_way = way; 00080 } 00081 00082 void after_ways() { 00083 if (m_last_way) { 00084 m_handler->way(m_last_way); 00085 m_last_way.reset(); 00086 } 00087 m_handler->after_ways(); 00088 } 00089 00090 void before_relations() { 00091 m_handler->before_relations(); 00092 } 00093 00094 void relation(const shared_ptr<Osmium::OSM::Relation>& relation) { 00095 if (m_last_relation) { 00096 if (relation->id() == m_last_relation->id()) { 00097 m_last_relation->endtime(relation->timestamp()); 00098 } 00099 m_handler->relation(m_last_relation); 00100 } 00101 m_last_relation = relation; 00102 } 00103 00104 void after_relations() { 00105 if (m_last_relation) { 00106 m_handler->relation(m_last_relation); 00107 m_last_relation.reset(); 00108 } 00109 m_handler->after_relations(); 00110 } 00111 00112 void final() { 00113 m_handler->final(); 00114 } 00115 00116 private: 00117 00118 THandler* m_handler; 00119 00120 shared_ptr<Osmium::OSM::Node> m_last_node; 00121 shared_ptr<Osmium::OSM::Way> m_last_way; 00122 shared_ptr<Osmium::OSM::Relation> m_last_relation; 00123 00124 }; // class EndTime 00125 00126 } // namespace Handler 00127 00128 } // namespace Osmium 00129 00130 #endif // OSMIUM_HANDLER_ENDTIME_HPP