FIFE  6e1afdbeda11afe9ac53e6023a4be96ef88f1dc6
event.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2017 by the FIFE team *
3  * http://www.fifengine.net *
4  * This file is part of FIFE. *
5  * *
6  * FIFE is free software; you can redistribute it and/or *
7  * modify it under the terms of the GNU Lesser General Public *
8  * License as published by the Free Software Foundation; either *
9  * version 2.1 of the License, or (at your option) any later version. *
10  * *
11  * This library is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14  * Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with this library; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20  ***************************************************************************/
21 /***************************************************************************
22  * Note! FIFE event channel borrows heavily from ideas of Guichan library *
23  * version 0.6 *
24  ***************************************************************************/
25 
26 
27 #ifndef FIFE_EVENTCHANNEL_EVENT_H
28 #define FIFE_EVENTCHANNEL_EVENT_H
29 
30 // Standard C++ library includes
31 //
32 #include <string>
33 #include <sstream>
34 
35 // 3rd party library includes
36 //
37 #include <SDL.h>
38 
39 // FIFE includes
40 // These includes are split up in two parts, separated by one empty line
41 // First block: files included from the FIFE root src directory
42 // Second block: files included from the same folder
43 //
45 
46 namespace FIFE {
49  class Event {
50  public:
53  Event():
54  m_isConsumed(false),
55  m_eventSource(NULL),
56  m_timestamp(SDL_GetTicks()) {}
57 
60  virtual ~Event() {}
61 
64  virtual void consume() { m_isConsumed = true; }
65 
69  virtual bool isConsumed() const { return m_isConsumed; }
70 
73  virtual IEventSource* getSource() const { return m_eventSource; }
74 
77  virtual void setSource(IEventSource* source) { m_eventSource = source; }
78 
81  virtual int32_t getTimeStamp() const { return m_timestamp; }
82 
85  virtual void setTimeStamp(int32_t timestamp ) { m_timestamp = timestamp; }
86 
89  virtual const std::string& getName() const {
90  const static std::string eventName("Event");
91  return eventName;
92  }
93 
96  virtual std::string getAttrStr() const {
97  std::stringstream ss;
98  ss << "consumed = " << m_isConsumed << ", ";
99  ss << "src = " << m_eventSource << ", ";
100  ss << "timestamp = " << m_timestamp;
101  return ss.str();
102  }
103 
106  virtual std::string getDebugString() const {
107  std::stringstream ss;
108  ss << getName() << std::endl;
109  ss << getAttrStr() << std::endl;
110  return ss.str();
111  }
112 
113  private:
119  int32_t m_timestamp;
120  };
121 
122 } //FIFE
123 
124 #endif
int32_t m_timestamp
Timestamp of the event.
Definition: event.h:119
virtual ~Event()
Destructor.
Definition: event.h:60
Event()
Constructor.
Definition: event.h:53
IEventSource * m_eventSource
The source of the event.
Definition: event.h:117
bool m_isConsumed
Indicates if the event is consumed.
Definition: event.h:115
virtual void setSource(IEventSource *source)
Sets the source of the event.
Definition: event.h:77
Base class for all events.
Definition: event.h:49
virtual std::string getDebugString() const
Gets the debugstring of the event.
Definition: event.h:106
virtual IEventSource * getSource() const
Gets the source of the event.
Definition: event.h:73
virtual int32_t getTimeStamp() const
Gets the timestamp of the event.
Definition: event.h:81
virtual const std::string & getName() const
Gets the name of the event.
Definition: event.h:89
virtual void setTimeStamp(int32_t timestamp)
Sets the timestamp of the event.
Definition: event.h:85
Representation of event source (a thing sending events)
Definition: ieventsource.h:42
virtual void consume()
Marks the event as consumed.
Definition: event.h:64
virtual std::string getAttrStr() const
Gets attribute string of the event.
Definition: event.h:96
virtual bool isConsumed() const
Checks if the event is consumed.
Definition: event.h:69