Osmium  0.1
include/osmium/handler/coordinates_for_ways.hpp
Go to the documentation of this file.
00001 #ifndef OSMIUM_HANDLER_COORDINATES_FOR_WAYS_HPP
00002 #define OSMIUM_HANDLER_COORDINATES_FOR_WAYS_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 <osmium/handler.hpp>
00026 
00027 namespace Osmium {
00028 
00029     namespace Handler {
00030 
00038         template <class TStoragePosIDs, class TStorageNegIDs>
00039         class CoordinatesForWays : public Base {
00040 
00041         public:
00042 
00043             CoordinatesForWays(TStoragePosIDs& storage_pos,
00044                                TStorageNegIDs& storage_neg)
00045                 : m_storage_pos(storage_pos),
00046                   m_storage_neg(storage_neg) {
00047             }
00048 
00052             void node(const shared_ptr<Osmium::OSM::Node const>& node) {
00053                 int64_t id = node->id();
00054                 if (id >= 0) {
00055                     m_storage_pos.set( id, node->position());
00056                 } else {
00057                     m_storage_neg.set(-id, node->position());
00058                 }
00059             }
00060 
00061             void after_nodes() const {
00062                 if (Osmium::debug()) {
00063                     std::cerr << "Memory used for node coordinates storage (approximate):\n  for positive IDs: "
00064                               << m_storage_pos.used_memory() / (1024 * 1024)
00065                               << " MiB\n  for negative IDs: "
00066                               << m_storage_neg.used_memory() / (1024 * 1024)
00067                               << " MiB\n";
00068                 }
00069             }
00070 
00075             void way(const shared_ptr<Osmium::OSM::Way>& way) {
00076                 for (Osmium::OSM::WayNodeList::iterator it = way->nodes().begin(); it != way->nodes().end(); ++it) {
00077                     const int64_t id = it->ref();
00078                     it->position(id >= 0 ? m_storage_pos[id] : m_storage_neg[-id]);
00079                 }
00080             }
00081 
00082         private:
00083 
00085             TStoragePosIDs& m_storage_pos;
00086 
00088             TStorageNegIDs& m_storage_neg;
00089 
00090         }; // class CoordinatesForWays
00091 
00092     } // namespace Handler
00093 
00094 } // namespace Osmium
00095 
00096 #endif // OSMIUM_HANDLER_COORDINATES_FOR_WAYS_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines