ReUseX
0.0.5
3D Point Cloud Processing for Building Reuse
Toggle main menu visibility
Loading...
Searching...
No Matches
Registry.hpp
Go to the documentation of this file.
1
// SPDX-FileCopyrightText: 2025 Povl Filip Sonne-Frederiksen
2
//
3
// SPDX-License-Identifier: GPL-3.0-or-later
4
5
#pragma once
6
#include "reusex/core/logging.hpp"
7
8
#include <boost/property_map/property_map.hpp>
9
10
#include <map>
11
#include <memory>
12
#include <string>
13
#include <typeindex>
14
#include <utility>
15
16
namespace
reusex::geometry
{
17
class
Registry
{
18
private
:
19
// Keyed by name and type_index
20
std::map<std::pair<std::string, std::type_index>, std::shared_ptr<void>>
21
registry;
22
23
public
:
24
virtual
~Registry
() =
default
;
25
template
<
typename
Key,
typename
T>
26
std::pair<boost::associative_property_map<std::map<Key, T>>,
bool
>
27
add_property_map
(
const
std::string &name) {
28
auto
key = std::make_pair(name, std::type_index(
typeid
(T)));
29
auto
it = registry.find(key);
30
if
(it != registry.end()) {
31
// Already exists: recover the map and wrap it in a property_map
32
auto
map_ptr = std::static_pointer_cast<std::map<Key, T>>(it->second);
33
return
{boost::associative_property_map<std::map<Key, T>>(*map_ptr),
34
false
};
35
}
else
{
36
// Create new map and store in registry
37
auto
m = std::make_shared<std::map<Key, T>>();
38
registry[key] = m;
39
return
{boost::associative_property_map<std::map<Key, T>>(*m),
true
};
40
}
41
}
42
43
template
<
typename
Key,
typename
T>
44
const
boost::associative_property_map<std::map<Key, T>>
45
property_map
(
const
std::string &name)
const
{
46
auto
key = std::make_pair(name, std::type_index(
typeid
(T)));
47
auto
it = registry.find(key);
48
if
(it == registry.end()) {
49
reusex::error
(
"Property map not found: {}"
, name);
50
throw
std::runtime_error(
"Property map not found"
);
51
}
52
auto
map_ptr = std::static_pointer_cast<std::map<Key, T>>(it->second);
53
return
boost::associative_property_map<std::map<Key, T>>(*map_ptr);
54
}
55
};
56
}
// namespace reusex::geometry
reusex::geometry::Registry
Definition
Registry.hpp:17
reusex::geometry::Registry::add_property_map
std::pair< boost::associative_property_map< std::map< Key, T > >, bool > add_property_map(const std::string &name)
Definition
Registry.hpp:27
reusex::geometry::Registry::~Registry
virtual ~Registry()=default
reusex::geometry::Registry::property_map
const boost::associative_property_map< std::map< Key, T > > property_map(const std::string &name) const
Definition
Registry.hpp:45
reusex::geometry
Definition
processing_observer.hpp:19
reusex::error
void error(fmt::format_string< Args... > format, Args &&...args)
Definition
logging.hpp:100
libs
reusex
include
geometry
Registry.hpp
Generated by
1.17.0