1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #ifndef DEBUGGER_CALLBACK_H
35 #define DEBUGGER_CALLBACK_H
37 #include "symbianutils_global.h"
42 /* Helper class for the 1-argument functor:
43 * Cloneable base class for the implementation which is
44 * invokeable with the argument. */
45 template <class Argument>
46 class CallbackImplBase
48 Q_DISABLE_COPY(CallbackImplBase)
51 virtual CallbackImplBase *clone() const = 0;
52 virtual void invoke(Argument a) = 0;
53 virtual ~CallbackImplBase() {}
56 /* Helper class for the 1-argument functor: Implementation for
57 * a class instance with a member function pointer. */
58 template <class Class, class Argument>
59 class CallbackMemberPtrImpl : public CallbackImplBase<Argument>
62 typedef void (Class::*MemberFuncPtr)(Argument);
64 CallbackMemberPtrImpl(Class *instance,
65 MemberFuncPtr memberFunc) :
67 m_memberFunc(memberFunc) {}
69 virtual CallbackImplBase<Argument> *clone() const
71 return new CallbackMemberPtrImpl<Class, Argument>(m_instance, m_memberFunc);
74 virtual void invoke(Argument a)
75 { (m_instance->*m_memberFunc)(a); }
78 MemberFuncPtr m_memberFunc;
81 } // namespace Internal
83 /* Default-constructible, copyable 1-argument functor providing an
84 * operator()(Argument) that invokes a member function of a class:
88 void print(const std::string &);
92 Callback<const std::string &> f1(&foo, &Foo::print);
96 template <class Argument>
100 Callback() : m_impl(0) {}
102 template <class Class>
103 Callback(Class *instance, void (Class::*memberFunc)(Argument)) :
104 m_impl(new Internal::CallbackMemberPtrImpl<Class,Argument>(instance, memberFunc))
112 Callback(const Callback &rhs) :
116 m_impl = rhs.m_impl->clone();
119 Callback &operator=(const Callback &rhs)
124 m_impl = rhs.m_impl->clone();
129 bool isNull() const { return m_impl == 0; }
130 operator bool() const { return !isNull(); }
132 void operator()(Argument a)
147 Internal::CallbackImplBase<Argument> *m_impl;
152 #endif // DEBUGGER_CALLBACK_H