From 27307fca0cd27098547c430bdaa9850038d981ad Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Tue, 10 Sep 2013 08:04:54 -0700 Subject: [PATCH] Use SharedFunction in ProtectedCall --- modules/beast_core/beast_core.h | 6 +- .../diagnostic/beast_ProtectedCall.h | 34 +++-------- .../beast_core/functional/SharedFunction.h | 58 ++++++++++--------- 3 files changed, 41 insertions(+), 57 deletions(-) diff --git a/modules/beast_core/beast_core.h b/modules/beast_core/beast_core.h index a6bc27deae..a265ca56eb 100644 --- a/modules/beast_core/beast_core.h +++ b/modules/beast_core/beast_core.h @@ -308,11 +308,12 @@ extern BEAST_API void BEAST_CALLTYPE logAssertion (char const* file, int line) n #include "maths/beast_uint24.h" #include "logging/beast_Logger.h" #include "diagnostic/beast_FPUFlags.h" +#include "memory/SharedObject.h" +#include "memory/SharedPtr.h" +#include "functional/SharedFunction.h" #include "diagnostic/beast_ProtectedCall.h" #include "containers/beast_AbstractFifo.h" #include "containers/beast_ArrayAllocationBase.h" -#include "memory/SharedObject.h" -#include "memory/SharedPtr.h" #include "containers/beast_DynamicObject.h" #include "containers/beast_ElementComparator.h" #include "maths/beast_Random.h" @@ -408,7 +409,6 @@ extern BEAST_API void BEAST_CALLTYPE logAssertion (char const* file, int line) n #include "diagnostic/MeasureFunctionCallTime.h" #include "functional/beast_Function.h" -#include "functional/SharedFunction.h" #include "thread/beast_DeadlineTimer.h" diff --git a/modules/beast_core/diagnostic/beast_ProtectedCall.h b/modules/beast_core/diagnostic/beast_ProtectedCall.h index d6013c0112..8d5533633d 100644 --- a/modules/beast_core/diagnostic/beast_ProtectedCall.h +++ b/modules/beast_core/diagnostic/beast_ProtectedCall.h @@ -125,33 +125,15 @@ public: #endif private: - struct Call + typedef SharedFunction FunctionType; + typedef FunctionType::Call Call; + + template + void callf (Function f) { - virtual void operator() () = 0; - }; - - template - struct CallType : public Call - { - public: - explicit CallType (Functor f) - : m_f (f) - { - } - - void operator() () - { - m_f (); - } - - private: - Functor m_f; - }; - - template - void callf (Functor f) - { - CallType wrapper (f); + //CallType wrapper (f); + FunctionType::CallType wrapper ( + BEAST_MOVE_CAST(Function)(f)); call (wrapper); } diff --git a/modules/beast_core/functional/SharedFunction.h b/modules/beast_core/functional/SharedFunction.h index fcb31e5d91..9f2b416139 100644 --- a/modules/beast_core/functional/SharedFunction.h +++ b/modules/beast_core/functional/SharedFunction.h @@ -31,6 +31,36 @@ template class SharedFunction { public: + class Call : public SharedObject + { + public: + virtual R operator() () = 0; + }; + + template + class CallType : public Call + { + public: + typedef typename A:: template rebind >::other Allocator; + + CallType (BEAST_MOVE_ARG(F) f, A a = A ()) + : m_f (BEAST_MOVE_CAST(F)(f)) + , m_a (a) + { + } + + R operator() () + { + return m_f (); + } + + private: + F m_f; + Allocator m_a; + }; + + //-------------------------------------------------------------------------- + template SharedFunction (F f, A a = A ()) : m_ptr (::new ( @@ -62,34 +92,6 @@ public: } private: - class Call : public SharedObject - { - public: - virtual R operator() () = 0; - }; - - template - class CallType : public Call - { - public: - typedef typename A:: template rebind >::other Allocator; - - CallType (BEAST_MOVE_ARG(F) f, A const& a) - : m_f (BEAST_MOVE_CAST(F)(f)) - , m_a (a) - { - } - - R operator() () - { - return m_f (); - } - - private: - F m_f; - Allocator m_a; - }; - SharedPtr m_ptr; };