| 
									
										
										
										
											2008-12-21 19:17:35 +00:00
										 |  |  | #ifndef FUNCTIONLIST_H
 | 
					
						
							|  |  |  | #define FUNCTIONLIST_H
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef _MSC_VER
 | 
					
						
							| 
									
										
										
										
											2008-08-15 12:11:42 +00:00
										 |  |  | #pragma  once
 | 
					
						
							| 
									
										
										
										
											2008-12-21 19:17:35 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-15 12:11:42 +00:00
										 |  |  | #include <boost/function.hpp>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-20 06:57:53 +00:00
										 |  |  | template<typename Signature> | 
					
						
							| 
									
										
										
										
											2008-08-15 12:11:42 +00:00
										 |  |  | class CFunctionList | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2008-08-20 06:57:53 +00:00
										 |  |  | 	std::vector<boost::function<Signature> > funcs; | 
					
						
							| 
									
										
										
										
											2008-08-15 12:11:42 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	CFunctionList(int){}; | 
					
						
							|  |  |  | 	CFunctionList(){}; | 
					
						
							| 
									
										
										
										
											2008-08-25 10:25:16 +00:00
										 |  |  | 	template <typename Functor>  | 
					
						
							|  |  |  | 	CFunctionList(const Functor &f) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		funcs.push_back(boost::function<Signature>(f)); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-08-20 06:57:53 +00:00
										 |  |  | 	CFunctionList(const boost::function<Signature> &first) | 
					
						
							| 
									
										
										
										
											2008-08-15 12:11:42 +00:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		funcs.push_back(first); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-08-22 12:21:09 +00:00
										 |  |  | 	CFunctionList(boost::function<Signature> &first) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		funcs.push_back(first); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-08-20 06:57:53 +00:00
										 |  |  | 	CFunctionList & operator+=(const boost::function<Signature> &first) | 
					
						
							| 
									
										
										
										
											2008-08-15 12:11:42 +00:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		funcs.push_back(first); | 
					
						
							|  |  |  | 		return *this; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-04-14 12:47:09 +00:00
										 |  |  | 	void add(const CFunctionList<Signature> &first) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		for (size_t i = 0; i < first.funcs.size(); i++) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			funcs.push_back(first.funcs[i]); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-08-28 17:36:34 +00:00
										 |  |  | 	void clear() | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		funcs.clear(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-08-15 12:11:42 +00:00
										 |  |  | 	operator bool() const | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return funcs.size(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	void operator()() const | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2008-08-20 06:57:53 +00:00
										 |  |  | 		std::vector<boost::function<Signature> > funcs2 = funcs; //backup
 | 
					
						
							| 
									
										
										
										
											2009-04-14 12:47:09 +00:00
										 |  |  | 		for(size_t i=0;i<funcs2.size(); ++i)  | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2008-08-15 12:11:42 +00:00
										 |  |  | 			funcs2[i](); | 
					
						
							| 
									
										
										
										
											2009-04-14 12:47:09 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2008-08-15 12:11:42 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-08-22 12:21:09 +00:00
										 |  |  | 	template <typename Arg>  | 
					
						
							|  |  |  | 	void operator()(const Arg & a) const | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		std::vector<boost::function<Signature> > funcs2 = funcs; //backup
 | 
					
						
							| 
									
										
										
										
											2009-04-14 12:47:09 +00:00
										 |  |  | 		for(int i=0;i<funcs2.size(); i++)  | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2008-08-22 12:21:09 +00:00
										 |  |  | 			funcs2[i](a); | 
					
						
							| 
									
										
										
										
											2009-04-14 12:47:09 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2008-08-22 12:21:09 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-09-24 08:15:49 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template<typename Signature> | 
					
						
							|  |  |  | class CFunctionList2 | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 	std::vector<boost::function<Signature> > funcs; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	CFunctionList2(int){}; | 
					
						
							|  |  |  | 	CFunctionList2(){}; | 
					
						
							|  |  |  | 	template <typename Functor>  | 
					
						
							|  |  |  | 	CFunctionList2(const Functor &f) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		funcs.push_back(boost::function<Signature>(f)); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	CFunctionList2(const boost::function<Signature> &first) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		funcs.push_back(first); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	CFunctionList2(boost::function<Signature> &first) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		funcs.push_back(first); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	CFunctionList2 & operator+=(const boost::function<Signature> &first) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		funcs.push_back(first); | 
					
						
							|  |  |  | 		return *this; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	void clear() | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		funcs.clear(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	operator bool() const | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return funcs.size(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	template <typename Arg>  | 
					
						
							|  |  |  | 	void operator()(const Arg & a) const | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		std::vector<boost::function<Signature> > funcs2 = funcs; //backup
 | 
					
						
							| 
									
										
										
										
											2009-04-14 12:47:09 +00:00
										 |  |  | 		for(size_t i=0;i<funcs2.size(); ++i)  | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2008-09-24 08:15:49 +00:00
										 |  |  | 			funcs2[i](a); | 
					
						
							| 
									
										
										
										
											2009-04-14 12:47:09 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2008-09-24 08:15:49 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-12-21 19:17:35 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif //FUNCTIONLISt_H
 |