+template <class Obj, class MemFun, class P1, class P2, class P3>
+class wxObjScopeGuardImpl3 : public wxScopeGuardImplBase
+{
+public:
+ static wxObjScopeGuardImpl3<Obj, MemFun, P1, P2, P3>
+ MakeObjGuard(Obj& obj, MemFun memFun, P1 p1, P2 p2, P3 p3)
+ {
+ return wxObjScopeGuardImpl3<Obj, MemFun, P1, P2, P3>(obj, memFun, p1, p2, p3);
+ }
+
+ ~wxObjScopeGuardImpl3() { wxPrivateOnScopeExit(*this); }
+
+ void Execute() { (m_obj.*m_memfun)(m_p1, m_p2, m_p3); }
+
+protected:
+ wxObjScopeGuardImpl3(Obj& obj, MemFun memFun, P1 p1, P2 p2, P3 p3)
+ : m_obj(obj), m_memfun(memFun), m_p1(p1), m_p2(p2), m_p3(p3) { }
+
+ Obj& m_obj;
+ MemFun m_memfun;
+ const P1 m_p1;
+ const P2 m_p2;
+ const P3 m_p3;
+};
+
+template <class Obj, class MemFun, class P1, class P2, class P3>
+inline wxObjScopeGuardImpl3<Obj, MemFun, P1, P2, P3>
+wxMakeObjGuard(Obj& obj, MemFun memFun, P1 p1, P2 p2, P3 p3)
+{
+ return wxObjScopeGuardImpl3<Obj, MemFun, P1, P2, P3>::
+ MakeObjGuard(obj, memFun, p1, p2, p3);
+}
+
+// ----------------------------------------------------------------------------
+// wxVariableSetter: use the same technique as for wxScopeGuard to allow
+// setting a variable to some value on block exit
+// ----------------------------------------------------------------------------
+
+#ifdef wxHAS_NAMESPACES
+
+namespace wxPrivate
+{
+
+// empty class just to be able to define a reference to it
+class VariableSetterBase { };
+
+typedef const VariableSetterBase& VariableSetter;
+
+template <typename T, typename U>
+class VariableSetterImpl : public VariableSetterBase
+{
+public:
+ VariableSetterImpl(T& var, U value)
+ : m_var(var),
+ m_value(value)
+ {
+ }
+
+ ~VariableSetterImpl()
+ {
+ m_var = m_value;
+ }
+
+private:
+ T& m_var;
+ const U m_value;
+
+ // suppress the warning about assignment operator not being generated
+ VariableSetterImpl<T, U>& operator=(const VariableSetterImpl<T, U>&);
+};
+
+template <typename T>
+class VariableNullerImpl : public VariableSetterBase
+{
+public:
+ VariableNullerImpl(T& var)
+ : m_var(var)
+ {
+ }
+
+ ~VariableNullerImpl()
+ {
+ m_var = NULL;
+ }
+
+private:
+ T& m_var;
+
+ VariableNullerImpl<T>& operator=(const VariableNullerImpl<T>&);
+};
+
+} // namespace wxPrivate
+
+template <typename T, typename U>
+inline
+wxPrivate::VariableSetterImpl<T, U> wxMakeVarSetter(T& var, U value)
+{
+ return wxPrivate::VariableSetterImpl<T, U>(var, value);
+}
+
+// calling wxMakeVarSetter(ptr, NULL) doesn't work because U is deduced to be
+// "int" and subsequent assignment of "U" to "T *" fails, so provide a special
+// function for this special case
+template <typename T>
+inline
+wxPrivate::VariableNullerImpl<T> wxMakeVarNuller(T& var)
+{
+ return wxPrivate::VariableNullerImpl<T>(var);
+}
+
+#endif // wxHAS_NAMESPACES
+