1 #ifndef OSMIUM_INDEX_MAP_HPP 2 #define OSMIUM_INDEX_MAP_HPP 43 #include <type_traits> 84 template <
typename TId,
typename TValue>
87 "TId template parameter for class Map must be unsigned integral type");
107 virtual ~Map() noexcept = default;
114 virtual void set(
const TId id,
const TValue value) = 0;
117 virtual const TValue
get(
const TId id)
const = 0;
125 virtual size_t size()
const = 0;
140 virtual void clear() = 0;
154 throw std::runtime_error(
"can't dump as list");
161 throw std::runtime_error(
"can't dump as array");
168 template <
typename TId,
typename TValue>
191 std::string error_message {
"Support for map type '"};
192 error_message += map_type_name;
193 error_message +=
"' not compiled into this binary.";
194 throw std::runtime_error(error_message);
205 return m_callbacks.emplace(map_type_name, func).second;
209 return m_callbacks.count(map_type_name);
213 std::vector<std::string> result;
215 for (
const auto& cb : m_callbacks) {
216 result.push_back(cb.first);
219 std::sort(result.begin(), result.end());
224 std::unique_ptr<map_type>
create_map(
const std::string& config_string)
const {
227 if (config.empty()) {
228 throw std::runtime_error(
"Need non-empty map type name.");
231 auto it = m_callbacks.find(config[0]);
232 if (it != m_callbacks.end()) {
233 return std::unique_ptr<map_type>((it->second)(config));
243 template <
typename TId,
typename TValue,
template<
typename,
typename>
class TMap>
245 TMap<TId, TValue>*
operator()(
const std::vector<std::string>&) {
246 return new TMap<TId, TValue>();
252 template <
typename TId,
typename TValue,
template<
typename,
typename>
class TMap>
259 #define OSMIUM_CONCATENATE_DETAIL_(x, y) x##y 260 #define OSMIUM_CONCATENATE_(x, y) OSMIUM_CONCATENATE_DETAIL_(x, y) 262 #define REGISTER_MAP(id, value, klass, name) \ 263 namespace osmium { namespace index { namespace detail { \ 264 const bool OSMIUM_CONCATENATE_(registered_, name) = osmium::index::register_map<id, value, klass>(#name); \ 265 inline bool OSMIUM_CONCATENATE_(get_registered_, name)() noexcept { \ 266 return OSMIUM_CONCATENATE_(registered_, name); \ 274 #endif // OSMIUM_INDEX_MAP_HPP std::map< const std::string, create_map_func > m_callbacks
Definition: map.hpp:180
#define OSMIUM_NORETURN
Definition: compatibility.hpp:41
virtual size_t used_memory() const =0
TId id_type
Definition: map.hpp:173
TValue value_type
Definition: map.hpp:174
TId key_type
The "key" type, usually osmium::unsigned_object_id_type.
Definition: map.hpp:100
bool register_map(const std::string &map_type_name, create_map_func func)
Definition: map.hpp:204
virtual size_t size() const =0
TMap< TId, TValue > * operator()(const std::vector< std::string > &)
Definition: map.hpp:245
bool register_map(const std::string &name)
Definition: map.hpp:253
TValue value_type
The "value" type, usually a Location or size_t.
Definition: map.hpp:103
virtual void reserve(const size_t)
Definition: map.hpp:109
Namespace for everything in the Osmium library.
Definition: assembler.hpp:66
virtual void dump_as_array(const int)
Definition: map.hpp:160
std::unique_ptr< map_type > create_map(const std::string &config_string) const
Definition: map.hpp:224
static OSMIUM_NORETURN void error(const std::string &map_type_name)
Definition: map.hpp:190
virtual void dump_as_list(const int)
Definition: map.hpp:153
virtual void sort()
Definition: map.hpp:146
virtual ~Map() noexcept=default
bool has_map_type(const std::string &map_type_name) const
Definition: map.hpp:208
static MapFactory< id_type, value_type > & instance()
Definition: map.hpp:199
std::function< map_type *(const std::vector< std::string > &)> create_map_func
Definition: map.hpp:176
Map & operator=(const Map &)=delete
std::vector< std::string > map_types() const
Definition: map.hpp:212
std::vector< std::string > split_string(const std::string &str, const char sep, bool compact=false)
Definition: string.hpp:50