add multiple argument versions
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Sun Sep 03 12:40:19 2006 +0200 (2006-09-03)
changeset 26011c8d27b674
parent 25 9b3bb088c560
child 27 77c7b2337cba
add multiple argument versions
src/simulator/simulator.h
     1.1 --- a/src/simulator/simulator.h	Sun Sep 03 12:24:04 2006 +0200
     1.2 +++ b/src/simulator/simulator.h	Sun Sep 03 12:40:19 2006 +0200
     1.3 @@ -141,6 +141,7 @@
     1.4  	 */
     1.5  	template <typename T>
     1.6  	static EventId schedule (Time time, void (T::*mem_ptr) (void), T *obj) {
     1.7 +		// zero argument version
     1.8  		class EventMemberImpl0 : public EventImpl {
     1.9  		public:
    1.10  			typedef void (T::*F)(void);
    1.11 @@ -158,7 +159,149 @@
    1.12  		} *ev = new EventMemberImpl0 (obj, mem_ptr);
    1.13  		return schedule (time, ev);
    1.14  	}
    1.15 +	template <typename T, typename T1>
    1.16 +	static EventId schedule (Time time, void (T::*f) (T1), T* t, T1 a1) {
    1.17 +		// one argument version
    1.18 +		class EventMemberImpl1 : public EventImpl {
    1.19 +		public:
    1.20 +			typedef void (T::*F)(T1);
    1.21 +			EventMemberImpl1 (T *obj, F function, T1 a1) 
    1.22 +				: m_obj (obj), 
    1.23 +				  m_function (function),
    1.24 +				  m_a1 (a1)
    1.25 +			{}
    1.26 +		protected:
    1.27 +			virtual ~EventMemberImpl1 () {}
    1.28 +		private:
    1.29 +			virtual void notify (void) { 
    1.30 +				(m_obj->*m_function) (m_a1);
    1.31 +			}
    1.32 +			T* m_obj;
    1.33 +			F m_function;
    1.34 +			T1 m_a1;
    1.35 +		} *ev = new EventMemberImpl1 (f, t, a1);
    1.36 +		return schedule (time, ev);
    1.37 +	}
    1.38 +	template <typename T, typename T1, typename T2>
    1.39 +	static EventId schedule (Time time, void (T::*f) (T1), T* t, T1 a1, T2 a2) {
    1.40 +		// two argument version
    1.41 +		class EventMemberImpl2 : public EventImpl {
    1.42 +		public:
    1.43 +			typedef void (T::*F)(T1, T2);
    1.44 +			
    1.45 +			EventMemberImpl2 (T *obj, F function, T1 a1, T2 a2) 
    1.46 +				: m_obj (obj), 
    1.47 +				  m_function (function),
    1.48 +				  m_a1 (a1),
    1.49 +				  m_a2 (a2)
    1.50 +			{ }
    1.51 +		protected:
    1.52 +			virtual ~EventMemberImpl2 () {}
    1.53 +		private:
    1.54 +			virtual void notify (void) { 
    1.55 +				(m_obj->*m_function) (m_a1, m_a2);
    1.56 +			}
    1.57 +			T* m_obj;
    1.58 +			F m_function;
    1.59 +			T1 m_a1;
    1.60 +			T2 m_a2;
    1.61 +		} *ev = new EventMemberImpl2 (t, f, a1, a2);
    1.62 +
    1.63 +		return schedule (time, ev);
    1.64 +	}
    1.65 +	template <typename T, typename T1, typename T2, typename T3>
    1.66 +	static EventId schedule (Time time, void (T::*f) (T1), T* t, T1 a1, T2 a2, T3 a3) {
    1.67 +		// three argument version
    1.68 +		class EventMemberImpl3 : public EventImpl {
    1.69 +		public:
    1.70 +			typedef void (T::*F)(T1, T2, T3);
    1.71 +			
    1.72 +			EventMemberImpl3 (T *obj, F function, T1 a1, T2 a2, T3 a3) 
    1.73 +				: m_obj (obj), 
    1.74 +				  m_function (function),
    1.75 +				  m_a1 (a1),
    1.76 +		  m_a2 (a2),
    1.77 +				  m_a3 (a3)
    1.78 +			{ }
    1.79 +		protected:
    1.80 +			virtual ~EventMemberImpl3 () {}
    1.81 +		private:
    1.82 +			virtual void notify (void) { 
    1.83 +				(m_obj->*m_function) (m_a1, m_a2, m_a3);
    1.84 +			}
    1.85 +			T* m_obj;
    1.86 +			F m_function;
    1.87 +			T1 m_a1;
    1.88 +			T2 m_a2;
    1.89 +			T3 m_a3;
    1.90 +		} *ev = new EventMemberImpl3 (t, f, a1, a2, a3);
    1.91 +		return schedule (time, ev);
    1.92 +	}
    1.93 +	template <typename T, typename T1, typename T2, typename T3, typename T4>
    1.94 +	static EventId schedule (Time time, void (T::*f) (T1), T* t, T1 a1, T2 a2, T3 a3, T4 a4) {
    1.95 +		// four argument version
    1.96 +		class EventMemberImpl4 : public EventImpl {
    1.97 +		public:
    1.98 +			typedef void (T::*F)(T1, T2, T3, T4);
    1.99 +			
   1.100 +			EventMemberImpl4 (T *obj, F function, T1 a1, T2 a2, T3 a3, T4 a4) 
   1.101 +				: m_obj (obj), 
   1.102 +				  m_function (function),
   1.103 +				  m_a1 (a1),
   1.104 +				  m_a2 (a2),
   1.105 +				  m_a3 (a3),
   1.106 +				  m_a4 (a4)
   1.107 +			{ }
   1.108 +		protected:
   1.109 +			virtual ~EventMemberImpl4 () {}
   1.110 +		private:
   1.111 +			virtual void notify (void) { 
   1.112 +				(m_obj->*m_function) (m_a1, m_a2, m_a3, m_a4);
   1.113 +			}
   1.114 +			T* m_obj;
   1.115 +			F m_function;
   1.116 +			T1 m_a1;
   1.117 +			T2 m_a2;
   1.118 +			T3 m_a3;
   1.119 +			T4 m_a4;
   1.120 +		} *ev = new EventMemberImpl4 (t, f, a1, a2, a3, a4);
   1.121 +		return schedule (time, ev);
   1.122 +	}
   1.123 +	template <typename T, typename T1, typename T2, typename T3, typename T4, typename T5>
   1.124 +	static EventId schedule (Time time, void (T::*f) (T1), T* t, 
   1.125 +				 T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) {
   1.126 +		// five argument version
   1.127 +		class EventMemberImpl5 : public EventImpl {
   1.128 +		public:
   1.129 +			typedef void (T::*F)(T1, T2, T3, T4, T5);
   1.130 +			
   1.131 +			EventMemberImpl5 (T *obj, F function, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) 
   1.132 +				: m_obj (obj), 
   1.133 +				  m_function (function),
   1.134 +				  m_a1 (a1),
   1.135 +				  m_a2 (a2),
   1.136 +				  m_a3 (a3),
   1.137 +				  m_a4 (a4),
   1.138 +				  m_a5 (a5)
   1.139 +			{ }
   1.140 +		protected:
   1.141 +			virtual ~EventMemberImpl5 () {}
   1.142 +		private:
   1.143 +			virtual void notify (void) { 
   1.144 +				(m_obj->*m_function) (m_a1, m_a2, m_a3, m_a4, m_a5);
   1.145 +			}
   1.146 +			T* m_obj;
   1.147 +			F m_function;
   1.148 +			T1 m_a1;
   1.149 +			T2 m_a2;
   1.150 +			T3 m_a3;
   1.151 +			T4 m_a4;
   1.152 +			T5 m_a5;
   1.153 +		} *ev = new EventMemberImpl5 (t, f, a1, a2, a3, a4, a5);
   1.154 +		return schedule (time, ev);
   1.155 +	}
   1.156  	static EventId schedule (Time time, void (*f) (void)) {
   1.157 +		// zero arg version
   1.158  		class EventFunctionImpl0 : public EventImpl {
   1.159  		public:
   1.160  			typedef void (*F)(void);
   1.161 @@ -178,6 +321,7 @@
   1.162  	}
   1.163  	template <typename T1>
   1.164  	static EventId schedule (Time time, void (*f) (T1), T1 a1) {
   1.165 +		// one arg version
   1.166  		class EventFunctionImpl1 : public EventImpl {
   1.167  		public:
   1.168  			typedef void (*F)(T1);
   1.169 @@ -197,6 +341,114 @@
   1.170  		} *ev = new EventFunctionImpl1(f, a1);
   1.171  		return schedule (time, ev);
   1.172  	}
   1.173 +	template <typename T1, typename T2>
   1.174 +	static EventId schedule (Time time, void (*f) (T1), T1 a1, T2 a2) {
   1.175 +		// two arg version
   1.176 +		class EventFunctionImpl2 : public EventImpl {
   1.177 +		public:
   1.178 +			typedef void (*F)(T1, T2);
   1.179 +			
   1.180 +			EventFunctionImpl2 (F function, T1 a1, T2 a2) 
   1.181 +				: m_function (function),
   1.182 +				  m_a1 (a1),
   1.183 +				  m_a2 (a2)
   1.184 +			{ }
   1.185 +		protected:
   1.186 +			virtual ~EventFunctionImpl2 () {}
   1.187 +		private:
   1.188 +			virtual void notify (void) { 
   1.189 +				(*m_function) (m_a1, m_a2);
   1.190 +			}
   1.191 +			F m_function;
   1.192 +			T1 m_a1;
   1.193 +			T2 m_a2;
   1.194 +		} *ev = new EventFunctionImpl2 (f, a1, a2);
   1.195 +		return schedule (time, ev);
   1.196 +	}
   1.197 +	template <typename T1, typename T2, typename T3>
   1.198 +	static EventId schedule (Time time, void (*f) (T1), T1 a1, T2 a2, T3 a3) {
   1.199 +		// three arg version
   1.200 +		class EventFunctionImpl3 : public EventImpl {
   1.201 +		public:
   1.202 +			typedef void (*F)(T1, T2, T3);
   1.203 +			
   1.204 +			EventFunctionImpl3 (F function, T1 a1, T2 a2, T3 a3) 
   1.205 +				: m_function (function),
   1.206 +				  m_a1 (a1),
   1.207 +				  m_a2 (a2),
   1.208 +				  m_a3 (a3)
   1.209 +			{ }
   1.210 +		protected:
   1.211 +			virtual ~EventFunctionImpl3 () {}
   1.212 +		private:
   1.213 +			virtual void notify (void) { 
   1.214 +				(*m_function) (m_a1, m_a2, m_a3);
   1.215 +			}
   1.216 +			F m_function;
   1.217 +			T1 m_a1;
   1.218 +			T2 m_a2;
   1.219 +			T3 m_a3;
   1.220 +		} *ev = new EventFunctionImpl3 (f, a1, a2, a3);
   1.221 +		return schedule (time, ev);
   1.222 +	}
   1.223 +	template <typename T1, typename T2, typename T3, typename T4>
   1.224 +	static EventId schedule (Time time, void (*f) (T1), T1 a1, T2 a2, T3 a3, T4 a4) {
   1.225 +		// four arg version
   1.226 +		class EventFunctionImpl4 : public EventImpl {
   1.227 +		public:
   1.228 +			typedef void (*F)(T1, T2, T3, T4);
   1.229 +			
   1.230 +			EventFunctionImpl4 (F function, T1 a1, T2 a2, T3 a3, T4 a4) 
   1.231 +				: m_function (function),
   1.232 +				  m_a1 (a1),
   1.233 +				  m_a2 (a2),
   1.234 +				  m_a3 (a3),
   1.235 +				  m_a4 (a4)
   1.236 +			{ }
   1.237 +		protected:
   1.238 +			virtual ~EventFunctionImpl4 () {}
   1.239 +		private:
   1.240 +			virtual void notify (void) { 
   1.241 +				(*m_function) (m_a1, m_a2, m_a3, m_a4);
   1.242 +			}
   1.243 +			F m_function;
   1.244 +			T1 m_a1;
   1.245 +			T2 m_a2;
   1.246 +			T3 m_a3;
   1.247 +			T4 m_a4;
   1.248 +		} *ev = new EventFunctionImpl4 (f, a1, a2, a3, a4);
   1.249 +		return schedule (time, ev);
   1.250 +	}
   1.251 +	template <typename T1, typename T2, typename T3, typename T4, typename T5>
   1.252 +	static EventId schedule (Time time, void (*f) (T1), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) {
   1.253 +		// five arg version
   1.254 +		class EventFunctionImpl5 : public EventImpl {
   1.255 +		public:
   1.256 +			typedef void (*F)(T1, T2, T3, T4, T5);
   1.257 +			
   1.258 +			EventFunctionImpl5 (F function, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) 
   1.259 +				: m_function (function),
   1.260 +				  m_a1 (a1),
   1.261 +				  m_a2 (a2),
   1.262 +				  m_a3 (a3),
   1.263 +				  m_a4 (a4),
   1.264 +				  m_a5 (a5)
   1.265 +			{ }
   1.266 +		protected:
   1.267 +			virtual ~EventFunctionImpl5 () {}
   1.268 +		private:
   1.269 +			virtual void notify (void) { 
   1.270 +				(*m_function) (m_a1, m_a2, m_a3, m_a4, m_a5);
   1.271 +			}
   1.272 +			F m_function;
   1.273 +			T1 m_a1;
   1.274 +			T2 m_a2;
   1.275 +			T3 m_a3;
   1.276 +			T4 m_a4;
   1.277 +			T5 m_a5;
   1.278 +		} *ev = new EventFunctionImpl5 (f, a1, a2, a3, a4, a5);
   1.279 +		return schedule (time, ev);
   1.280 +	}
   1.281  	/**
   1.282  	 * Unschedule the event. i.e.: the removed event never expires.
   1.283  	 * @param id the event to remove from the list of scheduled events.