WvStreams
|
00001 /* -*- Mode: C++ -*- 00002 * Worldvisions Weaver Software: 00003 * Copyright (C) 1997-2002 Net Integration Technologies, Inc. 00004 * 00005 */ 00006 #ifndef __WVCALLBACKLIST_H 00007 #define __WVCALLBACKLIST_H 00008 00009 #include <assert.h> 00010 #include <map> 00011 00012 00013 template<class InnerCallback> 00014 class WvCallbackList 00015 { 00016 private: 00017 std::map<void*, InnerCallback> list; 00018 00019 /* The idea of copying this gives me a headache. */ 00020 WvCallbackList(const WvCallbackList &); 00021 WvCallbackList& operator=(const WvCallbackList&); 00022 00023 public: 00024 WvCallbackList() 00025 { 00026 } 00027 void add(const InnerCallback &cb, void *cookie) 00028 { 00029 assert(list.find(cookie) == list.end()); 00030 list.insert(std::make_pair(cookie, cb)); 00031 } 00032 void del(void *cookie) 00033 { 00034 typename std::map<void*, InnerCallback>::iterator it = 00035 list.find(cookie); 00036 assert(it != list.end()); 00037 list.erase(it); 00038 } 00039 bool isempty() const 00040 { 00041 return list.empty(); 00042 } 00043 void operator()() const 00044 { 00045 typename std::map<void*, InnerCallback>::const_iterator it; 00046 00047 for (it = list.begin(); it != list.end(); ++it) 00048 it->second(); 00049 } 00050 template<typename P1> 00051 void operator()(P1 &p1) const 00052 { 00053 typename std::map<void*, InnerCallback>::const_iterator it; 00054 00055 for (it = list.begin(); it != list.end(); ++it) 00056 it->second(p1); 00057 } 00058 template<typename P1, 00059 typename P2> 00060 void operator()(P1 &p1, P2 &p2) const 00061 { 00062 typename std::map<void*, InnerCallback>::const_iterator it; 00063 00064 for (it = list.begin(); it != list.end(); ++it) 00065 it->second(p1, p2); 00066 } 00067 template<typename P1, 00068 typename P2, 00069 typename P3> 00070 void operator()(P1 &p1, P2 &p2, P3 &p3) const 00071 { 00072 typename std::map<void*, InnerCallback>::const_iterator it; 00073 00074 for (it = list.begin(); it != list.end(); ++it) 00075 it->second(p1, p2, p3); 00076 } 00077 template<typename P1, 00078 typename P2, 00079 typename P3, 00080 typename P4> 00081 void operator()(P1 &p1, P2 &p2, P3 &p3, P4 &p4) const 00082 { 00083 typename std::map<void*, InnerCallback>::const_iterator it; 00084 00085 for (it = list.begin(); it != list.end(); ++it) 00086 it->second(p1, p2, p3, p4); 00087 } 00088 template<typename P1, 00089 typename P2, 00090 typename P3, 00091 typename P4, 00092 typename P5> 00093 void operator()(P1 &p1, P2 &p2, P3 &p3, P4 &p4, P5 &p5) const 00094 { 00095 typename std::map<void*, InnerCallback>::const_iterator it; 00096 00097 for (it = list.begin(); it != list.end(); ++it) 00098 it->second(p1, p2, p3, p4, p5); 00099 } 00100 template<typename P1, 00101 typename P2, 00102 typename P3, 00103 typename P4, 00104 typename P5, 00105 typename P6> 00106 void operator()(P1 &p1, P2 &p2, P3 &p3, P4 &p4, P5 &p5, P6 &p6) const 00107 { 00108 typename std::map<void*, InnerCallback>::const_iterator it; 00109 00110 for (it = list.begin(); it != list.end(); ++it) 00111 it->second(p1, p2, p3, p4, p5, p6); 00112 } 00113 template<typename P1, 00114 typename P2, 00115 typename P3, 00116 typename P4, 00117 typename P5, 00118 typename P6, 00119 typename P7> 00120 void operator()(P1 &p1, P2 &p2, P3 &p3, P4 &p4, P5 &p5, P6 &p6, 00121 P7 &p7) const 00122 { 00123 typename std::map<void*, InnerCallback>::const_iterator it; 00124 00125 for (it = list.begin(); it != list.end(); ++it) 00126 it->second(p1, p2, p3, p4, p5, p6, p7); 00127 } 00128 template<typename P1, 00129 typename P2, 00130 typename P3, 00131 typename P4, 00132 typename P5, 00133 typename P6, 00134 typename P7, 00135 typename P8> 00136 void operator()(P1 &p1, P2 &p2, P3 &p3, P4 &p4, P5 &p5, P6 &p6, P7 &p7, 00137 P8 &p8) const 00138 { 00139 typename std::map<void*, InnerCallback>::const_iterator it; 00140 00141 for (it = list.begin(); it != list.end(); ++it) 00142 it->second(p1, p2, p3, p4, p5, p6, p7, p8); 00143 } 00144 }; 00145 00146 00147 #endif /* __WVCALLBACKLIST_H */