| 1 | #ifndef FACT_Event
|
|---|
| 2 | #define FACT_Event
|
|---|
| 3 |
|
|---|
| 4 | #include "EventImp.h"
|
|---|
| 5 |
|
|---|
| 6 | class Event : public EventImp
|
|---|
| 7 | {
|
|---|
| 8 | private:
|
|---|
| 9 | std::string fName; /// A name associated with the event
|
|---|
| 10 | std::string fFormat; /// A string describing the format of the data
|
|---|
| 11 | std::string fDescription; /// A human readable description of the event
|
|---|
| 12 |
|
|---|
| 13 | std::vector<char> fData; /// Data associated with this event
|
|---|
| 14 |
|
|---|
| 15 | Time fTime; /// Time stamp
|
|---|
| 16 | int fQoS; /// Quality of service
|
|---|
| 17 | bool fEmpty; /// Empty is true if received event was a NULL pointer
|
|---|
| 18 |
|
|---|
| 19 | public:
|
|---|
| 20 | Event() : fQoS(0), fEmpty(true) { }
|
|---|
| 21 | /// Constructs an event as a combination of an EventImp and a DimCommand
|
|---|
| 22 | Event(const std::string &name, const std::string &fmt="");
|
|---|
| 23 | /// Copy constructor
|
|---|
| 24 | Event(const EventImp &imp);
|
|---|
| 25 | Event(const EventImp &imp, const char *ptr, size_t siz);
|
|---|
| 26 |
|
|---|
| 27 | void SetDescription(const std::string &str) { fDescription=str; }
|
|---|
| 28 | std::string GetDescription() const { return fDescription; }
|
|---|
| 29 |
|
|---|
| 30 | /// Return the stored name of the event
|
|---|
| 31 | std::string GetName() const { return fName; }
|
|---|
| 32 | /// Return the stored format of the data
|
|---|
| 33 | std::string GetFormat() const { return fFormat; }
|
|---|
| 34 |
|
|---|
| 35 | /// Return a pointer to the data region
|
|---|
| 36 | const void *GetData() const { return &*fData.begin(); }
|
|---|
| 37 | /// Return the size of the data
|
|---|
| 38 | size_t GetSize() const { return fData.size(); }
|
|---|
| 39 |
|
|---|
| 40 | /// Return reference to a time stamp
|
|---|
| 41 | Time GetTime() const { return fTime; }
|
|---|
| 42 | /// Return Quality of Service
|
|---|
| 43 | int GetQoS() const { return fQoS; }
|
|---|
| 44 | /// Return if event is not just zero size but empty
|
|---|
| 45 | bool IsEmpty() const { return fEmpty; }
|
|---|
| 46 |
|
|---|
| 47 | void SetTime() { fTime = Time(); }
|
|---|
| 48 | void SetData(const std::vector<char> &data) { fData = data; }
|
|---|
| 49 | void SetData(const void *ptr, size_t siz) {
|
|---|
| 50 | const char *c = reinterpret_cast<const char*>(ptr);
|
|---|
| 51 | fData = std::vector<char>(c, c+siz); }
|
|---|
| 52 |
|
|---|
| 53 | void SetInt(int i) { SetData(&i, sizeof(i)); }
|
|---|
| 54 | void SetFloat(float f) { SetData(&f, sizeof(f)); }
|
|---|
| 55 | void SetDouble(float d) { SetData(&d, sizeof(d)); }
|
|---|
| 56 | void SetShort(short s) { SetData(&s, sizeof(s)); }
|
|---|
| 57 | void SetText(const char *txt) { SetData(txt, strlen(txt)+1); }
|
|---|
| 58 | void SetString(const std::string &str) { SetData(str.c_str(), str.length()+1); }
|
|---|
| 59 | };
|
|---|
| 60 |
|
|---|
| 61 | #endif
|
|---|