Fixed problem in DeviceSettings::strParam, returned wrong string
[avr-sim.git] / src / Clock.h
blob7c225768c426c716c16beb0c85ac9cced0ffed83
1 #ifndef SIM_CLOCK_H
2 #define SIM_CLOCK_H
4 #ifdef __GNUC__
5 # include <ext/slist>
6 #else
7 # include <list>
8 #endif
10 #include <utility>
11 #include "Types.h"
13 namespace sim {
14 typedef unsigned long long ClockOffset;
16 /**
17 * @author Tom Haber
18 * @date Apr 27, 2008
19 * @brief Template clock class
21 * This class is used by SimulationClock and Bus to provide the
22 * timings for SimulationObjects and Hardware. It implements
23 * the basic clock functionality: stepping and breakpoints.
25 * TODO optimize, some methods have a lazy implementation
26 * TODO slist might be too slow (also has portability issues)
28 template <class Type>
29 class Clock {
30 public:
31 Clock() : value(0) {}
33 public:
34 void setBreak(ClockOffset cycle, Type *obj);
35 void setBreakDelta(ClockOffset delta, Type *obj);
36 void setDividedBreak(ClockOffset prescaler, ClockOffset delta, Type *obj);
37 void clearBreak(Type *obj);
38 void clearBreak(ClockOffset cycle);
39 void reassignBreak(ClockOffset oldCycle, ClockOffset newCycle, Type *obj);
40 void reassignBreak(Type *obj, ClockOffset newCycle);
41 void reassignBreakDelta(ClockOffset delta, Type *obj);
43 public:
44 void step();
45 void clearAll();
47 ClockOffset ticks() const { return value; }
48 bool isEmpty() const { return objects.empty(); }
50 private:
51 ClockOffset value;
53 typedef std::pair<ClockOffset, Type*> Break;
54 #ifdef __GNUC__
55 typedef __gnu_cxx::slist< Break > ClockList;
56 #else
57 typedef std::slist< Break > ClockList;
58 #endif
59 typedef typename ClockList::iterator ClockListIt;
60 ClockList objects;
63 template <class Type>
64 inline void Clock<Type>::setBreakDelta(ClockOffset delta, Type *obj) {
65 setBreak( value + delta, obj );
70 #ifndef SIM_CLOCK_INC
71 # include "Clock.inc"
72 #endif
73 #endif /*SIM_CLOCK_H*/