From 7347477d4211180508e18e3cc3991ec15a2e53e1 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Sun, 28 Jul 2013 13:42:19 -0700 Subject: [PATCH] Add classes ProtectedCall and Main --- .../Builds/VisualStudio2012/beast.vcxproj | 21 +- .../VisualStudio2012/beast.vcxproj.filters | 21 +- Subtrees/beast/TODO.txt | 2 + .../modules/beast_basics/beast_basics.cpp | 2 - .../beast/modules/beast_basics/beast_basics.h | 1 - .../beast_basics/diagnostic/beast_CatchAny.h | 54 ---- .../beast_basics/threads/beast_CallQueue.h | 74 ++--- .../threads/beast_InterruptibleThread.cpp | 1 - .../beast_basics/threads/beast_Listeners.h | 180 ++++--------- .../beast_basics/threads/beast_ParallelFor.h | 252 +----------------- .../beast_basics/threads/beast_ThreadGroup.h | 36 +-- .../beast/modules/beast_core/beast_core.cpp | 2 + .../beast/modules/beast_core/beast_core.h | 8 +- .../diagnostic/beast_ProtectedCall.cpp} | 39 ++- .../diagnostic/beast_ProtectedCall.h | 163 +++++++++++ .../beast_core/diagnostic/beast_UnitTest.h | 15 +- .../beast_core/memory/beast_Uncopyable.h | 4 +- .../modules/beast_core/misc/beast_Main.cpp | 24 ++ .../modules/beast_core/misc/beast_Main.h | 40 +++ .../beast_core/system/beast_Functional.h | 42 +++ .../beast_core/system/beast_SystemStats.h | 2 - .../beast_core/threads/beast_Thread.cpp | 2 +- 22 files changed, 429 insertions(+), 556 deletions(-) delete mode 100644 Subtrees/beast/modules/beast_basics/diagnostic/beast_CatchAny.h rename Subtrees/beast/modules/{beast_basics/diagnostic/beast_CatchAny.cpp => beast_core/diagnostic/beast_ProtectedCall.cpp} (91%) create mode 100644 Subtrees/beast/modules/beast_core/diagnostic/beast_ProtectedCall.h create mode 100644 Subtrees/beast/modules/beast_core/misc/beast_Main.cpp create mode 100644 Subtrees/beast/modules/beast_core/misc/beast_Main.h diff --git a/Subtrees/beast/Builds/VisualStudio2012/beast.vcxproj b/Subtrees/beast/Builds/VisualStudio2012/beast.vcxproj index e73a037013..b19179f453 100644 --- a/Subtrees/beast/Builds/VisualStudio2012/beast.vcxproj +++ b/Subtrees/beast/Builds/VisualStudio2012/beast.vcxproj @@ -70,7 +70,6 @@ - @@ -116,6 +115,7 @@ + @@ -159,6 +159,7 @@ + @@ -266,12 +267,6 @@ - - true - true - true - true - true true @@ -399,6 +394,12 @@ true true + + true + true + true + true + true true @@ -513,6 +514,12 @@ true true + + true + true + true + true + true true diff --git a/Subtrees/beast/Builds/VisualStudio2012/beast.vcxproj.filters b/Subtrees/beast/Builds/VisualStudio2012/beast.vcxproj.filters index 3dd924c13a..11104f9c88 100644 --- a/Subtrees/beast/Builds/VisualStudio2012/beast.vcxproj.filters +++ b/Subtrees/beast/Builds/VisualStudio2012/beast.vcxproj.filters @@ -92,9 +92,6 @@ {e3a8f3eb-7f0f-4b81-b978-0dd0823f583b} - - {ba11b980-76dd-49a4-b2c7-878e9f08f8ce} - {b8caa85d-f224-4e3a-966f-a19b65023869} @@ -482,9 +479,6 @@ beast_basics - - beast_basics\diagnostic - beast_basics\events @@ -725,6 +719,12 @@ beast_core\maths + + beast_core\diagnostic + + + beast_core\misc + @@ -976,9 +976,6 @@ beast_basics - - beast_basics\diagnostic - beast_basics\events @@ -1126,6 +1123,12 @@ beast_core\maths + + beast_core\diagnostic + + + beast_core\misc + diff --git a/Subtrees/beast/TODO.txt b/Subtrees/beast/TODO.txt index 4c553c80e4..144a2bcc23 100644 --- a/Subtrees/beast/TODO.txt +++ b/Subtrees/beast/TODO.txt @@ -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 diff --git a/Subtrees/beast/modules/beast_basics/beast_basics.cpp b/Subtrees/beast/modules/beast_basics/beast_basics.cpp index aa1a8f8b52..37eeb256cf 100644 --- a/Subtrees/beast/modules/beast_basics/beast_basics.cpp +++ b/Subtrees/beast/modules/beast_basics/beast_basics.cpp @@ -40,8 +40,6 @@ namespace beast { -#include "diagnostic/beast_CatchAny.cpp" - #include "events/beast_DeadlineTimer.cpp" #include "events/beast_OncePerSecond.cpp" diff --git a/Subtrees/beast/modules/beast_basics/beast_basics.h b/Subtrees/beast/modules/beast_basics/beast_basics.h index 78f59c2f69..782bfa387c 100644 --- a/Subtrees/beast/modules/beast_basics/beast_basics.h +++ b/Subtrees/beast/modules/beast_basics/beast_basics.h @@ -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" diff --git a/Subtrees/beast/modules/beast_basics/diagnostic/beast_CatchAny.h b/Subtrees/beast/modules/beast_basics/diagnostic/beast_CatchAny.h deleted file mode 100644 index 22df5ca2fc..0000000000 --- a/Subtrees/beast/modules/beast_basics/diagnostic/beast_CatchAny.h +++ /dev/null @@ -1,54 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of Beast: https://github.com/vinniefalco/Beast - Copyright 2013, Vinnie Falco - - 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 f, - bool returnFromException = false); - -#endif diff --git a/Subtrees/beast/modules/beast_basics/threads/beast_CallQueue.h b/Subtrees/beast/modules/beast_basics/threads/beast_CallQueue.h index a40cb6a2b1..26fa5b8c93 100644 --- a/Subtrees/beast/modules/beast_basics/threads/beast_CallQueue.h +++ b/Subtrees/beast/modules/beast_basics/threads/beast_CallQueue.h @@ -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 void call (Fn f) - { - callf (bind (f)); - } + { callf (functional::bind (f)); } #endif #if BEAST_VARIADIC_MAX >= 2 template void call (Fn f, T1 t1) - { - callf (bind (f, t1)); - } + { callf (functional::bind (f, t1)); } #endif #if BEAST_VARIADIC_MAX >= 3 template 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 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 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 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 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 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 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 void queue (Fn f) - { - queuef (bind (f)); - } + { queuef (functional::bind (f)); } #endif #if BEAST_VARIADIC_MAX >= 2 template void queue (Fn f, T1 t1) - { - queuef (bind (f, t1)); - } + { queuef (functional::bind (f, t1)); } #endif #if BEAST_VARIADIC_MAX >= 3 template 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 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 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 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 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 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 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 /** @} */ diff --git a/Subtrees/beast/modules/beast_basics/threads/beast_InterruptibleThread.cpp b/Subtrees/beast/modules/beast_basics/threads/beast_InterruptibleThread.cpp index ed74edc43e..1e7fb08aee 100644 --- a/Subtrees/beast/modules/beast_basics/threads/beast_InterruptibleThread.cpp +++ b/Subtrees/beast/modules/beast_basics/threads/beast_InterruptibleThread.cpp @@ -205,7 +205,6 @@ void InterruptibleThread::run () m_runEvent.wait (); - //CatchAny (m_function); m_entryPoint->threadRun (); } diff --git a/Subtrees/beast/modules/beast_basics/threads/beast_Listeners.h b/Subtrees/beast/modules/beast_basics/threads/beast_Listeners.h index b22220775b..1b8997df72 100644 --- a/Subtrees/beast/modules/beast_basics/threads/beast_Listeners.h +++ b/Subtrees/beast/modules/beast_basics/threads/beast_Listeners.h @@ -474,73 +474,55 @@ public: #if BEAST_VARIADIC_MAX >= 1 template inline void call (Mf mf) - { - callf (bind (mf, _1)); - } + { callf (functional::bind (mf, placeholders::_1)); } #endif #if BEAST_VARIADIC_MAX >= 2 template 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 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 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 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 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 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 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 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 inline void queue (Mf mf) - { - queuef (bind (mf, _1)); - } + { queuef (functional::bind (mf, placeholders::_1)); } #endif #if BEAST_VARIADIC_MAX >= 2 template 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 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 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 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 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 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 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 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 inline void update (Mf mf) - { - updatef (mf, bind (mf, _1)); - } + { updatef (mf, functional::bind (mf, placeholders::_1)); } #endif #if BEAST_VARIADIC_MAX >= 2 template 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 /** @} */ }; diff --git a/Subtrees/beast/modules/beast_basics/threads/beast_ParallelFor.h b/Subtrees/beast/modules/beast_basics/threads/beast_ParallelFor.h index 93e8dbf8d8..e2e56fdb7b 100644 --- a/Subtrees/beast/modules/beast_basics/threads/beast_ParallelFor.h +++ b/Subtrees/beast/modules/beast_basics/threads/beast_ParallelFor.h @@ -97,73 +97,55 @@ public: #if BEAST_VARIADIC_MAX >= 1 template 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 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 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 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 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 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 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 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 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 - void operator () (int numberOfIterations, T1 t1, T2 t2, T3 t3, T4 t4) - { - Factory4 f (t1, t2, t3, t4); - doLoop (numberOfIterations, f); - } - -private: - typedef ThreadGroup::AllocatorType AllocatorType; - - //--- - - struct Iterator : public AllocatedBy - { - virtual ~Iterator () { } - virtual void operator () (int loopIndex) = 0; - }; - - //--- - - template - 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 - 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 (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 - , Uncopyable - { - private: - Factory& m_factory; - WaitableEvent& m_finishedEvent; - int const m_numberOfIterations; - Atomic m_loopIndex; - Atomic m_iterationsRemaining; - Atomic 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 m_currentIndex; - Atomic m_numberOfInstances; - int m_numberOfIterations; -}; - #endif diff --git a/Subtrees/beast/modules/beast_basics/threads/beast_ThreadGroup.h b/Subtrees/beast/modules/beast_basics/threads/beast_ThreadGroup.h index 50720e2dc5..58795b7f97 100644 --- a/Subtrees/beast/modules/beast_basics/threads/beast_ThreadGroup.h +++ b/Subtrees/beast/modules/beast_basics/threads/beast_ThreadGroup.h @@ -86,73 +86,55 @@ public: #if BEAST_VARIADIC_MAX >= 1 template void call (int maxThreads, Fn f) - { - callf (maxThreads, bind (f)); - } + { callf (maxThreads, functional::bind (f)); } #endif #if BEAST_VARIADIC_MAX >= 2 template 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 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 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 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 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 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 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 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 /** @} */ diff --git a/Subtrees/beast/modules/beast_core/beast_core.cpp b/Subtrees/beast/modules/beast_core/beast_core.cpp index ba3982a370..5cc3872901 100644 --- a/Subtrees/beast/modules/beast_core/beast_core.cpp +++ b/Subtrees/beast/modules/beast_core/beast_core.cpp @@ -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" diff --git a/Subtrees/beast/modules/beast_core/beast_core.h b/Subtrees/beast/modules/beast_core/beast_core.h index dc89b66f5a..d562f943aa 100644 --- a/Subtrees/beast/modules/beast_core/beast_core.h +++ b/Subtrees/beast/modules/beast_core/beast_core.h @@ -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" diff --git a/Subtrees/beast/modules/beast_basics/diagnostic/beast_CatchAny.cpp b/Subtrees/beast/modules/beast_core/diagnostic/beast_ProtectedCall.cpp similarity index 91% rename from Subtrees/beast/modules/beast_basics/diagnostic/beast_CatchAny.cpp rename to Subtrees/beast/modules/beast_core/diagnostic/beast_ProtectedCall.cpp index 3577550406..ff709eddcc 100644 --- a/Subtrees/beast/modules/beast_basics/diagnostic/beast_CatchAny.cpp +++ b/Subtrees/beast/modules/beast_core/diagnostic/beast_ProtectedCall.cpp @@ -205,11 +205,11 @@ END_BEAST_NAMESPACE //------------------------------------------------------------------------------ +#if 0 bool CatchAny (Function f, bool returnFromException) { bool caughtException = true; // assume the worst -#if 0 try { //ScopedPlatformExceptionCatcher platformExceptionCatcher; @@ -271,6 +271,41 @@ bool CatchAny (Function f, bool returnFromException) } } } -#endif return caughtException; } +#endif + +//------------------------------------------------------------------------------ + +void ProtectedCall::DefaultHandler::onException (ProtectedCall::Exception const& e) const +{ +} + +Static::Storage , 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); + } +} diff --git a/Subtrees/beast/modules/beast_core/diagnostic/beast_ProtectedCall.h b/Subtrees/beast/modules/beast_core/diagnostic/beast_ProtectedCall.h new file mode 100644 index 0000000000..d133d3aa81 --- /dev/null +++ b/Subtrees/beast/modules/beast_core/diagnostic/beast_ProtectedCall.h @@ -0,0 +1,163 @@ +//------------------------------------------------------------------------------ +/* + This file is part of Beast: https://github.com/vinniefalco/Beast + Copyright 2013, Vinnie Falco + + 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 + explicit ProtectedCall (Fn f) + { callf (functional::bind (f)); } +#endif + +#if BEAST_VARIADIC_MAX >= 2 + template + ProtectedCall (Fn f, T1 t1) + { callf (functional::bind (f, t1)); } +#endif + +#if BEAST_VARIADIC_MAX >= 3 + template + ProtectedCall (Fn f, T1 t1, T2 t2) + { callf (functional::bind (f, t1, t2)); } +#endif + +#if BEAST_VARIADIC_MAX >= 4 + template + ProtectedCall (Fn f, T1 t1, T2 t2, T3 t3) + { callf (functional::bind (f, t1, t2, t3)); } +#endif + +#if BEAST_VARIADIC_MAX >= 5 + template + 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 + 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 + 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 + 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 + 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 + 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); + + call (wrapper); + } + + void call (Call& call); + +private: + static Static::Storage , ProtectedCall> s_handler; +}; + +#endif diff --git a/Subtrees/beast/modules/beast_core/diagnostic/beast_UnitTest.h b/Subtrees/beast/modules/beast_core/diagnostic/beast_UnitTest.h index 25c72c905f..656ce7ae1d 100644 --- a/Subtrees/beast/modules/beast_core/diagnostic/beast_UnitTest.h +++ b/Subtrees/beast/modules/beast_core/diagnostic/beast_UnitTest.h @@ -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: diff --git a/Subtrees/beast/modules/beast_core/memory/beast_Uncopyable.h b/Subtrees/beast/modules/beast_core/memory/beast_Uncopyable.h index 349dde0a10..0ddf154c4e 100644 --- a/Subtrees/beast/modules/beast_core/memory/beast_Uncopyable.h +++ b/Subtrees/beast/modules/beast_core/memory/beast_Uncopyable.h @@ -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. diff --git a/Subtrees/beast/modules/beast_core/misc/beast_Main.cpp b/Subtrees/beast/modules/beast_core/misc/beast_Main.cpp new file mode 100644 index 0000000000..9db4c19802 --- /dev/null +++ b/Subtrees/beast/modules/beast_core/misc/beast_Main.cpp @@ -0,0 +1,24 @@ +//------------------------------------------------------------------------------ +/* + This file is part of Beast: https://github.com/vinniefalco/Beast + Copyright 2013, Vinnie Falco + + 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) +{ +} diff --git a/Subtrees/beast/modules/beast_core/misc/beast_Main.h b/Subtrees/beast/modules/beast_core/misc/beast_Main.h new file mode 100644 index 0000000000..a2951c65a3 --- /dev/null +++ b/Subtrees/beast/modules/beast_core/misc/beast_Main.h @@ -0,0 +1,40 @@ +//------------------------------------------------------------------------------ +/* + This file is part of Beast: https://github.com/vinniefalco/Beast + Copyright 2013, Vinnie Falco + + 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 + diff --git a/Subtrees/beast/modules/beast_core/system/beast_Functional.h b/Subtrees/beast/modules/beast_core/system/beast_Functional.h index ef178d2c19..b16f1915ba 100644 --- a/Subtrees/beast/modules/beast_core/system/beast_Functional.h +++ b/Subtrees/beast/modules/beast_core/system/beast_Functional.h @@ -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 diff --git a/Subtrees/beast/modules/beast_core/system/beast_SystemStats.h b/Subtrees/beast/modules/beast_core/system/beast_SystemStats.h index 41a6e79562..02a76b21ea 100644 --- a/Subtrees/beast/modules/beast_core/system/beast_SystemStats.h +++ b/Subtrees/beast/modules/beast_core/system/beast_SystemStats.h @@ -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. diff --git a/Subtrees/beast/modules/beast_core/threads/beast_Thread.cpp b/Subtrees/beast/modules/beast_core/threads/beast_Thread.cpp index b413818d83..a2f7289743 100644 --- a/Subtrees/beast/modules/beast_core/threads/beast_Thread.cpp +++ b/Subtrees/beast/modules/beast_core/threads/beast_Thread.cpp @@ -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 (userData)->threadEntryPoint(); + ProtectedCall (&Thread::threadEntryPoint, static_cast (userData)); } //==============================================================================