Sleeping Wombat GUI  0.100
swGUI
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
EventQueue.h
Go to the documentation of this file.
1 #pragma once
2 
10 #include "InputDeviceEvent.h"
11 
12 #include <vector>
13 
14 
15 
16 namespace sw {
17 namespace input
18 {
19 
20 
25 template< typename EventType >
27 {
28 private:
29 
30  std::vector< EventType > m_events;
32 
33 public:
34 
35  explicit EventQueue ();
36  ~EventQueue () = default;
37 
39  inline void AddEvent ( const EventType& event );
40 
42  inline void ClearReadEvents ();
43  inline bool NoMoreEvents () const { return (uint32)m_events.size() <= m_readPointer; }
44  inline uint32 EventsLeft () const { return (uint32)m_events.size() - m_readPointer; }
45 
48  inline const EventType& FrontEvent () const { assert( !NoMoreEvents() ); return m_events[ m_readPointer ]; }
49 
51  inline const EventType& PopEvent ();
52 
55  const std::vector< EventType >& GetEvents () const { return m_events; }
56 
58  uint32 GetReadPointer () const { return m_readPointer; }
59 };
60 
61 
62 //====================================================================================//
63 // Implementation
64 //====================================================================================//
65 
66 template< typename EventType >
68  : m_readPointer( 0 )
69 {}
70 
71 
72 // ================================ //
73 //
74 template< typename EventType >
75 inline void EventQueue< EventType >::AddEvent ( const EventType& event )
76 {
77  m_events.push_back( event );
78 }
79 
80 // ================================ //
81 //
82 template< typename EventType >
84 {
85  m_events.erase( m_events.begin(), m_events.begin() + m_readPointer );
86  m_readPointer = 0;
87 }
88 
89 // ================================ //
90 //
91 template< typename EventType >
93 {
94  assert( !NoMoreEvents() );
95  return m_events[ m_readPointer++ ];
96 }
97 
98 } // input
99 } // sw
100 
101 
void ClearReadEvents()
Removes all events after m_readPointer.
Definition: EventQueue.h:83
void AddEvent(const EventType &event)
Adds event on the end of queue.
Definition: EventQueue.h:75
const EventType & PopEvent()
Gets next event and moves m_readPointer.
Definition: EventQueue.h:92
Definition: DirectInputModule.cpp:11
uint32 EventsLeft() const
Definition: EventQueue.h:44
uint32 EventType
Event type identifier.
Definition: RegisteredEvent.h:19
Plik zawiera definicje podstawowych typów zmiennych.
uint32_t uint32
Definition: TypesDefinitions.h:31
const std::vector< EventType > & GetEvents() const
Gets whole array of events. This array consists of events to.
Definition: EventQueue.h:55
uint32 m_readPointer
Definition: EventQueue.h:31
EventQueue()
Definition: EventQueue.h:67
const EventType & FrontEvent() const
Reads next event without moving read pointer. Always check if there're any events in queue left...
Definition: EventQueue.h:48
Abstraction of event queue.
Definition: EventQueue.h:26
bool NoMoreEvents() const
Definition: EventQueue.h:43
uint32 GetReadPointer() const
Gets index of next event to read.
Definition: EventQueue.h:58
std::vector< EventType > m_events
Definition: EventQueue.h:30