• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

spl/DelegateDispatch.h

00001 /*
00002  *   This file is part of the Standard Portable Library (SPL).
00003  *
00004  *   SPL is free software: you can redistribute it and/or modify
00005  *   it under the terms of the GNU General Public License as published by
00006  *   the Free Software Foundation, either version 3 of the License, or
00007  *   (at your option) any later version.
00008  *
00009  *   SPL is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details.
00013  *
00014  *   You should have received a copy of the GNU General Public License
00015  *   along with SPL.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 #ifndef _delegatedispatch_h
00018 #define _delegatedispatch_h
00019 
00020 #include <spl/Delegate.h>
00021 #include <spl/collection/Vector.h>
00022 
00033 class DelegateDispatch : public IMemoryValidate
00034 {
00035 private:
00036         Vector<RefCountPtr<IDelegate> > m_delegates;
00037 
00038 public:
00039         DelegateDispatch();
00040         virtual ~DelegateDispatch();
00041 
00042         inline void Add(RefCountPtr<IDelegate> d)
00043         {
00044                 m_delegates.Add(d);
00045         }
00046 
00047         inline void operator +=(RefCountPtr<IDelegate> d)
00048         {
00049                 Add(d);
00050         }
00051 
00052         void Call();
00053 
00054         void Clear();
00055 
00056 #if defined(DEBUG)
00057         virtual void CheckMem() const;
00058         virtual void ValidateMem() const;
00059 #endif
00060 };
00061 
00066 template<typename ARG1>
00067 class DelegateDispatchOneParameter : public IMemoryValidate
00068 {
00069 private:
00070         Vector<RefCountPtr<IDelegateOneParameter<ARG1> > > m_delegates;
00071 
00072 public:
00073         DelegateDispatchOneParameter()
00074         : m_delegates()
00075         {
00076         }
00077 
00078         virtual ~DelegateDispatchOneParameter()
00079         {
00080         }
00081 
00082         inline void Add(RefCountPtr<IDelegateOneParameter<ARG1> > d)
00083         {
00084                 m_delegates.Add(d);
00085         }
00086 
00087         inline void operator +=(RefCountPtr<IDelegateOneParameter<ARG1> > d)
00088         {
00089                 Add(d);
00090         }
00091 
00092         void Call(ARG1 arg1)
00093         {
00094                 for (int x = 0; x < m_delegates.Count(); x++ )
00095                 {
00096                         m_delegates.ElementAtRef(x)->Call(arg1);
00097                 }
00098         }
00099 
00100         void Clear()
00101         {
00102                 for (int x = 0; x < m_delegates.Count(); x++ )
00103                 {
00104                         m_delegates.ElementAtRef(x)->Clear();
00105                 }
00106                 m_delegates.Clear();
00107         }
00108 
00109 #if defined(DEBUG)
00110         void CheckMem() const
00111         {
00112                 m_delegates.CheckMem();
00113         }
00114 
00115         void ValidateMem() const
00116         {
00117                 m_delegates.ValidateMem();
00118         }
00119 #endif
00120 };
00121 
00126 template<typename ARG1, typename ARG2>
00127 class DelegateDispatchTwoParameter : public IMemoryValidate
00128 {
00129 private:
00130         Vector<RefCountPtr<IDelegateTwoParameter<ARG1, ARG2> > > m_delegates;
00131 
00132 public:
00133         DelegateDispatchTwoParameter()
00134         : m_delegates()
00135         {
00136         }
00137 
00138         virtual ~DelegateDispatchTwoParameter()
00139         {
00140         }
00141 
00142         inline void Add(RefCountPtr<IDelegateTwoParameter<ARG1, ARG2> > d)
00143         {
00144                 m_delegates.Add(d);
00145         }
00146 
00147         inline void operator +=(RefCountPtr<IDelegateTwoParameter<ARG1, ARG2> > d)
00148         {
00149                 Add(d);
00150         }
00151 
00152         void Call(ARG1 arg1, ARG2 arg2)
00153         {
00154                 for (int x = 0; x < m_delegates.Count(); x++ )
00155                 {
00156                         m_delegates.ElementAtRef(x)->Call(arg1, arg2);
00157                 }
00158         }
00159 
00160         void Clear()
00161         {
00162                 for (int x = 0; x < m_delegates.Count(); x++ )
00163                 {
00164                         m_delegates.ElementAtRef(x)->Clear();
00165                 }
00166                 m_delegates.Clear();
00167         }
00168 
00169 #if defined(DEBUG)
00170         void CheckMem() const
00171         {
00172                 m_delegates.CheckMem();
00173         }
00174 
00175         void ValidateMem() const
00176         {
00177                 m_delegates.ValidateMem();
00178         }
00179 #endif
00180 };
00181 
00186 template<typename ARG1, typename ARG2, typename ARG3>
00187 class DelegateDispatchThreeParameter : public IMemoryValidate
00188 {
00189 private:
00190         Vector<RefCountPtr<IDelegateThreeParameter<ARG1, ARG2, ARG3> > > m_delegates;
00191 
00192 public:
00193         DelegateDispatchThreeParameter()
00194         : m_delegates()
00195         {
00196         }
00197 
00198         virtual ~DelegateDispatchThreeParameter()
00199         {
00200         }
00201 
00202         inline void Add(RefCountPtr<IDelegateThreeParameter<ARG1, ARG2, ARG3> > d)
00203         {
00204                 m_delegates.Add(d);
00205         }
00206 
00207         inline void operator +=(RefCountPtr<IDelegateThreeParameter<ARG1, ARG2, ARG3> > d)
00208         {
00209                 Add(d);
00210         }
00211 
00212         void Call(ARG1 arg1, ARG2 arg2, ARG3 arg3)
00213         {
00214                 for (int x = 0; x < m_delegates.Count(); x++ )
00215                 {
00216                         m_delegates.ElementAtRef(x)->Call(arg1, arg2, arg3);
00217                 }
00218         }
00219 
00220         void Clear()
00221         {
00222                 for (int x = 0; x < m_delegates.Count(); x++ )
00223                 {
00224                         m_delegates.ElementAtRef(x)->Clear();
00225                 }
00226                 m_delegates.Clear();
00227         }
00228 
00229 #if defined(DEBUG)
00230         void CheckMem() const
00231         {
00232                 m_delegates.CheckMem();
00233         }
00234 
00235         void ValidateMem() const
00236         {
00237                 m_delegates.ValidateMem();
00238         }
00239 #endif
00240 };
00241 
00244 #endif