Fixed problem in DeviceSettings::strParam, returned wrong string
[avr-sim.git] / src / Clock.inc
blobee8ae5c4bb72c813ae451f49de47bcebc6260b3f
1 #ifndef SIM_CLOCK_INC
2 #define SIM_CLOCK_INC
4 namespace sim {
6         template <class Type>
7         void Clock<Type>::setBreak(ClockOffset cycle, Type *obj) {
8                 ClockListIt it = objects.begin();
9                 while( it != objects.end() ) {
10                         if( it->first >= cycle )
11                                 break;
13                         it++;
14                 }
16                 objects.insert( it, std::make_pair(cycle, obj) );
17         }
19         template <class Type>
20         void Clock<Type>::setDividedBreak(ClockOffset prescaler, ClockOffset delta,
21                         Type *obj) {
23                 const ClockOffset mask = (prescaler - 1);
24                 const ClockOffset rem = prescaler - (value & mask);
25                 setBreak( value + rem + (delta - 1) * prescaler, obj );
26         }
28         template <class Type>
29         void Clock<Type>::clearBreak(Type *obj) {
30                 ClockListIt it = objects.begin();
31                 while( it != objects.end() ) {
32                         if( it->second == obj )
33                                 break;
35                         it++;
36                 }
38                 if( it != objects.end() )
39                         objects.erase( it );
40         }
42         template <class Type>
43         void Clock<Type>::clearBreak(ClockOffset cycle) {
44                 ClockListIt it = objects.begin();
45                 while( it != objects.end() ) {
46                         if( it->first >= cycle )
47                                 break;
49                         it++;
50                 }
52                 if( (it != objects.end()) && (it->first == cycle) )
53                         objects.erase( it );
54         }
56         template <class Type>
57         void Clock<Type>::reassignBreak(ClockOffset oldCycle, ClockOffset newCycle,
58                                                                         Type *obj) {
60                 ClockListIt it = objects.begin();
61                 while( it != objects.end() ) {
62                         if( it->first >= oldCycle )
63                                 break;
64                         else
65                                 it++;
66                 }
68                 if( (it != objects.end()) && (it->first == oldCycle) ) {
69                         objects.erase( it );
70                         setBreak( newCycle, obj );
71                 }
72         }
74         template <class Type>
75         void Clock<Type>::reassignBreak(Type *obj, ClockOffset newCycle) {
76                 clearBreak(obj);
77                 setBreak( newCycle, obj );
78         }
80         template <class Type>
81         void Clock<Type>::step() {
82                 value++;
84                 ClockListIt it = objects.begin();
85                 while( it != objects.end() ) {
86                         if( it->first > value )
87                                 break;
89                         Type *obj = it->second;
90                         obj->step();
91                         it++;
92                 }
94                 objects.erase( objects.begin(), it );
95         }
97         template <class Type>
98         void Clock<Type>::clearAll() {
99                 objects.clear();
100         }
102         template <class Type>
103         void Clock<Type>::reassignBreakDelta(ClockOffset delta, Type *obj) {
104                 clearBreak(obj);
105                 setBreakDelta(delta, obj);
106         }
109 #endif