Skip to content

Commit

Permalink
consistently use namespaces everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
lonvia committed Aug 3, 2024
1 parent 068e5e3 commit a323da4
Show file tree
Hide file tree
Showing 19 changed files with 148 additions and 100 deletions.
16 changes: 8 additions & 8 deletions lib/area.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace {

using MpManager = osmium::area::MultipolygonManager<osmium::area::Assembler>;

class AreaManagerSecondPassHandlerBase : public BaseHandler
class AreaManagerSecondPassHandlerBase : public pyosmium::BaseHandler
{
public:
AreaManagerSecondPassHandlerBase(MpManager *mp_manager)
Expand Down Expand Up @@ -69,7 +69,7 @@ class AreaManagerSecondPassHandler : public AreaManagerSecondPassHandlerBase

private:
py::args m_args;
HandlerChain m_handlers;
pyosmium::HandlerChain m_handlers;

};

Expand All @@ -86,14 +86,14 @@ class AreaManagerBufferHandler : public AreaManagerSecondPassHandlerBase
};


class AreaManager : public BaseHandler
class AreaManager : public pyosmium::BaseHandler
{
public:
AreaManager()
: m_mp_manager(m_assembler_config)
{}

BaseHandler *first_pass_handler() { return this; }
pyosmium::BaseHandler *first_pass_handler() { return this; }

// first-pass-handler
bool relation(osmium::Relation const *r) override
Expand All @@ -119,16 +119,16 @@ class AreaManager : public BaseHandler
osmium::area::MultipolygonManager<osmium::area::Assembler> m_mp_manager;
};

}
} // namespace

PYBIND11_MODULE(_area, m)
{
py::class_<AreaManagerSecondPassHandler, BaseHandler>(m,
py::class_<AreaManagerSecondPassHandler, pyosmium::BaseHandler>(m,
"AreaManagerSecondPassHandler");
py::class_<AreaManagerBufferHandler, BaseHandler>(m,
py::class_<AreaManagerBufferHandler, pyosmium::BaseHandler>(m,
"AreaManagerBufferHandler");

py::class_<AreaManager, BaseHandler>(m, "AreaManager",
py::class_<AreaManager, pyosmium::BaseHandler>(m, "AreaManager",
"Object manager class that manages building area objects from "
"ways and relations.")
.def(py::init<>())
Expand Down
4 changes: 4 additions & 0 deletions lib/base_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

#include <osmium/handler.hpp>

namespace pyosmium {

class BaseHandler : public osmium::handler::Handler
{
public:
Expand All @@ -36,4 +38,6 @@ class BaseHandler : public osmium::handler::Handler
virtual void flush() {}
};

} // namespace

#endif // PYOSMIUM_BASE_HANDLER_HPP
4 changes: 2 additions & 2 deletions lib/cast.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*
* This file is part of pyosmium. (https://osmcode.org/pyosmium/)
*
* Copyright (C) 2023 Sarah Hoffmann <[email protected]> and others.
* Copyright (C) 2024 Sarah Hoffmann <[email protected]> and others.
* For a full list of authors see the git log.
*/
#ifndef PYOSMIUM_CAST_H
Expand Down Expand Up @@ -122,6 +122,6 @@ T const &cast_list(pybind11::object const &o) {
return o.attr("_list").cast<T const &>();
}

}
} // namespace

#endif // PYOSMIUM_CAST_H
2 changes: 1 addition & 1 deletion lib/empty_tag_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class EmptyTagFilter : public pyosmium::BaseFilter

};

}
} // namespace

namespace pyosmium {

Expand Down
23 changes: 13 additions & 10 deletions lib/file_iterator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class OsmFileIterator
{
auto *node = static_cast<osmium::Node *>(entity);
if (!m_pre_handler.handle_node(*node)) {
m_current = m_type_module.attr("Node")(COSMNode{node});
m_current = m_type_module.attr("Node")(pyosmium::COSMNode{node});
m_current_type = osmium::item_type::node;
return m_current;
}
Expand All @@ -73,7 +73,7 @@ class OsmFileIterator
{
auto *way = static_cast<osmium::Way *>(entity);
if (!m_pre_handler.handle_way(*way)) {
m_current = m_type_module.attr("Way")(COSMWay{way});
m_current = m_type_module.attr("Way")(pyosmium::COSMWay{way});
m_current_type = osmium::item_type::way;
return m_current;
}
Expand All @@ -83,7 +83,7 @@ class OsmFileIterator
{
auto *rel = static_cast<osmium::Relation *>(entity);
if (!m_pre_handler.handle_relation(*rel)) {
m_current = m_type_module.attr("Relation")(COSMRelation{rel});
m_current = m_type_module.attr("Relation")(pyosmium::COSMRelation{rel});
m_current_type = osmium::item_type::relation;
return m_current;
}
Expand All @@ -93,7 +93,7 @@ class OsmFileIterator
{
auto *cs = static_cast<osmium::Changeset *>(entity);
if (!m_pre_handler.handle_changeset(*cs)) {
m_current = m_type_module.attr("Changeset")(COSMChangeset{cs});
m_current = m_type_module.attr("Changeset")(pyosmium::COSMChangeset{cs});
m_current_type = osmium::item_type::changeset;
return m_current;
}
Expand All @@ -112,16 +112,16 @@ class OsmFileIterator
{
switch (m_current_type) {
case osmium::item_type::node:
m_current.attr("_pyosmium_data").template cast<COSMNode *>()->invalidate();
m_current.attr("_pyosmium_data").template cast<pyosmium::COSMNode *>()->invalidate();
break;
case osmium::item_type::way:
m_current.attr("_pyosmium_data").template cast<COSMWay *>()->invalidate();
m_current.attr("_pyosmium_data").template cast<pyosmium::COSMWay *>()->invalidate();
break;
case osmium::item_type::relation:
m_current.attr("_pyosmium_data").template cast<COSMRelation *>()->invalidate();
m_current.attr("_pyosmium_data").template cast<pyosmium::COSMRelation *>()->invalidate();
break;
case osmium::item_type::changeset:
m_current.attr("_pyosmium_data").template cast<COSMChangeset *>()->invalidate();
m_current.attr("_pyosmium_data").template cast<pyosmium::COSMChangeset *>()->invalidate();
break;
}
m_current_type = osmium::item_type::undefined;
Expand All @@ -133,12 +133,14 @@ class OsmFileIterator
osmium::item_type m_current_type = osmium::item_type::undefined;
pybind11::object m_current;

HandlerChain m_pre_handler;
pyosmium::HandlerChain m_pre_handler;

pybind11::object m_type_module = pybind11::module_::import("osmium.osm.types");
};

}
} // namespace

namespace pyosmium {

void init_osm_file_iterator(py::module &m)
{
Expand All @@ -151,3 +153,4 @@ void init_osm_file_iterator(py::module &m)
;
}

} // namespace
2 changes: 1 addition & 1 deletion lib/filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
namespace py = pybind11;

PYBIND11_MODULE(_filter, m) {
py::class_<pyosmium::BaseFilter, BaseHandler>(m, "BaseFilter")
py::class_<pyosmium::BaseFilter, pyosmium::BaseHandler>(m, "BaseFilter")
.def("enable_for", &pyosmium::BaseFilter::enable_for,
py::arg("entities"),
"Set the OSM types this filter should be used for.")
Expand Down
12 changes: 8 additions & 4 deletions lib/geom.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*
* This file is part of pyosmium. (https://osmcode.org/pyosmium/)
*
* Copyright (C) 2023 Sarah Hoffmann <[email protected]> and others.
* Copyright (C) 2024 Sarah Hoffmann <[email protected]> and others.
* For a full list of authors see the git log.
*/
#include <pybind11/pybind11.h>
Expand All @@ -21,6 +21,8 @@
namespace py = pybind11;
namespace og = osmium::geom;

namespace {

struct WKBFactory : osmium::geom::WKBFactory<>
{
public:
Expand All @@ -46,7 +48,7 @@ void make_factory_class(py::module_ &m, char const *name, char const *doc)
if (py::isinstance<osmium::Location>(o)) {
return f.create_point(o.cast<osmium::Location const &>());
}
auto const *node = pyosmium::try_cast<COSMNode>(o);
auto const *node = pyosmium::try_cast<pyosmium::COSMNode>(o);
if (node) {
return f.create_point(*node->get());
}
Expand All @@ -57,7 +59,7 @@ void make_factory_class(py::module_ &m, char const *name, char const *doc)
"Create a point geometry from a :py:class:`osmium.osm.Node`.")
.def("create_linestring",
[](Factory &f, py::object const &o, og::use_nodes un, og::direction dir) {
auto const *way = pyosmium::try_cast<COSMWay>(o);
auto const *way = pyosmium::try_cast<pyosmium::COSMWay>(o);
if (way) {
return f.create_linestring(*way->get(), un, dir);
}
Expand All @@ -69,13 +71,15 @@ void make_factory_class(py::module_ &m, char const *name, char const *doc)
"Create a LineString geometry from a :py:class:`osmium.osm.Way`.")
.def("create_multipolygon",
[](Factory &f, py::object const &o) {
return f.create_multipolygon(*pyosmium::cast<COSMArea>(o).get());
return f.create_multipolygon(*pyosmium::cast<pyosmium::COSMArea>(o).get());
},
py::arg("area"),
"Create a MultiPolygon geometry from a :py:class:`osmium.osm.Area`.")
;
}

} // namespace

PYBIND11_MODULE(geom, m)
{
py::enum_<og::use_nodes>(m, "use_nodes")
Expand Down
4 changes: 4 additions & 0 deletions lib/handler_chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

namespace py = pybind11;

namespace pyosmium {

class HandlerChain : public osmium::handler::Handler
{
public:
Expand Down Expand Up @@ -109,4 +111,6 @@ class HandlerChain : public osmium::handler::Handler
std::vector<pyosmium::PythonHandler> m_python_handlers;
};

} // namespace

#endif //PYOSMIUM_HANDLER_CHAIN_H
4 changes: 2 additions & 2 deletions lib/io.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*
* This file is part of pyosmium. (https://osmcode.org/pyosmium/)
*
* Copyright (C) 2023 Sarah Hoffmann <[email protected]> and others.
* Copyright (C) 2024 Sarah Hoffmann <[email protected]> and others.
* For a full list of authors see the git log.
*/
#include <pybind11/pybind11.h>
Expand All @@ -19,7 +19,7 @@ class FileBuffer : public osmium::io::File
using osmium::io::File::File;
};

}
} // namespace


PYBIND11_MODULE(io, m)
Expand Down
2 changes: 1 addition & 1 deletion lib/key_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class KeyFilter : public pyosmium::BaseFilter
std::vector<std::string> m_keys;
};

}
} // namespace

namespace pyosmium {

Expand Down
12 changes: 8 additions & 4 deletions lib/merge_input_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class MergeInputReader
public:
void apply(py::args args, std::string const &idx, bool simplify)
{
HandlerChain handler{args};
pyosmium::HandlerChain handler{args};
if (idx.empty())
apply_without_location(handler, simplify);
else
Expand Down Expand Up @@ -128,7 +128,7 @@ class MergeInputReader
}

private:
void apply_without_location(HandlerChain& handler, bool simplify)
void apply_without_location(pyosmium::HandlerChain& handler, bool simplify)
{
if (simplify) {
objects.sort(osmium::object_order_type_id_reverse_version());
Expand All @@ -150,7 +150,7 @@ class MergeInputReader
changes.clear();
}

void apply_with_location(HandlerChain& handler, std::string const &idx,
void apply_with_location(pyosmium::HandlerChain& handler, std::string const &idx,
bool simplify)
{
using Index_fab =
Expand Down Expand Up @@ -199,7 +199,9 @@ class MergeInputReader
osmium::ObjectPointerCollection objects;
};

}
} // namespace

namespace pyosmium {

void init_merge_input_reader(py::module &m)
{
Expand Down Expand Up @@ -240,3 +242,5 @@ void init_merge_input_reader(py::module &m)
"safely discarded after the function has been called.")
;
};

} // namespace
11 changes: 9 additions & 2 deletions lib/node_location_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@

#include "base_handler.h"

namespace {

using LocationTable =
osmium::index::map::Map<osmium::unsigned_object_id_type, osmium::Location>;
using NodeLocationHandler =
osmium::handler::NodeLocationsForWays<LocationTable>;


class NodeLocationsForWays : public BaseHandler
class NodeLocationsForWays : public pyosmium::BaseHandler
{
public:
NodeLocationsForWays(LocationTable &idx)
Expand Down Expand Up @@ -50,8 +51,12 @@ class NodeLocationsForWays : public BaseHandler
bool apply_nodes_to_ways = true;
};

} // namespace

namespace py = pybind11;

namespace pyosmium {

void init_node_location_handler(py::module &m)
{
py::class_<NodeLocationsForWays, BaseHandler>(m, "NodeLocationsForWays")
Expand All @@ -65,3 +70,5 @@ void init_node_location_handler(py::module &m)
;

}

} // namespace
Loading

0 comments on commit a323da4

Please sign in to comment.