Osmium  0.1
include/osmium/handler/debug.hpp
Go to the documentation of this file.
00001 #ifndef OSMIUM_HANDLER_DEBUG_HPP
00002 #define OSMIUM_HANDLER_DEBUG_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 
00033         class Debug : public Base {
00034 
00035         public:
00036 
00037             Debug(bool has_multiple_object_versions=false) : Base(), m_has_multiple_object_versions(has_multiple_object_versions) {
00038             }
00039 
00040             void init(Osmium::OSM::Meta& meta) {
00041                 std::cout << "meta:\n";
00042                 if (meta.has_multiple_object_versions()) {
00043                     m_has_multiple_object_versions = true;
00044                 }
00045 
00046                 if (meta.bounds().defined()) {
00047                     std::cout << "  bounds=" << meta.bounds() << "\n";
00048                 }
00049             }
00050 
00051             void before_nodes() const {
00052                 std::cout << "before_nodes\n";
00053             }
00054 
00055             void node(const shared_ptr<Osmium::OSM::Node const>& node) const {
00056                 std::cout << "node:\n";
00057                 print_meta(node);
00058                 const Osmium::OSM::Position& position = node->position();
00059                 std::cout << "  lon=" << std::fixed << std::setprecision(7) << position.lon() << "\n";
00060                 std::cout << "  lat=" << std::fixed << std::setprecision(7) << position.lat() << "\n";
00061             }
00062 
00063             void after_nodes() const {
00064                 std::cout << "after_nodes\n";
00065             }
00066 
00067             void before_ways() const {
00068                 std::cout << "before_ways\n";
00069             }
00070 
00071             void way(const shared_ptr<Osmium::OSM::Way const>& way) const {
00072                 std::cout << "way:\n";
00073                 print_meta(way);
00074                 std::cout << "  node_count=" << way->node_count() << "\n";
00075                 std::cout << "  nodes:\n";
00076                 Osmium::OSM::WayNodeList::const_iterator end = way->nodes().end();
00077                 for (Osmium::OSM::WayNodeList::const_iterator it = way->nodes().begin(); it != end; ++it) {
00078                     std::cout << "    ref=" << it->ref() << "\n";
00079                 }
00080             }
00081 
00082             void after_ways() const {
00083                 std::cout << "after_ways\n";
00084             }
00085 
00086             void before_relations() const {
00087                 std::cout << "before_relations\n";
00088             }
00089 
00090             void relation(const shared_ptr<Osmium::OSM::Relation const>& relation) const {
00091                 std::cout << "relation:\n";
00092                 print_meta(relation);
00093                 std::cout << "  members: (count=" << relation->members().size() << ")\n";
00094                 Osmium::OSM::RelationMemberList::const_iterator end = relation->members().end();
00095                 for (Osmium::OSM::RelationMemberList::const_iterator it = relation->members().begin(); it != end; ++it) {
00096                     std::cout << "    type=" << it->type() << " ref=" << it->ref() << " role=|" << it->role() << "|" << "\n";
00097                 }
00098             }
00099 
00100             void after_relations() const {
00101                 std::cout << "after_relations\n";
00102             }
00103 
00104             void final() const {
00105                 std::cout << "final\n";
00106             }
00107 
00108         private:
00109 
00110             bool m_has_multiple_object_versions;
00111 
00112             void print_meta(const shared_ptr<Osmium::OSM::Object const>& object) const {
00113                 std::cout <<   "  id="        << object->id()
00114                           << "\n  version="   << object->version()
00115                           << "\n  uid="       << object->uid()
00116                           << "\n  user=|"     << object->user() << "|"
00117                           << "\n  changeset=" << object->changeset()
00118                           << "\n  timestamp=" << object->timestamp_as_string();
00119                 if (m_has_multiple_object_versions) {
00120                     std::cout << "\n  visible=" << (object->visible() ? "yes" : "no")
00121                               << "\n  endtime=" << object->endtime_as_string();
00122                 }
00123                 std::cout << "\n  tags: (count=" << object->tags().size() << ")\n";
00124                 Osmium::OSM::TagList::const_iterator end = object->tags().end();
00125                 for (Osmium::OSM::TagList::const_iterator it = object->tags().begin(); it != end; ++it) {
00126                     std::cout << "    k=|" << it->key() << "| v=|" << it->value() << "|" << "\n";
00127                 }
00128             }
00129 
00130         }; // class Debug
00131 
00132     } // namespace Handler
00133 
00134 } // namespace Osmium
00135 
00136 #endif // OSMIUM_HANDLER_DEBUG_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines