osrm-backend/include/extractor/extraction_relation.hpp

82 lines
1.9 KiB
C++
Raw Normal View History

2017-08-24 09:03:42 -04:00
#ifndef EXTRACTION_RELATION_HPP
#define EXTRACTION_RELATION_HPP
#include <osmium/osm/relation.hpp>
#include <boost/assert.hpp>
2017-08-24 09:03:42 -04:00
#include <string>
#include <unordered_map>
#include <vector>
2017-08-24 09:03:42 -04:00
namespace osrm
{
namespace extractor
{
struct ExtractionRelation
{
using AttributesMap = std::unordered_map<std::string, std::string>;
using OsmIDTyped = std::pair<osmium::object_id_type, osmium::item_type>;
struct OsmIDTypedHash
{
std::size_t operator()(const OsmIDTyped &id) const
{
return id.first ^ (static_cast<std::uint64_t>(id.second) << 56);
}
};
2017-08-24 09:03:42 -04:00
2017-09-01 09:55:00 -04:00
ExtractionRelation() : is_restriction(false) {}
2017-08-24 09:03:42 -04:00
void clear()
{
is_restriction = false;
values.clear();
}
2017-09-01 09:55:00 -04:00
bool IsRestriction() const { return is_restriction; }
2017-08-24 09:03:42 -04:00
AttributesMap &GetMember(const osmium::RelationMember &member)
{
return values[OsmIDTyped(member.ref(), member.type())];
}
2017-08-24 09:03:42 -04:00
bool is_restriction;
std::unordered_map<OsmIDTyped, AttributesMap, OsmIDTypedHash> values;
2017-08-24 09:03:42 -04:00
};
// It contains data of all parsed relations for each node/way element
class ExtractionRelationContainer
{
2017-09-01 09:55:00 -04:00
public:
using AttributesMap = ExtractionRelation::AttributesMap;
using OsmIDTyped = ExtractionRelation::OsmIDTyped;
using RelationList = std::vector<AttributesMap>;
2017-09-01 09:55:00 -04:00
void AddRelation(const ExtractionRelation &rel)
{
BOOST_ASSERT(!rel.is_restriction);
for (auto it : rel.values)
data[it.first].push_back(it.second);
}
const RelationList &Get(const OsmIDTyped &id) const
{
const auto it = data.find(id);
if (it != data.end())
return it->second;
static RelationList empty;
return empty;
}
2017-09-01 09:55:00 -04:00
private:
std::unordered_map<OsmIDTyped, RelationList, ExtractionRelation::OsmIDTypedHash> data;
};
2017-08-24 09:03:42 -04:00
} // namespace extractor
} // namespace osrm
#endif // EXTRACTION_RELATION_HPP