MNE-CPP  0.1.9
A Framework for Electrophysiology
eventmanager.h
Go to the documentation of this file.
1 //=============================================================================================================
36 #ifndef EVENTMANAGER_EVENTS_H
37 #define EVENTMANAGER_EVENTS_H
38 
39 //=============================================================================================================
40 // INCLUDES
41 //=============================================================================================================
42 
43 #include "events_global.h"
44 #include "event.h"
45 #include "eventgroup.h"
46 #include "eventsharedmemmanager.h"
47 
48 //=============================================================================================================
49 // STD INCLUDES
50 //=============================================================================================================
51 
52 #include <string>
53 #include <map>
54 #include <unordered_map>
55 #include <vector>
56 #include <memory>
57 
58 //=============================================================================================================
59 // NAMESPACE EVENTSLIB
60 //=============================================================================================================
61 
62 namespace EVENTSLIB {
63 
64 //=============================================================================================================
65 // EVENTSINTERNAL FORWARD DECLARATIONS
66 //=============================================================================================================
67 
68 namespace EVENTSINTERNAL {
69  class EventSharedMemManager;
70 }
71 
72 //=============================================================================================================
80 {
81 public:
82  //=========================================================================================================
86  EventManager();
87 
88  //=========================================================================================================
93  size_t getNumEvents() const;
94 
95  //=========================================================================================================
101  Event getEvent(idNum eventId) const;
102 
103  //=========================================================================================================
109  std::unique_ptr<std::vector<Event> > getEvents(const std::vector<idNum> eventIds) const ;
110 
111  //=========================================================================================================
116  std::unique_ptr<std::vector<Event> > getAllEvents() const ;
117 
118  //=========================================================================================================
124  std::unique_ptr<std::vector<Event> > getEventsInSample(int sample) const ;
125 
126  //=========================================================================================================
133  std::unique_ptr<std::vector<Event> > getEventsBetween(int sampleStart, int sampleEnd) const ;
134 
135  //=========================================================================================================
144  std::unique_ptr<std::vector<Event> > getEventsBetween(int sampleStart, int sampleEnd, idNum groupid) const ;
145 
146  //=========================================================================================================
155  std::unique_ptr<std::vector<Event> > getEventsBetween(int sampleStart, int sampleEnd, const std::vector<idNum>& groupIdsList) const ;
156 
157  //=========================================================================================================
163  std::unique_ptr<std::vector<Event> > getEventsInGroup(const idNum groupId) const;
164 
165  //=========================================================================================================
171  std::unique_ptr<std::vector<Event> > getEventsInGroups(const std::vector<idNum>& groupIdsList) const;
172 
173  //=========================================================================================================
179  Event addEvent(int sample);
180 
181  //=========================================================================================================
188  Event addEvent(int sample, idNum groupId);
189 
190  //=========================================================================================================
197  bool moveEvent(idNum eventId, int newSample);
198 
199  //=========================================================================================================
205  bool deleteEvent(idNum eventId) noexcept;
206 
207  //=========================================================================================================
213  bool deleteEvents(const std::vector<idNum>& eventIds);
214 
215  //=========================================================================================================
221  bool deleteEvents(std::unique_ptr<std::vector<Event> > eventIds);
222 
223  //=========================================================================================================
229  bool deleteEventsInGroup(idNum groupId);
230 
231  //=========================================================================================================
236  int getNumGroups() const;
237 
238  //=========================================================================================================
244  EventGroup getGroup(idNum groupId) const;
245 
246  //=========================================================================================================
251  std::unique_ptr<std::vector<EventGroup> > getAllGroups() const ;
252 
253  //=========================================================================================================
259  std::unique_ptr<std::vector<EventGroup> > getGroups(const std::vector<idNum>& groupIds) const ;
260 
261  //=========================================================================================================
267  EventGroup addGroup(const std::string& sGroupName);
268 
269  //=========================================================================================================
276  EventGroup addGroup(const std::string& sGroupName, const RgbColor& color);
277 
278  //=========================================================================================================
284  bool deleteGroup(const idNum groupId);
285 
286  //=========================================================================================================
292  bool deleteGroups(const std::vector<idNum>& groupIds);
293 
294  //=========================================================================================================
300  void renameGroup(const idNum groupId, const std::string& newName);
301 
302  //=========================================================================================================
308  void setGroupColor(const idNum groupId, const RgbColor& color);
309 
310  //=========================================================================================================
317  EventGroup mergeGroups(const std::vector<idNum>& groupIds, const std::string& newName);
318 
319  //=========================================================================================================
326  EventGroup duplicateGroup(const idNum groupId, const std::string& newName);
327 
328  //=========================================================================================================
335  bool addEventToGroup(const idNum eventId, const idNum groupId);
336 
337  //=========================================================================================================
344  bool addEventsToGroup(const std::vector<idNum>& eventIds, const idNum groupId);
345 
346  //=========================================================================================================
351  void initSharedMemory();
352 
353  //=========================================================================================================
358  void initSharedMemory(SharedMemoryMode mode);
359 
360  //=========================================================================================================
364  void stopSharedMemory();
365 
366  //=========================================================================================================
371  bool isSharedMemoryInit();
372 
373 private:
374  //=========================================================================================================
379  idNum generateNewEventId();
380 
381  //=========================================================================================================
386  idNum generateNewGroupId();
387 
388  //=========================================================================================================
393  void insertEvent(const EVENTSINTERNAL::EventINT& e);
394 
395  //=========================================================================================================
401  bool eraseEvent(idNum eventId);
402 
403  //=========================================================================================================
409  std::multimap<int, EVENTSINTERNAL::EventINT>::const_iterator findEventINT(idNum id) const;
410 
411  //=========================================================================================================
415  void createDefaultGroupIfNeeded();
416 
417  std::multimap<int, EVENTSINTERNAL::EventINT> m_EventsListBySample;
418  std::unordered_map<idNum, int> m_MapIdToSample;
419  std::map<idNum, EVENTSINTERNAL::EventGroupINT> m_GroupsList;
421  std::unique_ptr<EVENTSINTERNAL::EventSharedMemManager> m_pSharedMemManager;
423  idNum m_iEventIdCounter;
424  idNum m_iGroupIdCounter;
425  bool m_bDefaultGroupNotCreated;
426  idNum m_DefaultGroupId;
429 };
430 
431 //=============================================================================================================
435 template<typename T>
436 inline std::unique_ptr<std::vector<T> > allocateOutputContainer() noexcept
437 {
438  return std::make_unique<std::vector<T> >();
439 };
440 
441 //=============================================================================================================
445 template<typename T>
446 inline std::unique_ptr<std::vector<T> > allocateOutputContainer(size_t size) noexcept
447 {
448  auto v = std::make_unique<std::vector<T> >();
449  if(size > 0)
450  {
451  v->reserve(size);
452  }
453 
454  return v;
455 };
456 
457 }//namespace EVENTSLIB
458 #endif // EVENTS_H
eventsharedmemmanager.h
EventSharedMemManager definition.
EVENTSLIB::Event
Definition: event.h:71
eventgroup.h
EventGroup declaration.
event.h
Event declaration.
EVENTS_EXPORT
#define EVENTS_EXPORT
Definition: events_global.h:46
EVENTSLIB::EventGroup
EventGroup class is designed as a data holder for a group. It is designed towards ease of use for a c...
Definition: eventgroup.h:116
EVENTSLIB::allocateOutputContainer
std::unique_ptr< std::vector< T > > allocateOutputContainer() noexcept
Definition: eventmanager.h:436
EVENTSLIB::EVENTSINTERNAL::EventSharedMemManager
Definition: eventsharedmemmanager.h:160
EVENTSLIB::EventManager
Definition: eventmanager.h:79
EVENTSLIB::RgbColor
Definition: eventgroup.h:74
events_global.h
event library export/import macros.
EVENTSLIB::EVENTSINTERNAL::EventINT
Definition: event.h:115