EchoMap 2026-07-25 6d3977c
An experimental cross-platform digital signal processing application for sound-source localisation.
Loading...
Searching...
No Matches
Project.hpp
1//
2// Created by owd on 25/06/2026.
3//
4
5#ifndef ECHOMAP_PROJECT_HPP
6#define ECHOMAP_PROJECT_HPP
7
8#include <implot3d.h>
9
10#include <flat_map>
11#include <map>
12#include <memory>
13#include <ranges>
14#include <string_view>
15
17#include "Object.hpp"
18
19namespace echomap
20{
21
22class Signal;
23class Sensor;
24
25class Project : public Object<Project>
26{
27 std::flat_map<id_type, std::shared_ptr<Signal>> signals;
28 std::flat_map<id_type, std::unique_ptr<Sensor>> sensors;
29
30public:
36 explicit Project(std::string_view project_name = {});
37
38 // ReSharper disable once CppHidingFunction - We will never want destruct a Project through an Object pointer.
39 virtual ~Project();
40
48
56
69 void add_association(
70 const Signal& signal,
71 const Sensor& sensor
72 );
73
87 void add_association(
88 id_type signal_id,
89 id_type sensor_id
90 );
91
97 [[nodiscard]] auto observe_signals() const noexcept
98 {
99 return signals | std::views::values |
100 std::views::transform([](const std::shared_ptr<Signal>& container) -> const Signal& {
101 /*
102 * N.B. for this functor and all similar ones: this is an assertion, not an exception. If the Project
103 * possesses a container for something, but that container is empty, it's definitely violated an
104 * invariant. Failing on a name-based lookup would be exceptional, but this assertion failing
105 * indicates a bug.
106 *
107 * We intentionally produce references (as opposed to raw pointers) to indicate the non-optionality
108 * of these containers.
109 */
110 assert(container);
111 return *container;
112 });
113 }
114
120 [[nodiscard]] auto share_signals() const noexcept
121 {
122 return signals | std::views::values;
123 }
124
130 [[nodiscard]] size_t get_sensors_count() const noexcept;
131
137 [[nodiscard]] auto observe_sensors() const noexcept
138 {
139 return sensors | std::views::values |
140 std::views::transform([](const std::unique_ptr<Sensor>& container) -> const Sensor& {
141 assert(container);
142 return *container;
143 });
144 }
145
151 [[nodiscard]] auto observe_associations() const
152 {
153 return requested_channel_mapping | std::views::transform([this](const auto& association) {
154 return resolve_pair(association.first, association.second);
155 }) |
156 std::views::filter([](const auto& optional) {
157 return optional.has_value();
158 }) |
159 std::views::transform([](const auto& optional) {
160 return *optional;
161 });
162 }
163
164 [[nodiscard]] static ImPlot3DPoint get_sensor_point(
165 int idx,
166 const void* project_instance
167 ) noexcept;
168
177 [[nodiscard]] Sensor& get_mutable_sensor(id_type sensor_id);
178
179private:
195 [[nodiscard]] std::optional<std::pair<
196 const Signal&,
197 const Sensor&>>
199 id_type signal_id,
200 id_type sensor_id
201 ) const;
202
216};
217
218template <> constexpr std::string_view Object<Project>::class_name = "Project";
219
220} // namespace echomap
221
222#endif // ECHOMAP_PROJECT_HPP
EchoMap bidirectional unordered mapping container specification and implementation.
Object specification.
Maintains a bidirectional mapping between a key and value, allowing fast lookup on both objects.
static constexpr std::string_view class_name
Display name for objects of the type determined by the templated class.
Definition Object.hpp:235
auto observe_signals() const noexcept
Provides a transformed view for stored Signal objects in the Project.
Definition Project.hpp:97
Project(std::string_view project_name={})
Creates a new named Project.
Definition Project.cpp:15
const Sensor * add_sensor(std::unique_ptr< Sensor > &&sensor)
Transfers ownership of a Sensor into the Project.
Definition Project.cpp:35
auto share_signals() const noexcept
Provides a view of Signal objects detained in shared-ownership containers.
Definition Project.hpp:120
auto observe_associations() const
Provides a transformed view for defined channel mappings.
Definition Project.hpp:151
const Signal * add_signal(std::shared_ptr< Signal > &&signal)
Transfers ownership of a Signal into the Project.
Definition Project.cpp:24
std::optional< std::pair< const Signal &, const Sensor & > > resolve_pair(id_type signal_id, id_type sensor_id) const
Convenience function to simultaneously resolve observing references to a Signal and a Sensor from the...
Definition Project.cpp:112
BidirectionalUnorderedMapping< id_type, id_type > requested_channel_mapping
Mapping between Signal objects and Sensor objects (identified by their numerical IDs).
Definition Project.hpp:215
auto observe_sensors() const noexcept
Provides a transformed view for stored Sensor objects in the Project.
Definition Project.hpp:137
size_t get_sensors_count() const noexcept
Checks if any Sensor objects are owned by the Project.
Definition Project.cpp:82
void add_association(const Signal &signal, const Sensor &sensor)
Creates a new association between a Signal and Sensor.
Definition Project.cpp:46
Sensor & get_mutable_sensor(id_type sensor_id)
Retrieve a mutable reference to the Sensor with the given ID.
Definition Project.cpp:98
A single channel of discretely sampled audio data.
Definition Signal.hpp:40
The main EchoMap outermost namespace for all non-exported symbols.