csutil/compositefunctor.h
00001 /* 00002 Copyright (C) 2007 by Marten Svanfeldt 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library 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 GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public 00015 License along with this library; if not, write to the Free 00016 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00017 */ 00018 00019 #ifndef __CS_CSUTIL_COMPOSITEFUNCTOR_H__ 00020 #define __CS_CSUTIL_COMPOSITEFUNCTOR_H__ 00021 00022 namespace CS 00023 { 00024 namespace Meta 00025 { 00026 00027 template<typename Fn1, typename Fn2> 00028 class CompositeFunctorType2 00029 { 00030 public: 00031 CompositeFunctorType2 (Fn1& fn1, Fn2& fn2) 00032 : fn1 (fn1), fn2 (fn2) 00033 {} 00034 00035 void operator() () 00036 { 00037 fn1(); 00038 fn2(); 00039 } 00040 00041 template<typename A1> 00042 void operator() (A1& a1) 00043 { 00044 fn1(a1); 00045 fn2(a1); 00046 } 00047 00048 template<typename A1, typename A2> 00049 void operator() (A1& a1, A2& a2) 00050 { 00051 fn1(a1, a2); 00052 fn2(a1, a2); 00053 } 00054 00055 template<typename A1, typename A2, typename A3> 00056 void operator() (A1& a1, A2& a2, A3& a3) 00057 { 00058 fn1(a1, a2, a3); 00059 fn2(a1, a2, a3); 00060 } 00061 00062 template<typename A1, typename A2, typename A3, typename A4> 00063 void operator() (A1& a1, A2& a2, A3& a3, A4& a4) 00064 { 00065 fn1(a1, a2, a3, a4); 00066 fn2(a1, a2, a3, a4); 00067 } 00068 00069 private: 00070 Fn1& fn1; 00071 Fn2& fn2; 00072 }; 00073 00074 template<typename Fn1, typename Fn2, typename Fn3> 00075 class CompositeFunctorType3 00076 { 00077 public: 00078 CompositeFunctorType3 (Fn1& fn1, Fn2& fn2, Fn3& fn3) 00079 : fn1 (fn1), fn2 (fn2), fn3 (fn3) 00080 {} 00081 00082 void operator() () 00083 { 00084 fn1(); 00085 fn2(); 00086 fn3(); 00087 } 00088 00089 template<typename A1> 00090 void operator() (A1& a1) 00091 { 00092 fn1(a1); 00093 fn2(a1); 00094 fn3(a1); 00095 } 00096 00097 template<typename A1, typename A2> 00098 void operator() (A1& a1, A2& a2) 00099 { 00100 fn1(a1, a2); 00101 fn2(a1, a2); 00102 fn3(a1, a2); 00103 } 00104 00105 template<typename A1, typename A2, typename A3> 00106 void operator() (A1& a1, A2& a2, A3& a3) 00107 { 00108 fn1(a1, a2, a3); 00109 fn2(a1, a2, a3); 00110 fn3(a1, a2, a3); 00111 } 00112 00113 template<typename A1, typename A2, typename A3, typename A4> 00114 void operator() (A1& a1, A2& a2, A3& a3, A4& a4) 00115 { 00116 fn1(a1, a2, a3, a4); 00117 fn2(a1, a2, a3, a4); 00118 fn3(a1, a2, a3, a4); 00119 } 00120 00121 private: 00122 Fn1& fn1; 00123 Fn2& fn2; 00124 Fn3& fn3; 00125 }; 00126 00127 template<typename Fn1, typename Fn2> 00128 CompositeFunctorType2<Fn1, Fn2> CompositeFunctor (Fn1& fn1, Fn2& fn2) 00129 { 00130 return CompositeFunctorType2<Fn1, Fn2> (fn1, fn2); 00131 } 00132 00133 template<typename Fn1, typename Fn2, typename Fn3> 00134 CompositeFunctorType3<Fn1, Fn2, Fn3> CompositeFunctor (Fn1& fn1, Fn2& fn2, Fn3& fn3) 00135 { 00136 return CompositeFunctorType3<Fn1, Fn2, Fn3> (fn1, fn2, fn3); 00137 } 00138 } 00139 } 00140 00141 #endif
Generated for Crystal Space 2.0 by doxygen 1.6.1