52using namespace EVENTSLIB;
58constexpr static int invalidID(0);
59static std::string defaultGroupName(
"Default");
64: m_iEventIdCounter(invalidID)
65, m_iGroupIdCounter(invalidID)
66, m_bDefaultGroupNotCreated(true)
67, m_DefaultGroupId(invalidID)
70 m_pSharedMemManager = std::make_unique<EVENTSINTERNAL::EventSharedMemManager>(
this);
78 auto eventInt = findEventINT(eventId);
79 if(eventInt != m_EventsListBySample.end())
81 return Event(eventInt->second);
88std::multimap<int, EVENTSINTERNAL::EventINT>::const_iterator EventManager::findEventINT(idNum eventId)
const
90 int sample = m_MapIdToSample.at(eventId);
91 auto eventsRange = m_EventsListBySample.equal_range(sample);
92 for(
auto e = eventsRange.first; e != eventsRange.second; ++e)
94 if( e->second.getId() == eventId)
99 return m_EventsListBySample.end();
104std::unique_ptr<std::vector<Event> >
107 auto pEventsList(allocateOutputContainer<Event>(eventIds.size()));
108 for (
const auto&
id: eventIds)
111 if(event.id != invalidID)
113 pEventsList->push_back(event);
123 auto pEventsList(allocateOutputContainer<Event>(
getNumEvents()));
124 for(
auto& e: m_EventsListBySample)
126 pEventsList->emplace_back(
Event(e.second));
135 size_t numEventsInSample = m_EventsListBySample.count(sample);
136 auto pEventsList(allocateOutputContainer<Event>(numEventsInSample));
138 auto eventsRange = m_EventsListBySample.equal_range(sample);
139 for(
auto e = eventsRange.first; e != eventsRange.second; e++)
141 pEventsList->emplace_back(
Event(e->second));
148std::unique_ptr<std::vector<Event> >
151 int memoryHint = ((sampleEnd-sampleStart)/1000)+2;
152 auto pEventsList(allocateOutputContainer<Event>(memoryHint));
154 auto eventStart = m_EventsListBySample.lower_bound(sampleStart);
155 auto eventEnd = m_EventsListBySample.upper_bound(sampleEnd);
157 for(
auto e = eventStart; e != eventEnd; e++)
159 pEventsList->emplace_back(
Event(e->second));
166std::unique_ptr<std::vector<Event> >
169 int memoryHint = ((sampleEnd-sampleStart)/1000)+2;
170 auto pEventsList(allocateOutputContainer<Event>(memoryHint));
172 auto eventStart = m_EventsListBySample.lower_bound(sampleStart);
173 auto eventEnd = m_EventsListBySample.upper_bound(sampleEnd);
175 for(
auto e = eventStart; e != eventEnd; e++)
177 if(e->second.getGroupId() == groupId)
179 pEventsList->emplace_back(
Event(e->second));
187std::unique_ptr<std::vector<Event> >
190 int memoryHint = (sampleEnd-sampleStart)/200;
191 auto pEventsList(allocateOutputContainer<Event>(memoryHint));
193 auto eventStart = m_EventsListBySample.lower_bound(sampleStart);
194 auto eventEnd = m_EventsListBySample.upper_bound(sampleEnd);
196 for(
auto e = eventStart; e != eventEnd; e++)
198 for(
auto& groupId: groupIdsList)
200 if(e->second.getGroupId() == groupId)
202 pEventsList->emplace_back(
Event(e->second));
211std::unique_ptr<std::vector<Event> >
214 auto pEventsList(allocateOutputContainer<Event>());
216 for(
const auto& e: m_EventsListBySample)
218 if(e.second.getGroupId() == groupId)
220 pEventsList->emplace_back(
Event(e.second));
230 auto pEventsList(allocateOutputContainer<Event>());
232 for(
const auto& e: m_EventsListBySample)
234 for (
const auto groupId : groupIdsList)
236 if(e.second.getGroupId() == groupId)
238 pEventsList->emplace_back(
Event(e.second));
249idNum EventManager::generateNewEventId()
251 return ++m_iEventIdCounter;
256idNum EventManager::generateNewGroupId()
258 return ++m_iGroupIdCounter;
265 return m_EventsListBySample.size();
273 insertEvent(newEvent);
276 if(m_pSharedMemManager->isInit())
278 qDebug() <<
"Sending event to SM: Sample: " << sample;
279 m_pSharedMemManager->addEvent(newEvent.
getSample());
282 return Event(newEvent);
289 createDefaultGroupIfNeeded();
290 return addEvent(sample, m_DefaultGroupId);
298 auto event = findEventINT(eventId);
299 if(event != m_EventsListBySample.end())
304 insertEvent(newEvent);
314 bool eventFound(
false);
315 eventFound = eraseEvent(eventId);
319 if(eventFound && m_pSharedMemManager->isInit())
321 m_pSharedMemManager->deleteEvent(m_MapIdToSample.at(eventId));
329bool EventManager::eraseEvent(idNum eventId)
331 auto event = findEventINT(eventId);
332 if(event != m_EventsListBySample.end())
334 m_EventsListBySample.erase(event);
335 m_MapIdToSample.erase(eventId);
345 bool status(eventIds.size());
346 for(
const auto&
id: eventIds)
357 bool status(eventIds->size());
358 for(
auto& e: *eventIds){
368 std::vector<idNum> idList;
369 for(
auto& e: m_EventsListBySample)
371 if(e.second.getGroupId() == groupId)
373 idList.emplace_back(e.second.getId());
383 m_EventsListBySample.emplace(std::make_pair(e.
getSample(),e));
391 return (
int)(m_GroupsList.size());
398 auto groupFound = m_GroupsList.find(groupId);
399 if(groupFound != m_GroupsList.end())
412 size_t numGroups(m_GroupsList.size());
413 auto pGroupsList(allocateOutputContainer<EventGroup>(numGroups));
414 for(
const auto& g: m_GroupsList)
416 pGroupsList->emplace_back(
EventGroup(g.second));
423std::unique_ptr<std::vector<EventGroup> >
426 auto pGroupList(allocateOutputContainer<EventGroup>(groupIds.size()));
427 for(
const auto&
id: groupIds)
430 if (group.id != invalidID)
432 pGroupList->push_back(group);
443 m_GroupsList.emplace(newGroup.
getId(), newGroup);
452 m_GroupsList.emplace(newGroup.
getId(), newGroup);
464 auto groupToDeleteIter = m_GroupsList.find(groupId);
465 if(groupToDeleteIter != m_GroupsList.end())
467 m_GroupsList.erase(groupToDeleteIter);
469 if(!m_bDefaultGroupNotCreated && (groupId == m_DefaultGroupId))
471 m_bDefaultGroupNotCreated =
true;
472 m_DefaultGroupId = invalidID;
483 bool out(groupIds.size());
484 for(
auto g: groupIds)
495 auto group = m_GroupsList.find(groupId);
496 if(group != m_GroupsList.end())
498 group->second.setName(newName);
506 auto group = m_GroupsList.find(groupId);
507 if( group != m_GroupsList.end())
509 group->second.setColor(color);
520 for(
const auto& ev: *eventsAll)
522 for(
auto g: groupIds)
540 for(
const auto& e: *eventsToDuplicate)
553 if(m_MapIdToSample.count(eventId))
555 sample = m_MapIdToSample.at(eventId);
556 auto eventsRange = m_EventsListBySample.equal_range(sample);
557 std::multimap<int, EVENTSINTERNAL::EventINT>::iterator e = eventsRange.first;
558 for(; e != eventsRange.second; ++e)
560 if( e->second.getId() == eventId)
576 for( idNum
id: eventIds)
597 m_pSharedMemManager->init(mode);
606 m_pSharedMemManager->stop();
615 return m_pSharedMemManager->isInit();
620void EventManager::createDefaultGroupIfNeeded()
622 if(m_bDefaultGroupNotCreated)
625 m_bDefaultGroupNotCreated =
false;
626 m_DefaultGroupId = defaultGroup.id;
EventManager declaration.
void setSample(int iSample)
void setGroupId(idNum iGroup)
EventGroup class is designed as a data holder for a group. It is designed towards ease of use for a c...
the class stores the concept of an event group internally in the Event library.
std::unique_ptr< std::vector< Event > > getEventsInGroups(const std::vector< idNum > &groupIdsList) const
bool deleteGroup(const idNum groupId)
EventGroup getGroup(idNum groupId) const
EventGroup mergeGroups(const std::vector< idNum > &groupIds, const std::string &newName)
bool moveEvent(idNum eventId, int newSample)
bool addEventToGroup(const idNum eventId, const idNum groupId)
bool deleteEventsInGroup(idNum groupId)
EventGroup duplicateGroup(const idNum groupId, const std::string &newName)
EventGroup addGroup(const std::string &sGroupName)
bool deleteEvent(idNum eventId) noexcept
void renameGroup(const idNum groupId, const std::string &newName)
std::unique_ptr< std::vector< EventGroup > > getAllGroups() const
Event addEvent(int sample)
std::unique_ptr< std::vector< Event > > getEvents(const std::vector< idNum > eventIds) const
size_t getNumEvents() const
std::unique_ptr< std::vector< Event > > getAllEvents() const
bool deleteGroups(const std::vector< idNum > &groupIds)
void setGroupColor(const idNum groupId, const RgbColor &color)
bool deleteEvents(const std::vector< idNum > &eventIds)
bool isSharedMemoryInit()
Event getEvent(idNum eventId) const
bool addEventsToGroup(const std::vector< idNum > &eventIds, const idNum groupId)
std::unique_ptr< std::vector< EventGroup > > getGroups(const std::vector< idNum > &groupIds) const
std::unique_ptr< std::vector< Event > > getEventsBetween(int sampleStart, int sampleEnd) const
std::unique_ptr< std::vector< Event > > getEventsInSample(int sample) const
std::unique_ptr< std::vector< Event > > getEventsInGroup(const idNum groupId) const