00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef SAMPA_CALL_H
00020 #define SAMPA_CALL_H
00021
00022 #include "sampa/core/object.h"
00023
00024 #if SAMPA_CONFIG_TRACE_CALLS == SAMPA_DISABLED
00025
00026 # define SAMPA_IMPLEMENT_INTERFACE
00027
00028 namespace Sampa {
00029
00036 template<class Interface>
00037 class CallObserver : public Object {
00038 public:
00039 CallObserver(const Name& name)
00040 : Object(name), m_interface(0) {}
00041 void bind_target(Interface* interface) { m_interface = interface; }
00043 Interface* operator->() { return m_interface; }
00044 private:
00045 Interface* m_interface;
00046 SAMPA_PERSISTENT(CallObserver);
00048 };
00049 }
00050
00051 #else
00052
00053 namespace Sampa {
00054
00056 class Object;
00057
00058 class CallBase {
00059 public:
00060 CallBase(Object* from, Object* to);
00061 CallBase();
00062 ~CallBase();
00063 inline static void implement_interface(const char* function_name)
00064 {
00065 if (M_current_call) {
00066 M_current_call->m_function_name = function_name;
00067 M_current_call = 0;
00068 }
00069 }
00070 private:
00071 bool m_trace;
00072 const char* m_function_name;
00073 unsigned m_call_id;
00074 static CallBase* M_current_call;
00075 static unsigned M_num_call;
00076 };
00077
00078 template<class Interface>
00079 class Call : public CallBase {
00080 public:
00081 Call(Interface* interface, Object* from, Object* to)
00082 : CallBase(from, to), m_interface(interface) { }
00083 Call(Interface* interface)
00084 : m_interface(interface) { }
00085 Interface* operator->() { return m_interface; }
00086 private:
00087 Interface* m_interface;
00088 };
00090
00097 template<class Interface>
00098 class CallObserver : public Object {
00099 public:
00100 CallObserver(const Name& name)
00101 : Object(name), m_interface(0), m_target(0) {}
00102 void bind_target(Interface* interface) { m_interface = interface; m_target = dynamic_cast<Interface>(interface); }
00104 Call<Interface> operator->() { return Call<Interface>(m_interface, this, m_target); }
00105 private:
00106 Interface* m_interface;
00107 Object* m_target;
00108 SAMPA_PERSISTENT(CallObserver);
00110 };
00111 }
00112
00113 #ifdef __GNUC__
00114 # define SAMPA_IMPLEMENT_INTERFACE Sampa::CallBase::implement_interface(__PRETTY_FUNCTION__)
00115 #else
00116 # define SAMPA_IMPLEMENT_INTERFACE Sampa::CallBase::implement_interface(__func__)
00117 #endif
00118
00119 #endif
00120
00121 #endif