00001
00002 #ifndef EVENT_H
00003 #define EVENT_H
00004
00005
00006 #include "IS3DCommon.H"
00007 #include "G3DOperators.H"
00008
00009 namespace IS3D {
00010
00011
00012 class Event;
00013 typedef ReferenceCountedPointer<class Event> EventRef;
00014
00017 EventRef createCopyOfEvent(EventRef e);
00018
00022 class Event : public ReferenceCountedObject
00023 {
00024 public:
00025
00026 enum EventType {
00027 EVENTTYPE_STANDARD = 0,
00028 EVENTTYPE_1D = 1,
00029 EVENTTYPE_2D = 2,
00030 EVENTTYPE_3D = 3,
00031 EVENTTYPE_COORDINATEFRAME = 4,
00032 EVENTTYPE_MSG = 5
00033 };
00034
00035 Event(const std::string &name) {
00036 _name = name;
00037 _type = EVENTTYPE_STANDARD;
00038 }
00039
00040 Event(const std::string &name, const double data) {
00041 _name = name;
00042 _data1D = data;
00043 _type = EVENTTYPE_1D;
00044 }
00045
00046 Event(const std::string &name, const Vector2 &data) {
00047 _name = name;
00048 _data2D = data;
00049 _type = EVENTTYPE_2D;
00050 }
00051
00052 Event(const std::string &name, const Vector3 &data) {
00053 _name = name;
00054 _data3D = data;
00055 _type = EVENTTYPE_3D;
00056 }
00057
00058 Event(const std::string &name, const CoordinateFrame &data) {
00059 _name = name;
00060 _dataCF = data;
00061 _type = EVENTTYPE_COORDINATEFRAME;
00062 }
00063
00064 Event(const std::string &name, const std::string &data) {
00065 _name = name;
00066 _dataMsg = data;
00067 _type = EVENTTYPE_MSG;
00068 }
00069
00070 virtual ~Event() {}
00071
00072
00073 std::string getName() const { return _name; }
00074 EventType getType() const { return _type; }
00075
00076 double get1DData();
00077 Vector2 get2DData();
00078 Vector3 get3DData();
00079 CoordinateFrame getCoordinateFrameData();
00080 std::string getMsgData();
00081
00082 std::string toString();
00083
00084 void rename(const std::string &newname) { _name = newname; }
00085
00086 void serialize(BinaryOutput &b) const;
00087 void deserialize(BinaryInput &b);
00088
00089 protected:
00090 std::string _name;
00091 EventType _type;
00092 double _data1D;
00093 Vector2 _data2D;
00094 Vector3 _data3D;
00095 CoordinateFrame _dataCF;
00096 std::string _dataMsg;
00097 };
00098
00099
00100
00101
00102
00103 class EventCallbackFunctor
00104 {
00105 public:
00106 EventCallbackFunctor() {}
00107 virtual ~EventCallbackFunctor() {}
00108 virtual void exec(EventRef event) = 0;
00109 };
00110
00111 template <class T>
00112 class EventCallbackSpecificFunctor : public EventCallbackFunctor
00113 {
00114 public:
00115 typedef void (T::*MethodType)(EventRef event);
00116
00117 EventCallbackSpecificFunctor(T *obj, MethodType meth) {
00118 _obj = obj;
00119 _method = meth;
00120 }
00121
00122 virtual ~EventCallbackSpecificFunctor() {}
00123
00124 void exec(EventRef event) {
00125 (_obj->*_method)(event);
00126 }
00127
00128 protected:
00129 T *_obj;
00130 MethodType _method;
00131 };
00132
00133
00134
00135 }
00136
00137 #endif
00138