summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndré Nusser <andre.nusser@googlemail.com>2020-02-18 11:53:40 +0100
committerAndré Nusser <andre.nusser@googlemail.com>2020-02-23 13:46:28 +0100
commit7623de94e9566392ad69b2ca31dcf6453f816571 (patch)
tree9868e5b0f20cab29c11362e5a611662d30d77cfc /src
parent3184ffc5792bf24523a896961e197d8203cbca56 (diff)
Add two get(event_id) function to EventsDS.
Still needs testing and review.
Diffstat (limited to 'src')
-rw-r--r--src/events_ds.cc14
-rw-r--r--src/events_ds.h30
2 files changed, 44 insertions, 0 deletions
diff --git a/src/events_ds.cc b/src/events_ds.cc
index 097ddc1..3e1573f 100644
--- a/src/events_ds.cc
+++ b/src/events_ds.cc
@@ -56,6 +56,20 @@ void EventsDS::remove(EventID event_id)
id_to_info.remove(event_id);
}
+Event* EventsDS::get(EventID event_id)
+{
+ auto const& info = id_to_info.get(event_id);
+
+ // add new event types here
+ switch (info.type)
+ {
+ case Event::Type::SampleEvent:
+ return &getSample<SampleEvent>(info);
+ default:
+ assert(false);
+ }
+}
+
std::size_t EventsDS::numberOfEvents(channel_t ch) const
{
auto& channel_data = channel_data_array[ch];
diff --git a/src/events_ds.h b/src/events_ds.h
index dd13ec0..2e8fa43 100644
--- a/src/events_ds.h
+++ b/src/events_ds.h
@@ -67,6 +67,15 @@ public:
//! Removes the event with id being event_id.
void remove(EventID event_id);
+ //! Returns a reference to the element with id begin event_id. Note that to
+ //! get an event with this function, one has to know its type!
+ template <typename T>
+ T& get(EventID event_id);
+
+ //! Returns a pointer to the event with id begin event_id. As Event has a
+ //! member variable that carries the type, it can be then casted appropriately.
+ Event* get(EventID event_id);
+
//! Returns the number of all events of a certain channel.
std::size_t numberOfEvents(channel_t ch) const;
@@ -129,6 +138,9 @@ private:
InstrumentID current_groups_instrument_id;
void removeGroup(EventGroupID group_id, InstrumentID instrument_id = InstrumentID());
+
+ template <typename T>
+ T& getSample(EventInfo const& info);
};
template <typename T, typename... Args>
@@ -157,6 +169,12 @@ T& EventsDS::emplace(channel_t ch, Args&&... args)
}
template <typename T>
+T& EventsDS::get(EventID event_id)
+{
+ return getSample<T>(id_to_info.get(event_id));
+}
+
+template <typename T>
ContainerRange<std::vector<T>> EventsDS::iterateOver(channel_t ch)
{
// add new event types here
@@ -168,3 +186,15 @@ ContainerRange<std::vector<T>> EventsDS::iterateOver(channel_t ch)
return ContainerRange<std::vector<T>>(sample_events.begin(), sample_events.end());
}
}
+
+template <typename T>
+T& EventsDS::getSample(EventInfo const& info)
+{
+ // add new event types here
+ static_assert(std::is_same<T, SampleEvent>::value);
+
+ if (std::is_same<T, SampleEvent>::value)
+ {
+ return channel_data_array[info.ch].sample_events[info.channel_event_index];
+ }
+}