1 #ifndef OSMIUM_INDEX_MAP_HPP
2 #define OSMIUM_INDEX_MAP_HPP
46 #include <type_traits>
54 std::runtime_error(message) {
58 std::runtime_error(message) {
96 template <
typename TId,
typename TValue>
99 "TId template parameter for class Map must be unsigned integral type");
104 Map& operator=(
Map&&) noexcept = default;
119 virtual ~
Map() noexcept = default;
126 virtual void set(
const TId
id,
const TValue value) = 0;
135 virtual TValue
get(
const TId
id)
const = 0;
154 virtual std::size_t
size()
const = 0;
183 throw std::runtime_error{
"can't dump as list"};
190 throw std::runtime_error{
"can't dump as array"};
197 template <
typename TId,
typename TValue>
229 return m_callbacks.emplace(map_type_name, func).second;
237 std::vector<std::string> result;
240 result.push_back(cb.first);
243 std::sort(result.begin(), result.end());
248 std::unique_ptr<map_type>
create_map(
const std::string& config_string)
const {
251 if (config.empty()) {
257 return std::unique_ptr<map_type>((it->second)(config));
260 throw map_factory_error{std::string{
"Support for map type '"} + config[0] +
"' not compiled into this binary"};
267 template <
typename TId,
typename TValue,
template <
typename,
typename>
class TMap>
269 TMap<TId, TValue>*
operator()(
const std::vector<std::string>& ) {
270 return new TMap<TId, TValue>();
276 template <
typename TId,
typename TValue,
template <
typename,
typename>
class TMap>
283 #define OSMIUM_CONCATENATE_DETAIL_(x, y) x##y
284 #define OSMIUM_CONCATENATE_(x, y) OSMIUM_CONCATENATE_DETAIL_(x, y)
286 #define REGISTER_MAP(id, value, klass, name) \
287 namespace osmium { namespace index { namespace detail { \
288 namespace OSMIUM_CONCATENATE_(register_map_, __COUNTER__) { \
289 const bool registered = osmium::index::register_map<id, value, klass>(#name); \
290 inline bool get_registered() noexcept { \
TValue value_type
Definition: map.hpp:203
bool register_map(const std::string &map_type_name, create_map_func func)
Definition: map.hpp:228
~MapFactory() noexcept=default
MapFactory(MapFactory &&)=delete
static MapFactory< id_type, value_type > & instance()
Definition: map.hpp:223
MapFactory & operator=(MapFactory &&)=delete
MapFactory(const MapFactory &)=delete
std::vector< std::string > map_types() const
Definition: map.hpp:236
std::unique_ptr< map_type > create_map(const std::string &config_string) const
Definition: map.hpp:248
TId id_type
Definition: map.hpp:202
std::map< const std::string, create_map_func > m_callbacks
Definition: map.hpp:209
bool has_map_type(const std::string &map_type_name) const
Definition: map.hpp:232
std::function< map_type *(const std::vector< std::string > &)> create_map_func
Definition: map.hpp:205
MapFactory & operator=(const MapFactory &)=delete
virtual TValue get_noexcept(const TId id) const noexcept=0
TId key_type
The "key" type, usually osmium::unsigned_object_id_type.
Definition: map.hpp:109
virtual std::size_t used_memory() const =0
virtual void dump_as_array(const int)
Definition: map.hpp:189
virtual void sort()
Definition: map.hpp:175
TValue value_type
The "value" type, usually a Location or size_t.
Definition: map.hpp:112
virtual TValue get(const TId id) const =0
virtual void reserve(const std::size_t)
Definition: map.hpp:121
Map(Map &&) noexcept=default
virtual void dump_as_list(const int)
Definition: map.hpp:182
virtual void set(const TId id, const TValue value)=0
Set the field with id to value.
virtual std::size_t size() const =0
#define OSMIUM_EXPORT
Definition: compatibility.hpp:54
bool register_map(const std::string &name)
Definition: map.hpp:277
Namespace for everything in the Osmium library.
Definition: assembler.hpp:53
std::vector< std::string > split_string(const std::string &str, const char sep, bool compact=false)
Definition: string.hpp:50
Definition: location.hpp:555
TMap< TId, TValue > * operator()(const std::vector< std::string > &)
Definition: map.hpp:269
map_factory_error(const std::string &message)
Definition: map.hpp:57
map_factory_error(const char *message)
Definition: map.hpp:53