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

Last change on this file since 10470 was 10423, checked in by tbretz, 14 years ago
Added boolean option to Print to suppress the SERVER name if any.
File size: 2.9 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{ int fTargetState; /// Target state of an event
13 std::vector<int> fAllowedStates; /// List of states in which this event is allowed
14
15 /// http://www.boost.org/doc/libs/1_45_0/libs/bind/bind.html
16 boost::function<int(const EventImp &)> fFunction;
17
18public:
19 /// Constructor. Stores the target state given.
20 EventImp(int target=-1) : fTargetState(target) { }
21 /// Copy constructor
22 EventImp(const EventImp &cmd);
23
24 // Description
25 virtual void SetDescription(const std::string &) { }
26 virtual std::string GetDescription() const { return ""; }
27
28 // Function handling
29 EventImp &AssignFunction(const boost::function<int(const EventImp &)> &func) { fFunction = func; return *this; }
30 bool HasFunc() const { return !fFunction.empty(); }
31 int ExecFunc() const { return HasFunc() ? fFunction(*this) : -1; }
32
33 // Configuration helper
34 EventImp &operator()(const boost::function<int(const EventImp &)> &func) { return AssignFunction(func); }
35 EventImp &operator()(const std::string str) { SetDescription(str); return *this; }
36 EventImp &operator()(const char *str) { SetDescription(str); return *this; }
37
38 // Print contents
39 virtual void Print(std::ostream &out, bool strip=false) const;
40 virtual void Print(bool strip=false) const;
41
42 // Handling of the states
43 void AddAllowedState(int state);
44 void AddAllowedStates(const char *states);
45
46 bool IsStateAllowed(int state) const;
47
48 int GetTargetState() const { return fTargetState; }
49
50 // virtual function to return the data as stored in the derived classes
51 virtual std::string GetName() const { return ""; }
52 virtual std::string GetFormat() const { return ""; }
53
54 virtual const void *GetData() const { return 0; }
55 virtual int GetSize() const { return 0; }
56
57 virtual Time GetTime() const { return Time::None; }
58
59 // Getter for all the data contained (name, format, data and time)
60 short GetShort() const { return *reinterpret_cast<const short*>(GetData()); }
61 unsigned short GetUShort() const { return *reinterpret_cast<const unsigned short*>(GetData()); }
62 int GetInt() const { return *reinterpret_cast<const int*>(GetData()); }
63 unsigned int GetUInt() const { return *reinterpret_cast<const unsigned int*>(GetData()); }
64 float GetFloat() const { return *reinterpret_cast<const float*>(GetData()); }
65 double GetDouble() const { return *reinterpret_cast<const double*>(GetData()); }
66 const char *GetText() const { return reinterpret_cast<const char*>(GetData()); }
67 std::string GetString() const { return std::string(GetText(), GetSize()); }
68 std::vector<char> GetVector() const { return std::vector<char>(GetText(), GetText()+GetSize()); }
69
70};
71
72#endif
Note: See TracBrowser for help on using the repository browser.