00001 
00002 #ifndef INCLUDED_CompareTrans_h_
00003 #define INCLUDED_CompareTrans_h_
00004 
00005 #include "Behaviors/Transition.h"
00006 #include "Events/EventRouter.h"
00007 #include "Shared/MarkScope.h"
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 template<class T>
00026 class CompareTrans : public Transition {
00027 public:
00028 
00029   enum Test_t {
00030     LT, 
00031     GT, 
00032     LTE, 
00033     GTE, 
00034     EQ, 
00035     NE 
00036   };
00037   
00038 
00039   CompareTrans(StateNode* destination, const T* monitor, Test_t test, const T& value)
00040     : Transition(destination), mon(monitor), tst(test), val(value), isPolling(false), poller()
00041   { }
00042   
00043 
00044   CompareTrans(const std::string& name, StateNode* destination, const T* monitor, Test_t test, const T& value)
00045     : Transition(name,destination), mon(monitor), tst(test), val(value), isPolling(false), poller()
00046   { }
00047   
00048 
00049   CompareTrans(StateNode* destination, const T* monitor, Test_t test, const T& value, const EventBase& poll)
00050     : Transition(destination), mon(monitor), tst(test), val(value), isPolling(true), poller(poll)
00051   { }
00052   
00053 
00054   CompareTrans(const std::string& name, StateNode* destination, const T* monitor, Test_t test, const T& value, const EventBase& poll)
00055     : Transition(name,destination), mon(monitor), tst(test), val(value), isPolling(true), poller(poll)
00056   { }
00057   
00058 
00059   virtual void postStart() {
00060     Transition::postStart();
00061     if(isPolling)
00062       erouter->addListener(this,poller);
00063     else
00064       doEvent();
00065   }
00066 
00067 
00068   virtual void doEvent() {
00069     switch(tst) {
00070     case LT:
00071       if(*mon<val) fire();
00072       break;
00073     case GT:
00074       if(val<*mon) fire();
00075       break;
00076     case LTE:
00077       if(!(val<*mon)) fire();
00078       break;
00079     case GTE:
00080       if(!(*mon<val)) fire();
00081       break;
00082     case EQ:
00083       if(*mon==val) fire();
00084       break;
00085     case NE:
00086       if(!(*mon==val)) fire();
00087       break;
00088     }
00089   }
00090 
00091 protected:
00092   const T* mon; 
00093   Test_t tst; 
00094   T val; 
00095   bool isPolling; 
00096   EventBase poller; 
00097 
00098 private:
00099   CompareTrans(const CompareTrans& node); 
00100   CompareTrans operator=(const CompareTrans& node); 
00101 };
00102 
00103 
00104 
00105 
00106 
00107 
00108 #endif