00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00023
00024 #include "TriggerOR.h"
00025
00026 template<class Caller, typename InputType>
00027 TriggerOR<Caller,InputType>::TriggerOR(Caller* c, Action a):
00028 cal(c),
00029 act(a)
00030 {
00031 }
00032
00033 template<class Caller, typename InputType>
00034 TriggerOR<Caller,InputType>::~TriggerOR()
00035 {
00036 }
00037
00038
00039 template<class Caller, typename InputType>
00040 bool TriggerOR<Caller,InputType>::commit(InputType num, bool state)
00041 {
00042 typename InputMap::iterator it=inputs.find(num);
00043 if( it!=inputs.end() )
00044 {
00045 inputs[num] = state;
00046 check();
00047 return true;
00048 }
00049
00050 return false;
00051 }
00052
00053
00054 template<class Caller, typename InputType>
00055 void TriggerOR<Caller,InputType>::add(InputType num, bool state)
00056 {
00057 inputs[num] = state;
00058 check();
00059 }
00060
00061
00062 template<class Caller, typename InputType>
00063 void TriggerOR<Caller,InputType>::remove(InputType num)
00064 {
00065 typename InputMap::iterator it=inputs.find(num);
00066 if( it!=inputs.end() )
00067 inputs.erase(it);
00068
00069 check();
00070 }
00071
00072
00073 template<class Caller, typename InputType>
00074 bool TriggerOR<Caller,InputType>::getState(InputType num)
00075 {
00076 typename InputMap::iterator it=inputs.find(num);
00077 if( it!=inputs.end() )
00078 return it->second;
00079
00080 return false;
00081 }
00082
00083 template<class Caller, typename InputType>
00084 void TriggerOR<Caller,InputType>::check()
00085 {
00086 bool old = out;
00087 for( typename InputMap::iterator it=inputs.begin(); it!=inputs.end(); ++it )
00088 {
00089 if( it->second )
00090 {
00091
00092
00093 out = true;
00094 if( old != out )
00095 {
00096
00097
00098 (cal->*act)(out);
00099
00100
00101 }
00102 return;
00103 }
00104 }
00105
00106 out = false;
00107
00108 if( old != out )
00109 {
00110
00111
00112 (cal->*act)(out);
00113
00114
00115 }
00116 }
00117
00118 template<class Caller, typename InputType>
00119 void TriggerOR<Caller,InputType>::update()
00120 {
00121 (cal->*act)(out);
00122 }
00123
00124 template<class Caller, typename InputType>
00125 void TriggerOR<Caller,InputType>::reset()
00126 {
00127 out = false;
00128 (cal->*act)(out);
00129 }
00130