Skip to content

Commit 8b404d8

Browse files
committed
make sure that the handler bitfield is always initialised
Add a new virtual function apply_start() to BaseHandler which must forcably be called before running the handler through osmium::apply (the C++ function). Fixes #38.
1 parent 8c48cde commit 8b404d8

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

lib/generic_handler.hpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ class BaseHandler : public osmium::handler::Handler {
2525
};
2626

2727
public:
28+
virtual void apply_start() {};
2829
// handler functions
29-
virtual void node(const osmium::Node&)= 0;
30+
virtual void node(const osmium::Node&) = 0;
3031
virtual void way(const osmium::Way&) = 0;
3132
virtual void relation(const osmium::Relation&) = 0;
3233
virtual void changeset(const osmium::Changeset&) = 0;
@@ -163,14 +164,7 @@ struct SimpleHandlerWrap: BaseHandler, wrapper<BaseHandler> {
163164
apply_object(osmium::io::File(cbuf, len, cfmt), locations, idx);
164165
}
165166

166-
private:
167-
void apply_object(osmium::io::File file, bool locations, const std::string &idx)
168-
{
169-
osmium::osm_entity_bits::type entities = osmium::osm_entity_bits::nothing;
170-
BaseHandler::pre_handler handler = locations?
171-
BaseHandler::location_handler
172-
:BaseHandler::no_handler;
173-
167+
void apply_start() override {
174168
m_callbacks = osmium::osm_entity_bits::nothing;
175169
if (hasfunc("node"))
176170
m_callbacks |= osmium::osm_entity_bits::node;
@@ -182,6 +176,18 @@ struct SimpleHandlerWrap: BaseHandler, wrapper<BaseHandler> {
182176
m_callbacks |= osmium::osm_entity_bits::area;
183177
if (hasfunc("changeset"))
184178
m_callbacks |= osmium::osm_entity_bits::changeset;
179+
}
180+
181+
182+
private:
183+
void apply_object(osmium::io::File file, bool locations, const std::string &idx)
184+
{
185+
osmium::osm_entity_bits::type entities = osmium::osm_entity_bits::nothing;
186+
BaseHandler::pre_handler handler = locations?
187+
BaseHandler::location_handler
188+
:BaseHandler::no_handler;
189+
190+
apply_start();
185191

186192
if (m_callbacks & osmium::osm_entity_bits::area)
187193
{
@@ -202,6 +208,7 @@ struct SimpleHandlerWrap: BaseHandler, wrapper<BaseHandler> {
202208
apply(file, entities, handler, idx);
203209
}
204210

211+
205212
bool hasfunc(char const *name) {
206213
reference_existing_object::apply<SimpleHandlerWrap*>::type converter;
207214
PyObject* obj = converter( this );

lib/merged_input.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ namespace pyosmium {
5252
class MergeInputReader {
5353
public:
5454
void apply(BaseHandler& handler, bool simplify = true) {
55+
handler.apply_start();
5556
if (simplify) {
5657
objects.sort(osmium::object_order_type_id_reverse_version());
5758
osmium::item_type prev_type = osmium::item_type::undefined;

lib/osmium.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,16 @@ void apply_reader_simple(osmium::io::Reader &rd, T &h) {
2828
osmium::apply(rd, h);
2929
}
3030

31+
void apply_reader_simple(osmium::io::Reader &rd, BaseHandler &h) {
32+
h.apply_start();
33+
osmium::apply(rd, h);
34+
}
3135

3236
template <typename T>
3337
void apply_reader_simple_with_location(osmium::io::Reader &rd,
3438
osmium::handler::NodeLocationsForWays<T> &l,
3539
BaseHandler &h) {
40+
h.apply_start();
3641
osmium::apply(rd, l, h);
3742
}
3843

0 commit comments

Comments
 (0)