1 #ifndef OSMIUM_INDEX_MAP_HPP
2 #define OSMIUM_INDEX_MAP_HPP
43 #include <type_traits>
84 template <
typename TId,
typename TValue>
106 virtual ~Map() =
default;
113 virtual void set(
const TId
id,
const TValue value) = 0;
116 virtual const TValue
get(
const TId id)
const = 0;
124 virtual size_t size()
const = 0;
139 virtual void clear() = 0;
150 std::runtime_error(
"can't dump as list");
157 template <
typename TId,
typename TValue>
180 std::string error_message {
"Support for map type '"};
181 error_message += map_type_name;
182 error_message +=
"' not compiled into this binary.";
183 throw std::runtime_error(error_message);
194 return m_callbacks.emplace(map_type_name, func).second;
198 std::vector<std::string> result;
200 for (
const auto& cb : m_callbacks) {
201 result.push_back(cb.first);
204 std::sort(result.begin(), result.end());
209 std::unique_ptr<map_type>
create_map(
const std::string& config_string)
const {
212 if (config.empty()) {
213 throw std::runtime_error(
"Need non-empty map type name.");
216 auto it = m_callbacks.find(config[0]);
217 if (it != m_callbacks.end()) {
218 return std::unique_ptr<map_type>((it->second)(config));
228 template <
typename TId,
typename TValue,
template<
typename,
typename>
class TMap>
230 TMap<TId, TValue>*
operator()(
const std::vector<std::string>&) {
231 return new TMap<TId, TValue>();
237 template <
typename TId,
typename TValue,
template<
typename,
typename>
class TMap>
244 #define REGISTER_MAP(id, value, klass, name) \
246 const bool registered_index_map_##name = osmium::index::register_map<id, value, klass>(#name); \
253 #endif // OSMIUM_INDEX_MAP_HPP
osmium::index::map::Map< id_type, value_type > map_type
Definition: map.hpp:164
std::map< const std::string, create_map_func > m_callbacks
Definition: map.hpp:169
#define OSMIUM_NORETURN
Definition: compatibility.hpp:44
virtual size_t size() const =0
virtual size_t used_memory() const =0
bool register_map(const std::string &map_type_name, create_map_func func)
Definition: map.hpp:193
TMap< TId, TValue > * operator()(const std::vector< std::string > &)
Definition: map.hpp:230
bool register_map(const std::string &name)
Definition: map.hpp:238
virtual void reserve(const size_t)
Definition: map.hpp:108
Namespace for everything in the Osmium library.
Definition: assembler.hpp:55
std::unique_ptr< map_type > create_map(const std::string &config_string) const
Definition: map.hpp:209
TId key_type
The "key" type, usually osmium::unsigned_object_id_type.
Definition: map.hpp:99
TId id_type
Definition: map.hpp:162
static OSMIUM_NORETURN void error(const std::string &map_type_name)
Definition: map.hpp:179
virtual void dump_as_list(const int)
Definition: map.hpp:149
virtual void sort()
Definition: map.hpp:145
static MapFactory< id_type, value_type > & instance()
Definition: map.hpp:188
Map & operator=(const Map &)=delete
TValue value_type
The "value" type, usually a Location or size_t.
Definition: map.hpp:102
std::vector< std::string > map_types() const
Definition: map.hpp:197
TValue value_type
Definition: map.hpp:163
std::vector< std::string > split_string(const std::string &str, const char sep)
Definition: string.hpp:49
MapFactory & operator=(const MapFactory &)=delete
virtual void set(const TId id, const TValue value)=0
Set the field with id to value.
std::function< map_type *(const std::vector< std::string > &)> create_map_func
Definition: map.hpp:165