UniSet  1.4.0
TriggerOutput_template.h
См. документацию.
00001 /* This file is part of the UniSet project
00002  * Copyright (c) 2002 Free Software Foundation, Inc.
00003  * Copyright (c) 2002 Pavel Vainerman
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00018  */
00019 // --------------------------------------------------------------------------
00023 // --------------------------------------------------------------------------
00024 
00025 //---------------------------------------------------------------------------
00026 #include "TriggerOutput.h"
00027 //---------------------------------------------------------------------------
00028 
00029 template<class Caller, typename OutIdType, typename ValueType>
00030 TriggerOutput<Caller,OutIdType,ValueType>::TriggerOutput( Caller* r, Action a):
00031     cal(r),
00032     act(a)
00033 {
00034 }
00035 
00036 template <class Caller, typename OutIdType, typename ValueType>
00037 TriggerOutput<Caller,OutIdType,ValueType>::~TriggerOutput()
00038 {
00039 }
00040 
00041 //---------------------------------------------------------------------------
00042 template <class Caller, typename OutIdType, typename ValueType>
00043 void TriggerOutput<Caller,OutIdType,ValueType>::add(OutIdType num, ValueType val)
00044 {
00045     outs[num] = val; 
00046     set(num,val);
00047     try
00048     {
00049         (cal->*act)(num,val);
00050     }
00051     catch(...){}
00052 }
00053 
00054 //---------------------------------------------------------------------------
00055 template <class Caller, typename OutIdType, typename ValueType>
00056 void TriggerOutput<Caller,OutIdType,ValueType>::remove(OutIdType num)
00057 {
00058     typename OutList::iterator it=outs.find(num);
00059     if( it!=outs.end() )
00060         outs.erase(it);
00061 }
00062 
00063 //---------------------------------------------------------------------------
00064 template <class Caller, typename OutIdType, typename ValueType>
00065 bool TriggerOutput<Caller,OutIdType,ValueType>::getState(OutIdType out)
00066 {
00067     typename OutList::iterator it=outs.find(out);
00068     if( it!=outs.end() )
00069         return it->second;
00070 
00071     return false;
00072 }
00073 //---------------------------------------------------------------------------
00074 template <class Caller, typename OutIdType, typename ValueType>
00075 void TriggerOutput<Caller,OutIdType,ValueType>::set(OutIdType out, ValueType val)
00076 {
00077     typename OutList::iterator it=outs.find(out);
00078     if( it==outs.end() )
00079         return;
00080 
00081     // потом val
00082     ValueType prev(it->second);
00083     it->second = val;
00084     if( prev != val )
00085     {
00086         check(out);  // выставляем сперва все нули
00087         try
00088         {
00089             (cal->*act)(it->first, it->second);
00090         }
00091         catch(...){}
00092     }
00093 }
00094 //---------------------------------------------------------------------------
00095 template <class Caller, typename OutIdType, typename ValueType>
00096 void TriggerOutput<Caller,OutIdType,ValueType>::check(OutIdType newout)
00097 {
00098     for( typename OutList::iterator it=outs.begin(); it!=outs.end(); ++it )
00099     {
00100         if( it->first != newout && it->second )
00101         {
00102             it->second = 0;
00103 //          try
00104 //          {
00105                 (cal->*act)(it->first, it->second);
00106 //          }
00107 //          catch(...){}
00108         }
00109     }
00110 
00111 }
00112 //---------------------------------------------------------------------------
00113 template <class Caller, typename OutIdType, typename ValueType>
00114 void TriggerOutput<Caller,OutIdType,ValueType>::update()
00115 {
00116     for( typename OutList::iterator it=outs.begin(); it!=outs.end(); ++it )
00117         (cal->*act)(it->first, it->second);
00118 }
00119 //---------------------------------------------------------------------------
00120 template <class Caller, typename OutIdType, typename ValueType>
00121 void TriggerOutput<Caller,OutIdType,ValueType>::reset()
00122 {
00123     for( typename OutList::iterator it=outs.begin(); it!=outs.end(); ++it )
00124     {
00125         it->second = 0;
00126         (cal->*act)(it->first, it->second);
00127     }
00128 }
00129 //---------------------------------------------------------------------------