clock.h

Go to the documentation of this file.
00001 #include <list>
00002 
00003 class tickObjBase 
00004 {
00005   public:
00006   virtual void CallTick() = 0;
00007 };
00008 
00009 template <typename OBJ>
00010 class tickObj : public tickObjBase {
00011  public:
00012   tickObj(OBJ* o, void (OBJ::*f)(void)) : obj(o), funct(f) {}
00013   void CallTick() 
00014   {
00015     (obj->*funct)();
00016   }
00017   OBJ* obj;
00018   void (OBJ::*funct)(void);
00019 };
00020 
00021 
00022 using namespace std;
00023 class Clock
00024 {
00025  public:
00026   Clock(double);
00027  public:
00028   double frequency;    //Frequency of the clock
00029   double period;  //Period of the clock
00030   void risingEdge();
00031   void fallingEdge();
00032   //List of handlers registered for rising edge
00033   list<tickObjBase*> risingObjs;
00034   //List of handlers registered for falling edge
00035   list<tickObjBase*> fallingObjs;
00036 };
00037 
00038 template <typename OBJ> void registerClock(Clock* c, OBJ* obj, void(OBJ::*rising)(void), void(OBJ::*falling)(void))
00039 {
00040   if(rising) 
00041     {
00042       tickObjBase* riseObj=new tickObj<OBJ>(obj, rising);
00043       c->risingObjs.push_back(riseObj);
00044     }
00045   if(falling)
00046     {
00047       tickObjBase* fallObj=new tickObj<OBJ>(obj, falling);
00048       c->fallingObjs.push_back(fallObj);
00049     }
00050 }

Generated on Tue Oct 19 17:22:00 2010 for IRIS by  doxygen 1.5.8