00001
00002 #ifndef header_signal_v0
00003 #define header_signal_v0
00004
00005 #ifdef WIN32
00006 #pragma warning ( disable : 4786 )
00007 #endif
00008
00009 #include "slot_v0.h"
00010 #include <list>
00011
00012 class CL_Signal_v0
00013 {
00014 public:
00015 typedef CL_Slot_v0 *Slot;
00016 typedef std::list<Slot>::iterator SlotIterator;
00017
00018
00019 public:
00020 CL_Signal_v0()
00021 {
00022 }
00023
00024 ~CL_Signal_v0()
00025 {
00026 for (SlotIterator slot_it = slots.begin(); slot_it != slots.end(); slot_it++)
00027 {
00028 Slot slot = *slot_it;
00029 slot->release_ref();
00030 }
00031 }
00032
00033
00034 public:
00035 void operator() ()
00036 {
00037 call();
00038 }
00039
00040 void call()
00041 {
00042 std::list<SlotIterator> remove_slots;
00043
00044
00045 for (SlotIterator slot_it = slots.begin(); slot_it != slots.end(); slot_it++)
00046 {
00047 Slot slot = *slot_it;
00048
00049
00050
00051 if (slot->get_ref() == 1)
00052 {
00053 remove_slots.push_back(slot_it);
00054 continue;
00055 }
00056
00057 slot->call();
00058 }
00059
00060
00061 std::list<SlotIterator>::iterator remove_it;
00062 for (remove_it = remove_slots.begin(); remove_it != remove_slots.end(); remove_it++)
00063 {
00064 Slot slot = **remove_it;
00065 slot->release_ref();
00066 slots.erase(*remove_it);
00067 }
00068 }
00069
00070 CL_Slot connect(Slot slot)
00071 {
00072 slot->add_ref();
00073 slots.push_back(slot);
00074 return CL_Slot(slot);
00075 }
00076
00077 void disconnect(CL_Slot &disconnect_slot)
00078 {
00079 for (SlotIterator slot_it = slots.begin(); slot_it != slots.end();)
00080 {
00081 Slot slot = *slot_it;
00082 if (disconnect_slot.impl == slot)
00083 {
00084 slot->release_ref();
00085 slot_it = slots.erase(slot_it);
00086 }
00087 else
00088 slot_it++;
00089 }
00090 }
00091
00092
00093 private:
00094 std::list<Slot> slots;
00095 };
00096
00097 #endif