Add ExtractionRelation class
This commit is contained in:
parent
a5776288f6
commit
a253111cbe
60
include/extractor/extraction_relation.hpp
Normal file
60
include/extractor/extraction_relation.hpp
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
#ifndef EXTRACTION_RELATION_HPP
|
||||||
|
#define EXTRACTION_RELATION_HPP
|
||||||
|
|
||||||
|
#include "util/osm_id_typed.hpp"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
|
namespace osrm
|
||||||
|
{
|
||||||
|
namespace extractor
|
||||||
|
{
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
|
||||||
|
inline const char * checkedString(const char * str)
|
||||||
|
{
|
||||||
|
return str ? str : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace detail
|
||||||
|
|
||||||
|
struct ExtractionRelation
|
||||||
|
{
|
||||||
|
using AttributesMap = std::unordered_map<std::string, std::string>;
|
||||||
|
|
||||||
|
ExtractionRelation()
|
||||||
|
: is_restriction(false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void clear()
|
||||||
|
{
|
||||||
|
is_restriction = false;
|
||||||
|
values.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsRestriction() const
|
||||||
|
{
|
||||||
|
return is_restriction;
|
||||||
|
}
|
||||||
|
|
||||||
|
AttributesMap & GetMember(util::OsmIDTyped id)
|
||||||
|
{
|
||||||
|
return values[id.Hash()];
|
||||||
|
}
|
||||||
|
|
||||||
|
// AttributesMap & operator[] (util::OsmIDTyped id)
|
||||||
|
// {
|
||||||
|
// return values[id];
|
||||||
|
// }
|
||||||
|
|
||||||
|
bool is_restriction;
|
||||||
|
std::unordered_map<util::OsmIDTyped::HashType, AttributesMap> values;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace extractor
|
||||||
|
} // namespace osrm
|
||||||
|
|
||||||
|
#endif // EXTRACTION_RELATION_HPP
|
40
include/util/osm_id_typed.hpp
Normal file
40
include/util/osm_id_typed.hpp
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
#ifndef OSM_ID_TYPED_HPP
|
||||||
|
#define OSM_ID_TYPED_HPP
|
||||||
|
|
||||||
|
#include "typedefs.hpp"
|
||||||
|
|
||||||
|
namespace osrm
|
||||||
|
{
|
||||||
|
namespace util
|
||||||
|
{
|
||||||
|
|
||||||
|
class OsmIDTyped
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
using HashType = std::uint64_t;
|
||||||
|
|
||||||
|
OsmIDTyped(std::uint64_t id_, std::uint8_t type_)
|
||||||
|
: id(id_)
|
||||||
|
, type(type_)
|
||||||
|
{
|
||||||
|
// check if type value not above type size bound
|
||||||
|
BOOST_ASSERT(id_ < (std::uint64_t(1) << 56));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator == (const OsmIDTyped &other) { return (id == other.id && type == other.type); }
|
||||||
|
bool operator != (const OsmIDTyped &other) { return (id != other.id || type != other.type); }
|
||||||
|
|
||||||
|
inline HashType Hash() const { return (std::uint64_t(id) | std::uint64_t(type) << 56); }
|
||||||
|
|
||||||
|
std::uint64_t GetID() const { return id; }
|
||||||
|
std::uint8_t GetType() const { return type; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::uint64_t id : 56;
|
||||||
|
std::uint8_t type;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace util
|
||||||
|
} // namespace osrm
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user