diff options
author | André Nusser <andre.nusser@googlemail.com> | 2020-02-18 18:02:29 +0100 |
---|---|---|
committer | André Nusser <andre.nusser@googlemail.com> | 2020-02-23 13:46:28 +0100 |
commit | 63e5ab8fdbfac2553c79a4c3dc03039875d581c8 (patch) | |
tree | b6053510e8da96ff4dee42771cff47dbdb0db45f | |
parent | 2261c525f34f6df8ded520c2fa6278c9799d6997 (diff) |
Scratch the pointer returning get and instead add getType.
-rw-r--r-- | src/events_ds.cc | 13 | ||||
-rw-r--r-- | src/events_ds.h | 6 | ||||
-rw-r--r-- | test/eventsdstest.cc | 6 |
3 files changed, 7 insertions, 18 deletions
diff --git a/src/events_ds.cc b/src/events_ds.cc index 3e1573f..ee21f93 100644 --- a/src/events_ds.cc +++ b/src/events_ds.cc @@ -56,18 +56,9 @@ void EventsDS::remove(EventID event_id) id_to_info.remove(event_id); } -Event* EventsDS::get(EventID event_id) +Event::Type EventsDS::getType(EventID event_id) const { - 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); - } + return id_to_info.get(event_id).type; } std::size_t EventsDS::numberOfEvents(channel_t ch) const diff --git a/src/events_ds.h b/src/events_ds.h index 2e8fa43..0a93fe9 100644 --- a/src/events_ds.h +++ b/src/events_ds.h @@ -72,9 +72,9 @@ public: 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); + //! In case we don't know the type of an event, we can use this function to + //! retrieve it and then use get<Type>(...) to get the event. + Event::Type getType(EventID event_id) const; //! Returns the number of all events of a certain channel. std::size_t numberOfEvents(channel_t ch) const; diff --git a/test/eventsdstest.cc b/test/eventsdstest.cc index b9c2f0a..a293610 100644 --- a/test/eventsdstest.cc +++ b/test/eventsdstest.cc @@ -77,12 +77,10 @@ public: } DGUNIT_ASSERT(group_concat == "abcd"); - // get + // get and getType for (auto const& sample_event: events_ds.iterateOver<SampleEvent>(13)) { DGUNIT_ASSERT(events_ds.get<SampleEvent>(sample_event.id).channel == 13); - Event* event_ptr = events_ds.get(sample_event.id); - DGUNIT_ASSERT(event_ptr->type == Event::Type::SampleEvent); - DGUNIT_ASSERT(static_cast<SampleEvent*>(event_ptr)->channel == 13); + DGUNIT_ASSERT(events_ds.getType(sample_event.id) == Event::Type::SampleEvent); } // remove |