Add classes ProtectedCall and Main

This commit is contained in:
Vinnie Falco
2013-07-28 13:42:19 -07:00
parent 217d3bb7a8
commit 7347477d42
22 changed files with 429 additions and 556 deletions

View File

@@ -70,7 +70,6 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\modules\beast_basics\beast_basics.h" />
<ClInclude Include="..\..\modules\beast_basics\diagnostic\beast_CatchAny.h" />
<ClInclude Include="..\..\modules\beast_basics\events\beast_DeadlineTimer.h" />
<ClInclude Include="..\..\modules\beast_basics\events\beast_OncePerSecond.h" />
<ClInclude Include="..\..\modules\beast_basics\functor\beast_Function.h" />
@@ -116,6 +115,7 @@
<ClInclude Include="..\..\modules\beast_core\containers\beast_Variant.h" />
<ClInclude Include="..\..\modules\beast_core\diagnostic\beast_Debug.h" />
<ClInclude Include="..\..\modules\beast_core\diagnostic\beast_Error.h" />
<ClInclude Include="..\..\modules\beast_core\diagnostic\beast_ProtectedCall.h" />
<ClInclude Include="..\..\modules\beast_core\diagnostic\beast_FPUFlags.h" />
<ClInclude Include="..\..\modules\beast_core\diagnostic\beast_LeakChecked.h" />
<ClInclude Include="..\..\modules\beast_core\diagnostic\beast_SafeBool.h" />
@@ -159,6 +159,7 @@
<ClInclude Include="..\..\modules\beast_core\memory\beast_StaticObject.h" />
<ClInclude Include="..\..\modules\beast_core\memory\beast_Uncopyable.h" />
<ClInclude Include="..\..\modules\beast_core\memory\beast_WeakReference.h" />
<ClInclude Include="..\..\modules\beast_core\misc\beast_Main.h" />
<ClInclude Include="..\..\modules\beast_core\misc\beast_Result.h" />
<ClInclude Include="..\..\modules\beast_core\misc\beast_Uuid.h" />
<ClInclude Include="..\..\modules\beast_core\misc\beast_WindowsRegistry.h" />
@@ -266,12 +267,6 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\modules\beast_basics\beast_basics.cpp" />
<ClCompile Include="..\..\modules\beast_basics\diagnostic\beast_CatchAny.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\modules\beast_basics\events\beast_DeadlineTimer.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
@@ -399,6 +394,12 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\modules\beast_core\diagnostic\beast_ProtectedCall.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\modules\beast_core\diagnostic\beast_FPUFlags.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
@@ -513,6 +514,12 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\modules\beast_core\misc\beast_Main.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\modules\beast_core\misc\beast_Result.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>

View File

@@ -92,9 +92,6 @@
<Filter Include="beast_basics">
<UniqueIdentifier>{e3a8f3eb-7f0f-4b81-b978-0dd0823f583b}</UniqueIdentifier>
</Filter>
<Filter Include="beast_basics\diagnostic">
<UniqueIdentifier>{ba11b980-76dd-49a4-b2c7-878e9f08f8ce}</UniqueIdentifier>
</Filter>
<Filter Include="beast_basics\events">
<UniqueIdentifier>{b8caa85d-f224-4e3a-966f-a19b65023869}</UniqueIdentifier>
</Filter>
@@ -482,9 +479,6 @@
<ClInclude Include="..\..\modules\beast_basics\beast_basics.h">
<Filter>beast_basics</Filter>
</ClInclude>
<ClInclude Include="..\..\modules\beast_basics\diagnostic\beast_CatchAny.h">
<Filter>beast_basics\diagnostic</Filter>
</ClInclude>
<ClInclude Include="..\..\modules\beast_basics\events\beast_OncePerSecond.h">
<Filter>beast_basics\events</Filter>
</ClInclude>
@@ -725,6 +719,12 @@
<ClInclude Include="..\..\modules\beast_core\maths\beast_MurmurHash.h">
<Filter>beast_core\maths</Filter>
</ClInclude>
<ClInclude Include="..\..\modules\beast_core\diagnostic\beast_ProtectedCall.h">
<Filter>beast_core\diagnostic</Filter>
</ClInclude>
<ClInclude Include="..\..\modules\beast_core\misc\beast_Main.h">
<Filter>beast_core\misc</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\modules\beast_core\beast_core.cpp">
@@ -976,9 +976,6 @@
<ClCompile Include="..\..\modules\beast_basics\beast_basics.cpp">
<Filter>beast_basics</Filter>
</ClCompile>
<ClCompile Include="..\..\modules\beast_basics\diagnostic\beast_CatchAny.cpp">
<Filter>beast_basics\diagnostic</Filter>
</ClCompile>
<ClCompile Include="..\..\modules\beast_basics\events\beast_OncePerSecond.cpp">
<Filter>beast_basics\events</Filter>
</ClCompile>
@@ -1126,6 +1123,12 @@
<ClCompile Include="..\..\modules\beast_core\maths\beast_MurmurHash.cpp">
<Filter>beast_core\maths</Filter>
</ClCompile>
<ClCompile Include="..\..\modules\beast_core\diagnostic\beast_ProtectedCall.cpp">
<Filter>beast_core\diagnostic</Filter>
</ClCompile>
<ClCompile Include="..\..\modules\beast_core\misc\beast_Main.cpp">
<Filter>beast_core\misc</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Text Include="..\..\TODO.txt" />

View File

@@ -2,6 +2,8 @@
BEAST TODO
--------------------------------------------------------------------------------
- Import secp256k1 from sipa
- HashMap work:
- Add unit test
- Return size_t from hash function, take out upperLimit, move mod % to caller

View File

@@ -40,8 +40,6 @@
namespace beast
{
#include "diagnostic/beast_CatchAny.cpp"
#include "events/beast_DeadlineTimer.cpp"
#include "events/beast_OncePerSecond.cpp"

View File

@@ -246,7 +246,6 @@ namespace beast
// Order matters
#include "functor/beast_Function.h"
#include "diagnostic/beast_CatchAny.h"
#include "events/beast_DeadlineTimer.h"
#include "events/beast_OncePerSecond.h"
#include "math/beast_Math.h"

View File

@@ -1,54 +0,0 @@
//------------------------------------------------------------------------------
/*
This file is part of Beast: https://github.com/vinniefalco/Beast
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef BEAST_CATCHANY_BEASTHEADER
#define BEAST_CATCHANY_BEASTHEADER
/**
Exception catcher.
Executes the function and catches any exception.
In addition to C++ exceptions, this will also catch
any platform-specific exceptions. For example, SEH
(Structured Exception Handling) on Windows, or POSIX
signals if they are available.
If returnFromException is false then a framework
specific unhandled exception handler will be called.
Otherwise, this function will return true if it
catches something or else false.
The return value approach is useful for detecting
when outside code fails (for example, a VST plugin),
and disabling its future use for example.
@todo Remove dependence on the JUCEApplication object and remove beast_gui_basics.h from beast_core.cpp
@param f The function to call.
@param returnFromException `false` if exceptions should terminate the app.
@return `true` if an exception was caught.
@ingroup beast_core
*/
extern bool CatchAny (Function <void (void)> f,
bool returnFromException = false);
#endif

View File

@@ -99,7 +99,7 @@
fifo.call (&Object::func4); // even static members can be called.
fifo.callf (bind (&Object::func2, // same as: object->func2 ()
fifo.callf (functional::bind (&Object::func2, // same as: object->func2 ()
object));
}
@@ -217,73 +217,55 @@ public:
#if BEAST_VARIADIC_MAX >= 1
template <class Fn>
void call (Fn f)
{
callf (bind (f));
}
{ callf (functional::bind (f)); }
#endif
#if BEAST_VARIADIC_MAX >= 2
template <class Fn, class T1>
void call (Fn f, T1 t1)
{
callf (bind (f, t1));
}
{ callf (functional::bind (f, t1)); }
#endif
#if BEAST_VARIADIC_MAX >= 3
template <class Fn, class T1, class T2>
void call (Fn f, T1 t1, T2 t2)
{
callf (bind (f, t1, t2));
}
{ callf (functional::bind (f, t1, t2)); }
#endif
#if BEAST_VARIADIC_MAX >= 4
template <class Fn, class T1, class T2, class T3>
void call (Fn f, T1 t1, T2 t2, T3 t3)
{
callf (bind (f, t1, t2, t3));
}
{ callf (functional::bind (f, t1, t2, t3)); }
#endif
#if BEAST_VARIADIC_MAX >= 5
template <class Fn, class T1, class T2, class T3, class T4>
void call (Fn f, T1 t1, T2 t2, T3 t3, T4 t4)
{
callf (bind (f, t1, t2, t3, t4));
}
{ callf (functional::bind (f, t1, t2, t3, t4)); }
#endif
#if BEAST_VARIADIC_MAX >= 6
template <class Fn, class T1, class T2, class T3, class T4, class T5>
void call (Fn f, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5)
{
callf (bind (f, t1, t2, t3, t4, t5));
}
{ callf (functional::bind (f, t1, t2, t3, t4, t5)); }
#endif
#if BEAST_VARIADIC_MAX >= 7
template <class Fn, class T1, class T2, class T3, class T4, class T5, class T6>
void call (Fn f, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6)
{
callf (bind (f, t1, t2, t3, t4, t5, t6));
}
{ callf (functional::bind (f, t1, t2, t3, t4, t5, t6)); }
#endif
#if BEAST_VARIADIC_MAX >= 8
template <class Fn, class T1, class T2, class T3, class T4, class T5, class T6, class T7>
void call (Fn f, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7)
{
callf (bind (f, t1, t2, t3, t4, t5, t6, t7));
}
{ callf (functional::bind (f, t1, t2, t3, t4, t5, t6, t7)); }
#endif
#if BEAST_VARIADIC_MAX >= 9
template <class Fn, class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8>
void call (Fn f, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8)
{
callf (bind (f, t1, t2, t3, t4, t5, t6, t7, t8));
}
{ callf (functional::bind (f, t1, t2, t3, t4, t5, t6, t7, t8)); }
#endif
/** @} */
@@ -349,73 +331,55 @@ public:
#if BEAST_VARIADIC_MAX >= 1
template <class Fn>
void queue (Fn f)
{
queuef (bind (f));
}
{ queuef (functional::bind (f)); }
#endif
#if BEAST_VARIADIC_MAX >= 2
template <class Fn, class T1>
void queue (Fn f, T1 t1)
{
queuef (bind (f, t1));
}
{ queuef (functional::bind (f, t1)); }
#endif
#if BEAST_VARIADIC_MAX >= 3
template <class Fn, class T1, class T2>
void queue (Fn f, T1 t1, T2 t2)
{
queuef (bind (f, t1, t2));
}
{ queuef (functional::bind (f, t1, t2)); }
#endif
#if BEAST_VARIADIC_MAX >= 4
template <class Fn, class T1, class T2, class T3>
void queue (Fn f, T1 t1, T2 t2, T3 t3)
{
queuef (bind (f, t1, t2, t3));
}
{ queuef (functional::bind (f, t1, t2, t3)); }
#endif
#if BEAST_VARIADIC_MAX >= 5
template <class Fn, class T1, class T2, class T3, class T4>
void queue (Fn f, T1 t1, T2 t2, T3 t3, T4 t4)
{
queuef (bind (f, t1, t2, t3, t4));
}
{ queuef (functional::bind (f, t1, t2, t3, t4)); }
#endif
#if BEAST_VARIADIC_MAX >= 6
template <class Fn, class T1, class T2, class T3, class T4, class T5>
void queue (Fn f, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5)
{
queuef (bind (f, t1, t2, t3, t4, t5));
}
{ queuef (functional::bind (f, t1, t2, t3, t4, t5)); }
#endif
#if BEAST_VARIADIC_MAX >= 7
template <class Fn, class T1, class T2, class T3, class T4, class T5, class T6>
void queue (Fn f, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6)
{
queuef (bind (f, t1, t2, t3, t4, t5, t6));
}
{ queuef (functional::bind (f, t1, t2, t3, t4, t5, t6)); }
#endif
#if BEAST_VARIADIC_MAX >= 8
template <class Fn, class T1, class T2, class T3, class T4, class T5, class T6, class T7>
void queue (Fn f, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7)
{
queuef (bind (f, t1, t2, t3, t4, t5, t6, t7));
}
{ queuef (functional::bind (f, t1, t2, t3, t4, t5, t6, t7)); }
#endif
#if BEAST_VARIADIC_MAX >= 9
template <class Fn, class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8>
void queue (Fn f, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8)
{
queuef (bind (f, t1, t2, t3, t4, t5, t6, t7, t8));
}
{ queuef (functional::bind (f, t1, t2, t3, t4, t5, t6, t7, t8)); }
#endif
/** @} */

View File

@@ -205,7 +205,6 @@ void InterruptibleThread::run ()
m_runEvent.wait ();
//CatchAny (m_function);
m_entryPoint->threadRun ();
}

View File

@@ -474,73 +474,55 @@ public:
#if BEAST_VARIADIC_MAX >= 1
template <class Mf>
inline void call (Mf mf)
{
callf (bind (mf, _1));
}
{ callf (functional::bind (mf, placeholders::_1)); }
#endif
#if BEAST_VARIADIC_MAX >= 2
template <class Mf, class T1>
void call (Mf mf, T1 t1)
{
callf (bind (mf, _1, t1));
}
{ callf (functional::bind (mf, placeholders::_1, t1)); }
#endif
#if BEAST_VARIADIC_MAX >= 3
template <class Mf, class T1, class T2>
void call (Mf mf, T1 t1, T2 t2)
{
callf (bind (mf, _1, t1, t2));
}
{ callf (functional::bind (mf, placeholders::_1, t1, t2)); }
#endif
#if BEAST_VARIADIC_MAX >= 4
template <class Mf, class T1, class T2, class T3>
void call (Mf mf, T1 t1, T2 t2, T3 t3)
{
callf (bind (mf, _1, t1, t2, t3));
}
{ callf (functional::bind (mf, placeholders::_1, t1, t2, t3)); }
#endif
#if BEAST_VARIADIC_MAX >= 5
template <class Mf, class T1, class T2, class T3, class T4>
void call (Mf mf, T1 t1, T2 t2, T3 t3, T4 t4)
{
callf (bind (mf, _1, t1, t2, t3, t4));
}
{ callf (functional::bind (mf, placeholders::_1, t1, t2, t3, t4)); }
#endif
#if BEAST_VARIADIC_MAX >= 6
template <class Mf, class T1, class T2, class T3, class T4, class T5>
void call (Mf mf, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5)
{
callf (bind (mf, _1, t1, t2, t3, t4, t5));
}
{ callf (functional::bind (mf, placeholders::_1, t1, t2, t3, t4, t5)); }
#endif
#if BEAST_VARIADIC_MAX >= 7
template <class Mf, class T1, class T2, class T3, class T4, class T5, class T6>
void call (Mf mf, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6)
{
callf (bind (mf, _1, t1, t2, t3, t4, t5, t6));
}
{ callf (functional::bind (mf, placeholders::_1, t1, t2, t3, t4, t5, t6)); }
#endif
#if BEAST_VARIADIC_MAX >= 8
template <class Mf, class T1, class T2, class T3, class T4, class T5, class T6, class T7>
void call (Mf mf, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7)
{
callf (bind (mf, _1, t1, t2, t3, t4, t5, t6, t7));
}
{ callf (functional::bind (mf, placeholders::_1, t1, t2, t3, t4, t5, t6, t7)); }
#endif
#if BEAST_VARIADIC_MAX >= 9
template <class Mf, class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8>
void call (Mf mf, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8)
{
callf (bind (mf, _1, t1, t2, t3, t4, t5, t6, t7, t8));
}
{ callf (functional::bind (mf, placeholders::_1, t1, t2, t3, t4, t5, t6, t7, t8)); }
#endif
/** @} */
@@ -556,73 +538,55 @@ public:
#if BEAST_VARIADIC_MAX >= 1
template <class Mf>
inline void queue (Mf mf)
{
queuef (bind (mf, _1));
}
{ queuef (functional::bind (mf, placeholders::_1)); }
#endif
#if BEAST_VARIADIC_MAX >= 2
template <class Mf, class T1>
void queue (Mf mf, T1 t1)
{
queuef (bind (mf, _1, t1));
}
{ queuef (functional::bind (mf, placeholders::_1, t1)); }
#endif
#if BEAST_VARIADIC_MAX >= 3
template <class Mf, class T1, class T2>
void queue (Mf mf, T1 t1, T2 t2)
{
queuef (bind (mf, _1, t1, t2));
}
{ queuef (functional::bind (mf, placeholders::_1, t1, t2)); }
#endif
#if BEAST_VARIADIC_MAX >= 4
template <class Mf, class T1, class T2, class T3>
void queue (Mf mf, T1 t1, T2 t2, T3 t3)
{
queuef (bind (mf, _1, t1, t2, t3));
}
{ queuef (functional::bind (mf, placeholders::_1, t1, t2, t3)); }
#endif
#if BEAST_VARIADIC_MAX >= 5
template <class Mf, class T1, class T2, class T3, class T4>
void queue (Mf mf, T1 t1, T2 t2, T3 t3, T4 t4)
{
queuef (bind (mf, _1, t1, t2, t3, t4));
}
{ queuef (functional::bind (mf, placeholders::_1, t1, t2, t3, t4)); }
#endif
#if BEAST_VARIADIC_MAX >= 6
template <class Mf, class T1, class T2, class T3, class T4, class T5>
void queue (Mf mf, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5)
{
queuef (bind (mf, _1, t1, t2, t3, t4, t5));
}
{ queuef (functional::bind (mf, placeholders::_1, t1, t2, t3, t4, t5)); }
#endif
#if BEAST_VARIADIC_MAX >= 7
template <class Mf, class T1, class T2, class T3, class T4, class T5, class T6>
void queue (Mf mf, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6)
{
queuef (bind (mf, _1, t1, t2, t3, t4, t5, t6));
}
{ queuef (functional::bind (mf, placeholders::_1, t1, t2, t3, t4, t5, t6)); }
#endif
#if BEAST_VARIADIC_MAX >= 8
template <class Mf, class T1, class T2, class T3, class T4, class T5, class T6, class T7>
void queue (Mf mf, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7)
{
queuef (bind (mf, _1, t1, t2, t3, t4, t5, t6, t7));
}
{ queuef (functional::bind (mf, placeholders::_1, t1, t2, t3, t4, t5, t6, t7)); }
#endif
#if BEAST_VARIADIC_MAX >= 9
template <class Mf, class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8>
void queue (Mf mf, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8)
{
queuef (bind (mf, _1, t1, t2, t3, t4, t5, t6, t7, t8));
}
{ queuef (functional::bind (mf, placeholders::_1, t1, t2, t3, t4, t5, t6, t7, t8)); }
#endif
/** @} */
@@ -644,73 +608,55 @@ public:
#if BEAST_VARIADIC_MAX >= 1
template <class Mf>
inline void update (Mf mf)
{
updatef (mf, bind (mf, _1));
}
{ updatef (mf, functional::bind (mf, placeholders::_1)); }
#endif
#if BEAST_VARIADIC_MAX >= 2
template <class Mf, class T1>
void update (Mf mf, T1 t1)
{
updatef (mf, bind (mf, _1, t1));
}
{ updatef (mf, functional::bind (mf, placeholders::_1, t1)); }
#endif
#if BEAST_VARIADIC_MAX >= 3
template <class Mf, class T1, class T2>
void update (Mf mf, T1 t1, T2 t2)
{
updatef (mf, bind (mf, _1, t1, t2));
}
{ updatef (mf, functional::bind (mf, placeholders::_1, t1, t2)); }
#endif
#if BEAST_VARIADIC_MAX >= 4
template <class Mf, class T1, class T2, class T3>
void update (Mf mf, T1 t1, T2 t2, T3 t3)
{
updatef (mf, bind (mf, _1, t1, t2, t3));
}
{ updatef (mf, functional::bind (mf, placeholders::_1, t1, t2, t3)); }
#endif
#if BEAST_VARIADIC_MAX >= 5
template <class Mf, class T1, class T2, class T3, class T4>
void update (Mf mf, T1 t1, T2 t2, T3 t3, T4 t4)
{
updatef (mf, bind (mf, _1, t1, t2, t3, t4));
}
{ updatef (mf, functional::bind (mf, placeholders::_1, t1, t2, t3, t4)); }
#endif
#if BEAST_VARIADIC_MAX >= 6
template <class Mf, class T1, class T2, class T3, class T4, class T5>
void update (Mf mf, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5)
{
updatef (mf, bind (mf, _1, t1, t2, t3, t4, t5));
}
{ updatef (mf, functional::bind (mf, placeholders::_1, t1, t2, t3, t4, t5)); }
#endif
#if BEAST_VARIADIC_MAX >= 7
template <class Mf, class T1, class T2, class T3, class T4, class T5, class T6>
void update (Mf mf, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6)
{
updatef (mf, bind (mf, _1, t1, t2, t3, t4, t5, t6));
}
{ updatef (mf, functional::bind (mf, placeholders::_1, t1, t2, t3, t4, t5, t6)); }
#endif
#if BEAST_VARIADIC_MAX >= 8
template <class Mf, class T1, class T2, class T3, class T4, class T5, class T6, class T7>
void update (Mf mf, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7)
{
updatef (mf, bind (mf, _1, t1, t2, t3, t4, t5, t6, t7));
}
{ updatef (mf, functional::bind (mf, placeholders::_1, t1, t2, t3, t4, t5, t6, t7)); }
#endif
#if BEAST_VARIADIC_MAX >= 9
template <class Mf, class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8>
void update (Mf mf, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8)
{
updatef (mf, bind (mf, _1, t1, t2, t3, t4, t5, t6, t7, t8));
}
{ updatef (mf, functional::bind (mf, placeholders::_1, t1, t2, t3, t4, t5, t6, t7, t8)); }
#endif
/** @} */
@@ -729,73 +675,55 @@ public:
#if BEAST_VARIADIC_MAX >= 1
template <class Mf>
inline void call1 (ListenerClass* const listener, Mf mf)
{
call1f (listener, bind (mf, _1));
}
{ call1f (listener, functional::bind (mf, placeholders::_1)); }
#endif
#if BEAST_VARIADIC_MAX >= 2
template <class Mf, class T1>
void call1 (ListenerClass* const listener, Mf mf, T1 t1)
{
call1f (listener, bind (mf, _1, t1));
}
{ call1f (listener, functional::bind (mf, placeholders::_1, t1)); }
#endif
#if BEAST_VARIADIC_MAX >= 3
template <class Mf, class T1, class T2>
void call1 (ListenerClass* const listener, Mf mf, T1 t1, T2 t2)
{
call1f (listener, bind (mf, _1, t1, t2));
}
{ call1f (listener, functional::bind (mf, placeholders::_1, t1, t2)); }
#endif
#if BEAST_VARIADIC_MAX >= 4
template <class Mf, class T1, class T2, class T3>
void call1 (ListenerClass* const listener, Mf mf, T1 t1, T2 t2, T3 t3)
{
call1f (listener, bind (mf, _1, t1, t2, t3));
}
{ call1f (listener, functional::bind (mf, placeholders::_1, t1, t2, t3)); }
#endif
#if BEAST_VARIADIC_MAX >= 5
template <class Mf, class T1, class T2, class T3, class T4>
void call1 (ListenerClass* const listener, Mf mf, T1 t1, T2 t2, T3 t3, T4 t4)
{
call1f (listener, bind (mf, _1, t1, t2, t3, t4));
}
{ call1f (listener, functional::bind (mf, placeholders::_1, t1, t2, t3, t4)); }
#endif
#if BEAST_VARIADIC_MAX >= 6
template <class Mf, class T1, class T2, class T3, class T4, class T5>
void call1 (ListenerClass* const listener, Mf mf, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5)
{
call1f (listener, bind (mf, _1, t1, t2, t3, t4, t5));
}
{ call1f (listener, functional::bind (mf, placeholders::_1, t1, t2, t3, t4, t5)); }
#endif
#if BEAST_VARIADIC_MAX >= 7
template <class Mf, class T1, class T2, class T3, class T4, class T5, class T6>
void call1 (ListenerClass* const listener, Mf mf, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6)
{
call1f (listener, bind (mf, _1, t1, t2, t3, t4, t5, t6));
}
{ call1f (listener, functional::bind (mf, placeholders::_1, t1, t2, t3, t4, t5, t6)); }
#endif
#if BEAST_VARIADIC_MAX >= 8
template <class Mf, class T1, class T2, class T3, class T4, class T5, class T6, class T7>
void call1 (ListenerClass* const listener, Mf mf, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7)
{
call1f (listener, bind (mf, _1, t1, t2, t3, t4, t5, t6, t7));
}
{ call1f (listener, functional::bind (mf, placeholders::_1, t1, t2, t3, t4, t5, t6, t7)); }
#endif
#if BEAST_VARIADIC_MAX >= 9
template <class Mf, class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8>
void call1 (ListenerClass* const listener, Mf mf, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8)
{
call1f (listener, bind (mf, _1, t1, t2, t3, t4, t5, t6, t7, t8));
}
{ call1f (listener, functional::bind (mf, placeholders::_1, t1, t2, t3, t4, t5, t6, t7, t8)); }
#endif
/** @} */
@@ -812,73 +740,55 @@ public:
#if BEAST_VARIADIC_MAX >= 1
template <class Mf>
inline void queue1 (ListenerClass* const listener, Mf mf)
{
queue1f (listener, bind (mf, _1));
}
{ queue1f (listener, functional::bind (mf, placeholders::_1)); }
#endif
#if BEAST_VARIADIC_MAX >= 2
template <class Mf, class T1>
void queue1 (ListenerClass* const listener, Mf mf, T1 t1)
{
queue1f (listener, bind (mf, _1, t1));
}
{ queue1f (listener, functional::bind (mf, placeholders::_1, t1)); }
#endif
#if BEAST_VARIADIC_MAX >= 3
template <class Mf, class T1, class T2>
void queue1 (ListenerClass* const listener, Mf mf, T1 t1, T2 t2)
{
queue1f (listener, bind (mf, _1, t1, t2));
}
{ queue1f (listener, functional::bind (mf, placeholders::_1, t1, t2)); }
#endif
#if BEAST_VARIADIC_MAX >= 4
template <class Mf, class T1, class T2, class T3>
void queue1 (ListenerClass* const listener, Mf mf, T1 t1, T2 t2, T3 t3)
{
queue1f (listener, bind (mf, _1, t1, t2, t3));
}
{ queue1f (listener, functional::bind (mf, placeholders::_1, t1, t2, t3)); }
#endif
#if BEAST_VARIADIC_MAX >= 5
template <class Mf, class T1, class T2, class T3, class T4>
void queue1 (ListenerClass* const listener, Mf mf, T1 t1, T2 t2, T3 t3, T4 t4)
{
queue1f (listener, bind (mf, _1, t1, t2, t3, t4));
}
{ queue1f (listener, functional::bind (mf, placeholders::_1, t1, t2, t3, t4)); }
#endif
#if BEAST_VARIADIC_MAX >= 6
template <class Mf, class T1, class T2, class T3, class T4, class T5>
void queue1 (ListenerClass* const listener, Mf mf, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5)
{
queue1f (listener, bind (mf, _1, t1, t2, t3, t4, t5));
}
{ queue1f (listener, functional::bind (mf, placeholders::_1, t1, t2, t3, t4, t5)); }
#endif
#if BEAST_VARIADIC_MAX >= 7
template <class Mf, class T1, class T2, class T3, class T4, class T5, class T6>
void queue1 (ListenerClass* const listener, Mf mf, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6)
{
queue1f (listener, bind (mf, _1, t1, t2, t3, t4, t5, t6));
}
{ queue1f (listener, functional::bind (mf, placeholders::_1, t1, t2, t3, t4, t5, t6)); }
#endif
#if BEAST_VARIADIC_MAX >= 8
template <class Mf, class T1, class T2, class T3, class T4, class T5, class T6, class T7>
void queue1 (ListenerClass* const listener, Mf mf, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7)
{
queue1f (listener, bind (mf, _1, t1, t2, t3, t4, t5, t6, t7));
}
{ queue1f (listener, functional::bind (mf, placeholders::_1, t1, t2, t3, t4, t5, t6, t7)); }
#endif
#if BEAST_VARIADIC_MAX >= 9
template <class Mf, class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8>
void queue1 (ListenerClass* const listener, Mf mf, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8)
{
queue1f (listener, bind (mf, _1, t1, t2, t3, t4, t5, t6, t7, t8));
}
{ queue1f (listener, functional::bind (mf, placeholders::_1, t1, t2, t3, t4, t5, t6, t7, t8)); }
#endif
/** @} */
};

View File

@@ -97,73 +97,55 @@ public:
#if BEAST_VARIADIC_MAX >= 1
template <class Fn>
void loop (int n, Fn f)
{
loopf (n, bind (f, _1));
}
{ loopf (n, functional::bind (f, placeholders::_1)); }
#endif
#if BEAST_VARIADIC_MAX >= 2
template <class Fn, class T1>
void loop (int n, Fn f, T1 t1)
{
loopf (n, bind (f, t1, _1));
}
{ loopf (n, functional::bind (f, t1, placeholders::_1)); }
#endif
#if BEAST_VARIADIC_MAX >= 3
template <class Fn, class T1, class T2>
void loop (int n, Fn f, T1 t1, T2 t2)
{
loopf (n, bind (f, t1, t2, _1));
}
{ loopf (n, functional::bind (f, t1, t2, placeholders::_1)); }
#endif
#if BEAST_VARIADIC_MAX >= 4
template <class Fn, class T1, class T2, class T3>
void loop (int n, Fn f, T1 t1, T2 t2, T3 t3)
{
loopf (n, bind (f, t1, t2, t3, _1));
}
{ loopf (n, functional::bind (f, t1, t2, t3, placeholders::_1)); }
#endif
#if BEAST_VARIADIC_MAX >= 5
template <class Fn, class T1, class T2, class T3, class T4>
void loop (int n, Fn f, T1 t1, T2 t2, T3 t3, T4 t4)
{
loopf (n, bind (f, t1, t2, t3, t4, _1));
}
{ loopf (n, functional::bind (f, t1, t2, t3, t4, placeholders::_1)); }
#endif
#if BEAST_VARIADIC_MAX >= 6
template <class Fn, class T1, class T2, class T3, class T4, class T5>
void loop (int n, Fn f, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5)
{
loopf (n, bind (f, t1, t2, t3, t4, t5, _1));
}
{ loopf (n, functional::bind (f, t1, t2, t3, t4, t5, placeholders::_1)); }
#endif
#if BEAST_VARIADIC_MAX >= 7
template <class Fn, class T1, class T2, class T3, class T4, class T5, class T6>
void loop (int n, Fn f, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6)
{
loopf (n, bind (f, t1, t2, t3, t4, t5, t6, _1));
}
{ loopf (n, functional::bind (f, t1, t2, t3, t4, t5, t6, placeholders::_1)); }
#endif
#if BEAST_VARIADIC_MAX >= 8
template <class Fn, class T1, class T2, class T3, class T4, class T5, class T6, class T7>
void loop (int n, Fn f, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7)
{
loopf (n, bind (f, t1, t2, t3, t4, t5, t6, t7, _1));
}
{ loopf (n, functional::bind (f, t1, t2, t3, t4, t5, t6, t7, placeholders::_1)); }
#endif
#if BEAST_VARIADIC_MAX >= 9
template <class Fn, class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8>
void loop (int n, Fn f, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8)
{
loopf (n, bind (f, t1, t2, t3, t4, t5, t6, t7, t8, _1));
}
{ loopf (n, functional::bind (f, t1, t2, t3, t4, t5, t6, t7, t8, placeholders::_1)); }
#endif
/** @} */
@@ -272,220 +254,4 @@ private:
int m_numberOfIterations;
};
//------------------------------------------------------------------------------
class ParallelFor2 : Uncopyable
{
public:
/** Create a parallel for loop.
It is best to keep this object around instead of creating and destroying
it every time you need to run a loop.
@param pool The ThreadGroup to use. If this is omitted then a singleton
ThreadGroup is used which contains one thread per CPU.
*/
explicit ParallelFor2 (ThreadGroup& pool = *GlobalThreadGroup::getInstance ())
: m_pool (pool)
, m_finishedEvent (false) // auto-reset
{
}
/** Determine the number of threads in the group.
@return The number of threads in the group.
*/
int getNumberOfThreads () const
{
return m_pool.getNumberOfThreads ();
}
template <class F, class T1, class T2, class T3, class T4>
void operator () (int numberOfIterations, T1 t1, T2 t2, T3 t3, T4 t4)
{
Factory4 <F, T1, T2, T3, T4> f (t1, t2, t3, t4);
doLoop (numberOfIterations, f);
}
private:
typedef ThreadGroup::AllocatorType AllocatorType;
//---
struct Iterator : public AllocatedBy <AllocatorType>
{
virtual ~Iterator () { }
virtual void operator () (int loopIndex) = 0;
};
//---
template <class Functor>
struct IteratorType : public Iterator, Uncopyable
{
explicit IteratorType (Functor f) : m_f (f)
{
}
void operator () (int loopIndex)
{
m_f (loopIndex);
}
private:
Functor m_f;
};
//---
struct Factory
{
virtual ~Factory () { }
virtual Iterator* operator () (AllocatorType& allocator) = 0;
};
template <class F, class T1, class T2, class T3, class T4>
struct Factory4 : Factory
{
Factory4 (T1 t1, T2 t2, T3 t3, T4 t4)
: m_t1 (t1), m_t2 (t2), m_t3 (t3), m_t4 (t4) { }
Iterator* operator () (AllocatorType& allocator)
{
return new (allocator) IteratorType <F> (m_t1, m_t2, m_t3, m_t4);
}
private:
T1 m_t1;
T2 m_t2;
T3 m_t3;
T4 m_t4;
};
private:
class LoopState
: public AllocatedBy <AllocatorType>
, Uncopyable
{
private:
Factory& m_factory;
WaitableEvent& m_finishedEvent;
int const m_numberOfIterations;
Atomic <int> m_loopIndex;
Atomic <int> m_iterationsRemaining;
Atomic <int> m_numberOfParallelInstances;
AllocatorType& m_allocator;
public:
LoopState (Factory& factory,
WaitableEvent& finishedEvent,
int numberOfIterations,
int numberOfParallelInstances,
AllocatorType& allocator)
: m_factory (factory)
, m_finishedEvent (finishedEvent)
, m_numberOfIterations (numberOfIterations)
, m_loopIndex (-1)
, m_iterationsRemaining (numberOfIterations)
, m_numberOfParallelInstances (numberOfParallelInstances)
, m_allocator (allocator)
{
}
~LoopState ()
{
}
void forLoopBody ()
{
Iterator* iterator = m_factory (m_allocator);
for (;;)
{
// Request a loop index to process.
int const loopIndex = ++m_loopIndex;
// Is it in range?
if (loopIndex < m_numberOfIterations)
{
// Yes, so process it.
(*iterator) (loopIndex);
// Was this the last work item to complete?
if (--m_iterationsRemaining == 0)
{
// Yes, signal.
m_finishedEvent.signal ();
break;
}
}
else
{
// Out of range, all work is complete or assigned.
break;
}
}
release ();
delete iterator;
}
void release ()
{
if (--m_numberOfParallelInstances == 0)
delete this;
}
};
private:
void doLoop (int numberOfIterations, Factory& factory)
{
if (numberOfIterations > 1)
{
int const numberOfThreads = m_pool.getNumberOfThreads ();
// The largest number of pool threads we need is one less than the number
// of iterations, because we also run the loop body on the caller's thread.
//
int const maxThreads = numberOfIterations - 1;
// Calculate the number of parallel instances as the smaller of the number
// of threads available (including the caller's) and the number of iterations.
//
int const numberOfParallelInstances = std::min (
numberOfThreads + 1, numberOfIterations);
LoopState* loopState (new (m_pool.getAllocator ()) LoopState (
factory,
m_finishedEvent,
numberOfIterations,
numberOfParallelInstances,
m_pool.getAllocator ()));
m_pool.call (maxThreads, &LoopState::forLoopBody, loopState);
// Also use the caller's thread to run the loop body.
loopState->forLoopBody ();
m_finishedEvent.wait ();
}
else if (numberOfIterations == 1)
{
// Just one iteration, so do it.
Iterator* iter = factory (m_pool.getAllocator ());
(*iter) (0);
delete iter;
}
}
private:
ThreadGroup& m_pool;
WaitableEvent m_finishedEvent;
Atomic <int> m_currentIndex;
Atomic <int> m_numberOfInstances;
int m_numberOfIterations;
};
#endif

View File

@@ -86,73 +86,55 @@ public:
#if BEAST_VARIADIC_MAX >= 1
template <class Fn>
void call (int maxThreads, Fn f)
{
callf (maxThreads, bind (f));
}
{ callf (maxThreads, functional::bind (f)); }
#endif
#if BEAST_VARIADIC_MAX >= 2
template <class Fn, class T1>
void call (int maxThreads, Fn f, T1 t1)
{
callf (maxThreads, bind (f, t1));
}
{ callf (maxThreads, functional::bind (f, t1)); }
#endif
#if BEAST_VARIADIC_MAX >= 3
template <class Fn, class T1, class T2>
void call (int maxThreads, Fn f, T1 t1, T2 t2)
{
callf (maxThreads, bind (f, t1, t2));
}
{ callf (maxThreads, functional::bind (f, t1, t2)); }
#endif
#if BEAST_VARIADIC_MAX >= 4
template <class Fn, class T1, class T2, class T3>
void call (int maxThreads, Fn f, T1 t1, T2 t2, T3 t3)
{
callf (maxThreads, bind (f, t1, t2, t3));
}
{ callf (maxThreads, functional::bind (f, t1, t2, t3)); }
#endif
#if BEAST_VARIADIC_MAX >= 5
template <class Fn, class T1, class T2, class T3, class T4>
void call (int maxThreads, Fn f, T1 t1, T2 t2, T3 t3, T4 t4)
{
callf (maxThreads, bind (f, t1, t2, t3, t4));
}
{ callf (maxThreads, functional::bind (f, t1, t2, t3, t4)); }
#endif
#if BEAST_VARIADIC_MAX >= 6
template <class Fn, class T1, class T2, class T3, class T4, class T5>
void call (int maxThreads, Fn f, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5)
{
callf (maxThreads, bind (f, t1, t2, t3, t4, t5));
}
{ callf (maxThreads, functional::bind (f, t1, t2, t3, t4, t5)); }
#endif
#if BEAST_VARIADIC_MAX >= 7
template <class Fn, class T1, class T2, class T3, class T4, class T5, class T6>
void call (int maxThreads, Fn f, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6)
{
callf (maxThreads, bind (f, t1, t2, t3, t4, t5, t6));
}
{ callf (maxThreads, functional::bind (f, t1, t2, t3, t4, t5, t6)); }
#endif
#if BEAST_VARIADIC_MAX >= 8
template <class Fn, class T1, class T2, class T3, class T4, class T5, class T6, class T7>
void call (int maxThreads, Fn f, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7)
{
callf (maxThreads, bind (f, t1, t2, t3, t4, t5, t6, t7));
}
{ callf (maxThreads, functional::bind (f, t1, t2, t3, t4, t5, t6, t7)); }
#endif
#if BEAST_VARIADIC_MAX >= 9
template <class Fn, class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8>
void call (int maxThreads, Fn f, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8)
{
callf (maxThreads, bind (f, t1, t2, t3, t4, t5, t6, t7, t8));
}
{ callf (maxThreads, functional::bind (f, t1, t2, t3, t4, t5, t6, t7, t8)); }
#endif
/** @} */

View File

@@ -148,6 +148,7 @@ namespace beast
#include "diagnostic/beast_Error.cpp"
#include "diagnostic/beast_FPUFlags.cpp"
#include "diagnostic/beast_LeakChecked.cpp"
#include "diagnostic/beast_ProtectedCall.cpp"
#include "diagnostic/beast_UnitTest.cpp"
#include "diagnostic/beast_UnitTestUtilities.cpp"
@@ -171,6 +172,7 @@ namespace beast
#include "memory/beast_MemoryBlock.cpp"
#include "misc/beast_Main.cpp"
#include "misc/beast_Result.cpp"
#include "misc/beast_Uuid.cpp"

View File

@@ -194,10 +194,12 @@ namespace beast
// Order matters, since headers don't have their own #include lines.
// Add new includes to the bottom.
#include "memory/beast_Uncopyable.h"
#include "system/beast_PlatformDefs.h"
#include "system/beast_TargetPlatform.h"
#include "system/beast_Functional.h"
#include "memory/beast_Uncopyable.h"
#include "maths/beast_MathsFunctions.h"
#include "memory/beast_Atomic.h"
#include "memory/beast_AtomicCounter.h"
@@ -226,6 +228,7 @@ namespace beast
#include "diagnostic/beast_Error.h"
#include "diagnostic/beast_FPUFlags.h"
#include "diagnostic/beast_Throw.h"
#include "diagnostic/beast_ProtectedCall.h"
#include "containers/beast_AbstractFifo.h"
#include "containers/beast_Array.h"
#include "containers/beast_ArrayAllocationBase.h"
@@ -276,6 +279,7 @@ namespace beast
#include "memory/beast_MemoryAlignment.h"
#include "memory/beast_CacheLine.h"
#include "memory/beast_RecycledObjectPool.h"
#include "misc/beast_Main.h"
#include "misc/beast_Result.h"
#include "misc/beast_Uuid.h"
#include "misc/beast_WindowsRegistry.h"
@@ -292,7 +296,7 @@ namespace beast
#include "streams/beast_MemoryOutputStream.h"
#include "streams/beast_OutputStream.h"
#include "streams/beast_SubregionStream.h"
#include "system/beast_Functional.h"
#include "system/beast_SystemStats.h"
#include "text/beast_Identifier.h"
#include "text/beast_LocalisedStrings.h"

View File

@@ -205,11 +205,11 @@ END_BEAST_NAMESPACE
//------------------------------------------------------------------------------
#if 0
bool CatchAny (Function <void (void)> f, bool returnFromException)
{
bool caughtException = true; // assume the worst
#if 0
try
{
//ScopedPlatformExceptionCatcher platformExceptionCatcher;
@@ -271,6 +271,41 @@ bool CatchAny (Function <void (void)> f, bool returnFromException)
}
}
}
#endif
return caughtException;
}
#endif
//------------------------------------------------------------------------------
void ProtectedCall::DefaultHandler::onException (ProtectedCall::Exception const& e) const
{
}
Static::Storage <Atomic <ProtectedCall::Handler const*>, ProtectedCall>
ProtectedCall::s_handler;
void ProtectedCall::setHandler (Handler const& handler)
{
s_handler->set (&handler);
}
void ProtectedCall::call (Call& call)
{
static DefaultHandler const defaultHandler;
Handler const* handler = s_handler->get ();
if (handler == nullptr)
handler = &defaultHandler;
try
{
call ();
}
catch (...)
{
Exception e;
handler->onException (e);
}
}

View File

@@ -0,0 +1,163 @@
//------------------------------------------------------------------------------
/*
This file is part of Beast: https://github.com/vinniefalco/Beast
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef BEAST_P_H_INCLUDED
#define BEAST_PROTECTEDCALL_H_INCLUDED
/** Call a function in a protected exception context.
This is for intercepting unhandled exceptions, reporting on the extended
information provided by @ref Throw, and calling a customizable unhandled
exception callback. Some implementations will also catch native exceptions
such as memory violations or segmentation faults.
An unhandled exception should terminate the process with a non zero
return code.
To use this, construct an instance with your funtion and arguments as
parameters. For example:
@code
extern void funcThatMightThrow (int numberOfTimes);
ProtectedCall (&funcThatMightThrow, 3);
@endcode
*/
class ProtectedCall
{
public:
struct Exception
{
};
/** This receives the unhandled exception. */
struct Handler
{
/** Called when an uhandled exception is thrown.
@note This can be called from multiple threads, which is
why it is const.
*/
virtual void onException (Exception const& e) const = 0;
};
/** The default handler writes to std::cerr makes the process exit. */
class DefaultHandler : public Handler
{
void onException (Exception const& e) const;
};
static void setHandler (Handler const& handler);
public:
#if BEAST_VARIADIC_MAX >= 1
template <class Fn>
explicit ProtectedCall (Fn f)
{ callf (functional::bind (f)); }
#endif
#if BEAST_VARIADIC_MAX >= 2
template <class Fn, class T1>
ProtectedCall (Fn f, T1 t1)
{ callf (functional::bind (f, t1)); }
#endif
#if BEAST_VARIADIC_MAX >= 3
template <class Fn, class T1, class T2>
ProtectedCall (Fn f, T1 t1, T2 t2)
{ callf (functional::bind (f, t1, t2)); }
#endif
#if BEAST_VARIADIC_MAX >= 4
template <class Fn, class T1, class T2, class T3>
ProtectedCall (Fn f, T1 t1, T2 t2, T3 t3)
{ callf (functional::bind (f, t1, t2, t3)); }
#endif
#if BEAST_VARIADIC_MAX >= 5
template <class Fn, class T1, class T2, class T3, class T4>
ProtectedCall (Fn f, T1 t1, T2 t2, T3 t3, T4 t4)
{ callf (functional::bind (f, t1, t2, t3, t4)); }
#endif
#if BEAST_VARIADIC_MAX >= 6
template <class Fn, class T1, class T2, class T3, class T4, class T5>
ProtectedCall (Fn f, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5)
{ callf (functional::bind (f, t1, t2, t3, t4, t5)); }
#endif
#if BEAST_VARIADIC_MAX >= 7
template <class Fn, class T1, class T2, class T3, class T4, class T5, class T6>
ProtectedCall (Fn f, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6)
{ callf (functional::bind (f, t1, t2, t3, t4, t5, t6)); }
#endif
#if BEAST_VARIADIC_MAX >= 8
template <class Fn, class T1, class T2, class T3, class T4, class T5, class T6, class T7>
ProtectedCall (Fn f, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7)
{ callf (functional::bind (f, t1, t2, t3, t4, t5, t6, t7)); }
#endif
#if BEAST_VARIADIC_MAX >= 9
template <class Fn, class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8>
ProtectedCall (Fn f, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8)
{ callf (functional::bind (f, t1, t2, t3, t4, t5, t6, t7, t8)); }
#endif
private:
struct Call
{
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);
call (wrapper);
}
void call (Call& call);
private:
static Static::Storage <Atomic <Handler const*>, ProtectedCall> s_handler;
};
#endif

View File

@@ -21,8 +21,8 @@
*/
//==============================================================================
#ifndef BEAST_UNITTEST_BEASTHEADER
#define BEAST_UNITTEST_BEASTHEADER
#ifndef BEAST_UNITTEST_H_INCLUDED
#define BEAST_UNITTEST_H_INCLUDED
class UnitTests;
@@ -32,17 +32,6 @@ class UnitTests;
@code
FIX THE EXAMPLE FOR THE NEW API!
class MyTest : public UnitTest
{
public:

View File

@@ -17,8 +17,8 @@
*/
//==============================================================================
#ifndef BEAST_UNCOPYABLE_BEASTHEADER
#define BEAST_UNCOPYABLE_BEASTHEADER
#ifndef BEAST_UNCOPYABLE_H_INCLUDED
#define BEAST_UNCOPYABLE_H_INCLUDED
/** Prevent copy construction and assignment.

View File

@@ -0,0 +1,24 @@
//------------------------------------------------------------------------------
/*
This file is part of Beast: https://github.com/vinniefalco/Beast
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
Main::Main (int argc, char const* const* argv)
: m_argc (argc)
, m_argv (argv)
{
}

View File

@@ -0,0 +1,40 @@
//------------------------------------------------------------------------------
/*
This file is part of Beast: https://github.com/vinniefalco/Beast
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef BEAST_MAIN_H_INCLUDED
#define BEAST_MAIN_H_INCLUDED
/** Represents a command line program's entry point.
*/
class BEAST_API Main : Uncopyable
{
public:
Main (int argc, char const* const* argv);
int getExitCode () const;
static Main& getInstance ();
protected:
int const m_argc;
char const* const* const m_argv;
};
#endif

View File

@@ -55,11 +55,21 @@
#if BEAST_BIND_USES_STD
namespace functional
{
using std::ref;
using std::cref;
using std::bind;
using std::function;
}
using namespace functional;
namespace placeholders
{
#if BEAST_BIND_PLACEHOLDERS_N >= 1
using std::placeholders::_1;
#endif
@@ -140,15 +150,29 @@ using std::placeholders::_19;
using std::placeholders::_20;
#endif
}
using namespace placeholders;
//------------------------------------------------------------------------------
#elif BEAST_BIND_USES_TR1
namespace functional
{
using std::tr1::ref;
using std::tr1::cref;
using std::tr1::bind;
using std::tr1::function;
}
using namespace functional;
namespace placeholders
{
#if BEAST_BIND_PLACEHOLDERS_N >= 1
using std::tr1::placeholders::_1;
#endif
@@ -229,15 +253,29 @@ using std::tr1::placeholders::_19;
using std::tr1::placeholders::_20;
#endif
}
using namespace placeholders;
//------------------------------------------------------------------------------
#elif BEAST_BIND_USES_BOOST
namespace functional
{
using boost::ref;
using boost::cref;
using boost::bind;
using boost::function;
}
using namespace functional;
namespace placeholders
{
#if BEAST_BIND_PLACEHOLDERS_N >= 1
using boost::placeholders::_1;
#endif
@@ -318,6 +356,10 @@ using boost::placeholders::_19;
using boost::placeholders::_20;
#endif
}
using namespace placeholders;
//------------------------------------------------------------------------------
#else

View File

@@ -24,8 +24,6 @@
#ifndef BEAST_SYSTEMSTATS_BEASTHEADER
#define BEAST_SYSTEMSTATS_BEASTHEADER
#include "../text/beast_StringArray.h"
//==============================================================================
/**
Contains methods for finding out about the current hardware and OS configuration.

View File

@@ -98,7 +98,7 @@ void Thread::threadEntryPoint()
// used to wrap the incoming call from the platform-specific code
void BEAST_API beast_threadEntryPoint (void* userData)
{
static_cast <Thread*> (userData)->threadEntryPoint();
ProtectedCall (&Thread::threadEntryPoint, static_cast <Thread*> (userData));
}
//==============================================================================