/usr/include/osmium/storage/objectstore.hpp is in libosmium-dev 0.0~20111213-g7f3500a-3build5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 | #ifndef OSMIUM_STORAGE_OBJECTSTORE_HPP
#define OSMIUM_STORAGE_OBJECTSTORE_HPP
/*
Copyright 2011 Jochen Topf <jochen@topf.org> and others (see README).
This file is part of Osmium (https://github.com/joto/osmium).
Osmium is free software: you can redistribute it and/or modify it under the
terms of the GNU Lesser General Public License or (at your option) the GNU
General Public License as published by the Free Software Foundation, either
version 3 of the Licenses, or (at your option) any later version.
Osmium is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU Lesser General Public License and the GNU
General Public License for more details.
You should have received a copy of the Licenses along with Osmium. If not, see
<http://www.gnu.org/licenses/>.
*/
#include <set>
#include <boost/bind.hpp>
#include <osmium/handler.hpp>
namespace Osmium {
namespace Storage {
/**
* Stores Nodes, Ways, and Relations in main memory. Can store multiple
* versions of the same object. Storage is ordered by id and version.
*
* The object store uses the handler interface, so storage is simply by
* calling the node(), way(), and relation() methods like in any other
* handler.
*
* Note that Osmium OSM objects are rather larger, so this store can use
* a lot of memory. In many cases you don't need the whole object but only
* parts of it, so using a more space efficient storage might be possible.
*/
class ObjectStore : public Osmium::Handler::Base {
public:
ObjectStore() : Base(), m_nodes(), m_ways(), m_relations() {
}
/**
* Insert shared_ptr of Node into object store.
*/
void node(const shared_ptr<Osmium::OSM::Node const>& node) {
m_nodes.insert(node);
}
/**
* Insert shared_ptr of Way into object store.
*/
void way(const shared_ptr<Osmium::OSM::Way const>& way) {
m_ways.insert(way);
}
/**
* Insert shared_ptr of Relation into object store.
*/
void relation(const shared_ptr<Osmium::OSM::Relation const>& relation) {
m_relations.insert(relation);
}
/**
* Remove all nodes from object store.
*/
void clear_nodes() {
m_nodes.clear();
}
/**
* Remove all ways from object store.
*/
void clear_ways() {
m_ways.clear();
}
/**
* Remove all relations from object store.
*/
void clear_relations() {
m_relations.clear();
}
/**
* Remove all objects from object store.
*/
void clear() {
clear_nodes();
clear_ways();
clear_relations();
}
/**
* Feed contents of object store to the given handler. Because
* objects are stored ordered by id and version, they will be
* fed to the handler in order.
*
* If clear is set, all nodes/ways/relations are removed from the
* object store after the after_nodes/ways/relations() call to the
* handler.
*
* @tparam THandler Handler class.
* @param handler Pointer to handler.
* @param meta Reference to Osmium::OSM::Meta object which will be given to init() method of handler.
* @param clear Should objects be cleared from the object store? Default is true.
*/
template <class THandler>
void feed_to(THandler* handler, Osmium::OSM::Meta& meta, bool clear=true) {
handler->init(meta);
handler->before_nodes();
std::for_each(m_nodes.begin(), m_nodes.end(), boost::bind(&THandler::node, handler, _1));
handler->after_nodes();
if (clear) {
clear_nodes();
}
handler->before_ways();
std::for_each(m_ways.begin(), m_ways.end(), boost::bind(&THandler::way, handler, _1));
handler->after_ways();
if (clear) {
clear_ways();
}
handler->before_relations();
std::for_each(m_relations.begin(), m_relations.end(), boost::bind(&THandler::relation, handler, _1));
handler->after_relations();
if (clear) {
clear_relations();
}
handler->final();
}
private:
typedef std::set<shared_ptr<Osmium::OSM::Node const> > nodeset;
typedef std::set<shared_ptr<Osmium::OSM::Way const> > wayset;
typedef std::set<shared_ptr<Osmium::OSM::Relation const> > relationset;
nodeset m_nodes;
wayset m_ways;
relationset m_relations;
public:
/**
* Handler that inserts objects from the store in the right
* position in the stream of objects it gets and forwards all
* objects to another handler.
*
* Do not change the object store while this handler is active.
*/
template <class THandler>
class ApplyHandler : public Osmium::Handler::Forward<THandler> {
public:
ApplyHandler(ObjectStore& os, THandler* handler, Osmium::OSM::Meta& meta) :
Osmium::Handler::Forward<THandler>(handler),
m_object_store(os),
m_handler(handler),
m_meta(meta),
m_nodes_iter(os.m_nodes.begin()),
m_nodes_end(os.m_nodes.end()),
m_ways_iter(os.m_ways.begin()),
m_ways_end(os.m_ways.end()),
m_relations_iter(os.m_relations.begin()),
m_relations_end(os.m_relations.end()) {
}
void init(const Osmium::OSM::Meta&) {
m_handler->init(m_meta);
}
void node(const shared_ptr<Osmium::OSM::Node>& node) {
while (m_nodes_iter != m_nodes_end && **m_nodes_iter < *node) {
m_handler->node(*m_nodes_iter++);
}
m_handler->node(node);
}
void after_nodes() {
while (m_nodes_iter != m_nodes_end) {
m_handler->node(*m_nodes_iter++);
}
m_handler->after_nodes();
m_object_store.clear_nodes();
}
void way(const shared_ptr<Osmium::OSM::Way>& way) {
while (m_ways_iter != m_ways_end && **m_ways_iter < *way) {
m_handler->way(*m_ways_iter++);
}
m_handler->way(way);
}
void after_ways() {
while (m_ways_iter != m_ways_end) {
m_handler->way(*m_ways_iter++);
}
m_handler->after_ways();
m_object_store.clear_ways();
}
void relation(const shared_ptr<Osmium::OSM::Relation>& relation) {
while (m_relations_iter != m_relations_end && **m_relations_iter < *relation) {
m_handler->relation(*m_relations_iter++);
}
m_handler->relation(relation);
}
void after_relations() {
while (m_relations_iter != m_relations_end) {
m_handler->relation(*m_relations_iter++);
}
m_handler->after_relations();
m_object_store.clear_relations();
}
private:
ObjectStore& m_object_store;
THandler* m_handler;
Osmium::OSM::Meta& m_meta;
ObjectStore::nodeset::iterator m_nodes_iter;
ObjectStore::nodeset::iterator m_nodes_end;
ObjectStore::wayset::iterator m_ways_iter;
ObjectStore::wayset::iterator m_ways_end;
ObjectStore::relationset::iterator m_relations_iter;
ObjectStore::relationset::iterator m_relations_end;
}; // class ApplyHandler
}; // class ObjectStore
} // namespace Storage
} // namespace Osmium
#endif // OSMIUM_STORAGE_OBJECTSTORE_HPP
|