1 #ifndef OSMIUM_INDEX_MAP_HPP 2 #define OSMIUM_INDEX_MAP_HPP 43 #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");
102 Map& operator=(
const Map&) =
delete;
107 Map& operator=(
Map&&) =
default;
119 virtual ~
Map() noexcept = default;
121 virtual
void reserve(const
size_t) {
126 virtual void set(
const TId id,
const TValue value) = 0;
135 virtual TValue
get(
const TId id)
const = 0;
146 virtual TValue get_noexcept(
const TId
id)
const noexcept = 0;
154 virtual size_t size()
const = 0;
163 virtual size_t used_memory()
const = 0;
169 virtual void clear() = 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>
227 return m_callbacks.emplace(map_type_name, func).second;
231 return m_callbacks.count(map_type_name) != 0;
235 std::vector<std::string> result;
237 for (
const auto& cb : m_callbacks) {
238 result.push_back(cb.first);
241 std::sort(result.begin(), result.end());
246 std::unique_ptr<map_type>
create_map(
const std::string& config_string)
const {
249 if (config.empty()) {
253 auto it = m_callbacks.find(config[0]);
254 if (it != m_callbacks.end()) {
255 return std::unique_ptr<map_type>((it->second)(config));
258 throw map_factory_error{std::string{
"Support for map type '"} + config[0] +
"' not compiled into this binary"};
265 template <
typename TId,
typename TValue,
template<
typename,
typename>
class TMap>
267 TMap<TId, TValue>*
operator()(
const std::vector<std::string>&) {
268 return new TMap<TId, TValue>();
274 template <
typename TId,
typename TValue,
template<
typename,
typename>
class TMap>
281 #define OSMIUM_CONCATENATE_DETAIL_(x, y) x##y 282 #define OSMIUM_CONCATENATE_(x, y) OSMIUM_CONCATENATE_DETAIL_(x, y) 284 #define REGISTER_MAP(id, value, klass, name) \ 285 namespace osmium { namespace index { namespace detail { \ 286 const bool OSMIUM_CONCATENATE_(registered_, name) = osmium::index::register_map<id, value, klass>(#name); \ 287 inline bool OSMIUM_CONCATENATE_(get_registered_, name)() noexcept { \ 288 return OSMIUM_CONCATENATE_(registered_, name); \ 296 #endif // OSMIUM_INDEX_MAP_HPP std::map< const std::string, create_map_func > m_callbacks
Definition: map.hpp:209
std::unique_ptr< map_type > create_map(const std::string &config_string) const
Definition: map.hpp:246
TId id_type
Definition: map.hpp:202
TValue value_type
Definition: map.hpp:203
Definition: reader_iterator.hpp:39
TId key_type
The "key" type, usually osmium::unsigned_object_id_type.
Definition: map.hpp:112
bool register_map(const std::string &map_type_name, create_map_func func)
Definition: map.hpp:226
TMap< TId, TValue > * operator()(const std::vector< std::string > &)
Definition: map.hpp:267
bool register_map(const std::string &name)
Definition: map.hpp:275
TValue value_type
The "value" type, usually a Location or size_t.
Definition: map.hpp:115
bool has_map_type(const std::string &map_type_name) const
Definition: map.hpp:230
Namespace for everything in the Osmium library.
Definition: assembler.hpp:63
virtual void dump_as_array(const int)
Definition: map.hpp:189
std::vector< std::string > map_types() const
Definition: map.hpp:234
virtual void dump_as_list(const int)
Definition: map.hpp:182
virtual void sort()
Definition: map.hpp:175
static MapFactory< id_type, value_type > & instance()
Definition: map.hpp:221
std::function< map_type *(const std::vector< std::string > &)> create_map_func
Definition: map.hpp:205
map_factory_error(const std::string &message)
Definition: map.hpp:57
map_factory_error(const char *message)
Definition: map.hpp:53
std::vector< std::string > split_string(const std::string &str, const char sep, bool compact=false)
Definition: string.hpp:50