Use SharedFunction in ProtectedCall

This commit is contained in:
Vinnie Falco
2013-09-10 08:04:54 -07:00
parent 8b1b6050e7
commit 27307fca0c
3 changed files with 41 additions and 57 deletions

View File

@@ -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"

View File

@@ -125,33 +125,15 @@ public:
#endif
private:
struct Call
typedef SharedFunction <void (void)> FunctionType;
typedef FunctionType::Call Call;
template <class Function>
void callf (Function f)
{
virtual void operator() () = 0;
};
template <class Functor>
struct CallType : public Call
{
public:
explicit CallType (Functor f)
: m_f (f)
{
}
void operator() ()
{
m_f ();
}
private:
Functor m_f;
};
template <class Functor>
void callf (Functor f)
{
CallType <Functor> wrapper (f);
//CallType <Functor> wrapper (f);
FunctionType::CallType <Function> wrapper (
BEAST_MOVE_CAST(Function)(f));
call (wrapper);
}

View File

@@ -31,6 +31,36 @@ template <typename R, class A>
class SharedFunction <R (void), A>
{
public:
class Call : public SharedObject
{
public:
virtual R operator() () = 0;
};
template <typename F>
class CallType : public Call
{
public:
typedef typename A:: template rebind <CallType <F> >::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 <typename F>
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 <typename F>
class CallType : public Call
{
public:
typedef typename A:: template rebind <CallType <F> >::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 <Call> m_ptr;
};