source: trunk/FACT++/src/EventImp.h@ 10218

Last change on this file since 10218 was 10183, checked in by tbretz, 11 years ago
New import.
File size: 2.2 KB
Line 
1#ifndef FACT_EventImp
2#define FACT_EventImp
3
4#include <string>
5#include <vector>
6
7#include <boost/function.hpp>
8
9#include "Time.h"
10
11class EventImp
12{
13 int fTargetState; /// Target state of an event
14 std::vector<int> fAllowedStates; /// List of states in which this event is allowed
15
16 /// http://www.boost.org/doc/libs/1_45_0/libs/bind/bind.html
17 boost::function<int(const EventImp &)> fFunction;
18
19public:
20 /// Constructor. Stores the target state given.
21 EventImp(int target=-1) : fTargetState(target) { }
22 /// Copy constructor
23 EventImp(const EventImp &cmd);
24
25 // Function handling
26 void AssignFunction(boost::function<int(const EventImp &)> func) { fFunction = func; }
27 bool HasFunc() const { return !fFunction.empty(); }
28 int ExecFunc() const { return HasFunc() ? fFunction(*this) : -1; }
29
30 // Print contents
31 virtual void Print(std::ostream &out) const;
32 virtual void Print() const;
33
34 // Handling of the states
35 void AddAllowedState(int state);
36 void AddAllowedStates(const char *states);
37
38 bool IsStateAllowed(int state) const;
39
40 int GetTargetState() const { return fTargetState; }
41
42 // virtual function to return the data as stored in the derived classes
43 virtual std::string GetName() const { return ""; }
44 virtual std::string GetFormat() const { return ""; }
45
46 virtual const void *GetData() const { return 0; }
47 virtual int GetSize() const { return 0; }
48
49 virtual Time GetTime() const { return Time::None; }
50
51 // Getter for all the data contained (name, format, data and time)
52 short GetShort() const { return *reinterpret_cast<const short*>(GetData()); }
53 unsigned short GetUShort() const { return *reinterpret_cast<const unsigned short*>(GetData()); }
54 int GetInt() const { return *reinterpret_cast<const int*>(GetData()); }
55 unsigned int GetUInt() const { return *reinterpret_cast<const unsigned int*>(GetData()); }
56 float GetFloat() const { return *reinterpret_cast<const float*>(GetData()); }
57 double GetDouble() const { return *reinterpret_cast<const double*>(GetData()); }
58 const char *GetText() const { return reinterpret_cast<const char*>(GetData()); }
59
60};
61
62#endif
Note: See TracBrowser for help on using the repository browser.