00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef _PROPERTY_LISTENER_HH_
00025 #define _PROPERTY_LISTENER_HH_
00026
00027
00028 #include <vos/corelibs/vos/vos.hh>
00029
00030 class Property;
00031 class ExtrapolatedProperty;
00032
00033
00034
00035
00036
00037 class PROPERTY_API PropertyEvent : public RefCounted
00038 {
00039 public:
00040 typedef enum {PropertyWrite, PropertyReplace, PropertyRead} EventType;
00041
00042 private:
00043 EventType event;
00044 string oldvalue;
00045 string newvalue;
00046 string olddatatype;
00047 string newdatatype;
00048 Vobject* initiator;
00049 Property* property;
00050 int offset;
00051 int length;
00052 bool isACcheck;
00053
00054 public:
00055 PropertyEvent(EventType et, Vobject& init, Property& property,
00056 const string& value,
00057 const string& datatype,
00058 bool isACcheck);
00059 PropertyEvent(EventType et, Vobject& init, Property& property,
00060 const string& value,
00061 const string& datatype,
00062 const string& oldvalue,
00063 const string& olddatatype,
00064 bool isACcheck);
00065 PropertyEvent(EventType et, Vobject& init, Property& property,
00066 int offset,
00067 int length,
00068 const string& value,
00069 const string& datatype,
00070 bool isACcheck);
00071 PropertyEvent(EventType et, Vobject& init, Property& property,
00072 int offset,
00073 int length,
00074 const string& value,
00075 const string& datatype,
00076 const string& oldvalue,
00077 const string& olddatatype,
00078 bool isACcheck);
00079
00080 virtual ~PropertyEvent();
00081
00082
00083 EventType getEvent() const { return event; }
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094 Vobject* getInitiator() const { return initiator; }
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105 Property* getProperty() const { return property; }
00106
00107
00108
00109
00110
00111
00112
00113
00114 unsigned int getOffset() const { return offset; }
00115
00116
00117 unsigned int getLength() const { return length; }
00118
00119
00120
00121
00122 const string& getOldValue() const { return oldvalue; }
00123
00124
00125
00126
00127 const string& getNewValue() const { return newvalue; }
00128
00129
00130
00131
00132 const string& getValue() const
00133 { return (isACcheck ? oldvalue : newvalue); }
00134
00135
00136
00137
00138 void setNewValue(const string& v) { newvalue = v; }
00139
00140
00141
00142
00143 const string& getOldDataType() const { return olddatatype; }
00144
00145
00146
00147
00148 const string& getNewDataType() const { return newdatatype; }
00149
00150
00151
00152
00153 const string& getDataType() const
00154 { return (isACcheck ? olddatatype : newdatatype); }
00155
00156
00157
00158
00159 void setNewDataType(const string& dt) { newdatatype = dt; }
00160 };
00161
00162
00163
00164
00165
00166
00167
00168
00169 class PROPERTY_API PropertyListener {
00170 public:
00171 virtual ~PropertyListener();
00172
00173
00174
00175
00176
00177 virtual void notifyPropertyChange(const PropertyEvent& event) = 0;
00178 };
00179
00180
00181
00182
00183
00184 class PROPERTY_API ExtrapolatedPropertyListener {
00185 public:
00186 virtual void notifyBaseChange(ExtrapolatedProperty& ep,
00187 const vector<double>& position,
00188 const vector<double>& velocity,
00189 const vector<double>& acceleration,
00190 double t) = 0;
00191 virtual void notifyPositionChange(ExtrapolatedProperty& ep,
00192 const vector<double>& position,
00193 const vector<double>& velocity,
00194 const vector<double>& acceleration,
00195 double t) = 0;
00196 };
00197
00198
00199
00200
00201
00202
00203
00204 class PROPERTY_API DoNothingPropertyListener : public virtual PropertyListener, public virtual ExtrapolatedPropertyListener
00205 {
00206 public:
00207 static DoNothingPropertyListener static_;
00208
00209 virtual void notifyPropertyChange(const PropertyEvent& e) {};
00210
00211 virtual void notifyPositionChange(ExtrapolatedProperty& , const vector<double>& , const vector<double>& ,
00212 const vector<double>& , double ) {};
00213 virtual void notifyBaseChange(ExtrapolatedProperty& , const vector<double>& , const vector<double>& ,
00214 const vector<double>& , double ) {};
00215 };
00216
00217
00218
00219
00220
00221
00222
00223 class ExtrapolatedListenerSiteWrapper : public virtual ExtrapolatedPropertyListener
00224 {
00225 public:
00226 Site* site;
00227 ExtrapolatedListenerSiteWrapper(Site* s);
00228 virtual ~ExtrapolatedListenerSiteWrapper();
00229 virtual void notifyPositionChange(ExtrapolatedProperty& ep,
00230 const vector<double>& position,
00231 const vector<double>& velocity,
00232 const vector<double>& acceleration,
00233 double t);
00234 virtual void notifyBaseChange(ExtrapolatedProperty& ep,
00235 const vector<double>& position,
00236 const vector<double>& velocity,
00237 const vector<double>& acceleration,
00238 double t);
00239 class Cmp {
00240 public:
00241 inline bool operator()(const ExtrapolatedPropertyListener* p, const ExtrapolatedPropertyListener* q) const {
00242 const ExtrapolatedListenerSiteWrapper* pw;
00243 const ExtrapolatedListenerSiteWrapper* qw;
00244 if((pw = dynamic_cast<const ExtrapolatedListenerSiteWrapper*>(p))
00245 && (qw = dynamic_cast<const ExtrapolatedListenerSiteWrapper*>(q)))
00246 {
00247 return pw->site < qw->site;
00248 } else return (p < q);
00249 };
00250 };
00251 };
00252
00253
00254
00255
00256
00257
00258 class PropertyListenerSiteWrapper : public virtual PropertyListener
00259 {
00260 string firstnonce;
00261 public:
00262 Site* site;
00263 PropertyListenerSiteWrapper(Site* s, const string& firstnonce);
00264 PropertyListenerSiteWrapper(Site* s);
00265 virtual ~PropertyListenerSiteWrapper();
00266 virtual void notifyPropertyChange(const PropertyEvent& e);
00267
00268 class Cmp {
00269 public:
00270 inline bool operator()(const PropertyListener* p, const PropertyListener* q) const {
00271 const PropertyListenerSiteWrapper* pw;
00272 const PropertyListenerSiteWrapper* qw;
00273 if((pw = dynamic_cast<const PropertyListenerSiteWrapper*>(p))
00274 && (qw = dynamic_cast<const PropertyListenerSiteWrapper*>(q)))
00275 {
00276 return pw->site < qw->site;
00277 } else return (p < q);
00278 };
00279 };
00280 };
00281
00282
00283
00284 #endif