00001 /* 00002 This class provides basic signals and slots support. 00003 00004 Copyright (C) 2010 - 2014 Christoph Haenisch 00005 00006 Chair of Medical Engineering (mediTEC) 00007 RWTH Aachen University 00008 Pauwelsstr. 20 00009 52074 Aachen 00010 Germany 00011 00012 See license.txt for more information. 00013 00014 Version 1.2.2 (2014-07-03) 00015 */ 00016 00023 #include "TRTK/Signals.hpp" 00024 00025 00026 using namespace std; 00027 00028 00029 namespace TRTK 00030 { 00031 00032 00033 namespace Signals 00034 { 00035 00036 00038 // SlotBase and Slot // 00040 00041 00042 SlotBase::SlotBase() 00043 { 00044 for (unsigned i = 0; i < sizeof(function_address); ++i) 00045 { 00046 function_address[i] = 0; 00047 } 00048 } 00049 00050 00051 bool operator==(const SlotBase & x, const SlotBase & y) 00052 { 00053 if (x.getObject() == NULL && y.getObject() == NULL) 00054 { 00055 // global function 00056 00057 const char * function_address_x = x.getGlobalFunction(); 00058 const char * function_address_y = y.getGlobalFunction(); 00059 00060 bool is_equal = true; 00061 00062 for (int i = 0; i < SlotBase::MAX_FUNCTION_POINTER_SIZE; ++i) 00063 { 00064 is_equal = is_equal && (function_address_x[i] == function_address_y[i]); 00065 } 00066 00067 return is_equal; 00068 } 00069 else if (x.getObject() == y.getObject()) // We checked 'x.getObject() != NULL' above. 00070 { 00071 // class function 00072 00073 const char * function_address_x = x.getClassFunction(); 00074 const char * function_address_y = y.getClassFunction(); 00075 00076 bool is_equal = true; 00077 00078 for (int i = 0; i < SlotBase::MAX_FUNCTION_POINTER_SIZE; ++i) 00079 { 00080 is_equal = is_equal && (function_address_x[i] == function_address_y[i]); 00081 } 00082 00083 return is_equal; 00084 } 00085 else 00086 { 00087 return false; 00088 } 00089 } 00090 00091 00093 // Receiver // 00095 00096 00097 Receiver::Receiver() 00098 { 00099 }; 00100 00101 00102 // Informs all signals, which are connected to a class derived from Receiver, 00103 // from its destruction. 00104 00105 Receiver::~Receiver() 00106 { 00107 // Automatically disconnect all signals. 00108 00109 list<pair<const SignalBase *, SlotAdapterBase *> >::iterator it; 00110 00111 for (it = m_connected_signals.begin(); it != m_connected_signals.end(); ++it) 00112 { 00113 const SignalBase * signal = (*it).first; 00114 SlotAdapterBase * slot = (*it).second; 00115 signal->disconnectReceiver(slot); 00116 } 00117 }; 00118 00119 00120 // If a signal is connected to a class derived from Receiver, it calls this function. 00121 00122 void Receiver::notifyConnection(const SignalBase * signal, SlotAdapterBase * slot) const 00123 { 00124 m_connected_signals.push_back(make_pair(signal, slot)); 00125 } 00126 00127 00128 // If a signal connected to a class derived from Receiver is destroyed or entirely 00129 // disconnected, it calls this function. 00130 00131 void Receiver::notifyDisconnection(const SignalBase * signal) const 00132 { 00133 // Delete all entries that refer to 'signal'. 00134 00135 list<pair<const SignalBase *, SlotAdapterBase *> >::iterator it = m_connected_signals.begin(); 00136 00137 while (it != m_connected_signals.end()) 00138 { 00139 if (signal == (*it).first) 00140 { 00141 it = m_connected_signals.erase(it); 00142 } 00143 else 00144 { 00145 ++it; 00146 } 00147 } 00148 } 00149 00150 00151 } // namespace Signals 00152 00153 00154 } // namespace TRTK
Documentation generated by Doxygen