General refactoring of beast framework classes

This commit is contained in:
Vinnie Falco
2013-09-12 08:26:25 -07:00
parent 84ef06e35c
commit 02acf7d6d0
26 changed files with 514 additions and 306 deletions

View File

@@ -17,31 +17,33 @@
*/
//==============================================================================
Static::Storage <Atomic <Main*>, Main> Main::s_instance;
Main* Main::s_instance;
Main::Main ()
{
bool const replaced = s_instance->compareAndSetBool (this, nullptr);
// If this happens it means there are two instances of Main!
if (! replaced)
FatalError ("Multiple instances of Main", __FILE__, __LINE__);
check_precondition (s_instance == nullptr);
s_instance = this;
}
Main::~Main ()
{
s_instance->set (nullptr);
s_instance = nullptr;
}
Main& Main::getInstance ()
{
bassert (s_instance->get () != nullptr);
bassert (s_instance != nullptr);
return *s_instance->get ();
return *s_instance;
}
void Main::runStartupUnitTests ()
int Main::runStartupUnitTests ()
{
int exitCode = EXIT_SUCCESS;
struct StartupUnitTests : UnitTests
{
void logMessage (String const&)
@@ -105,15 +107,20 @@ void Main::runStartupUnitTests ()
{
tests.reportResults ();
tests.log ("Terminating due to failed startup tests");
tests.log ("Terminating with an error due to failed startup tests.");
Process::terminate ();
exitCode = EXIT_FAILURE;
}
return exitCode;
}
int Main::runFromMain (int argc, char const* const* argv)
{
runStartupUnitTests ();
int exitCode (runStartupUnitTests ());
return run (argc, argv);
if (exitCode == EXIT_SUCCESS)
exitCode = run (argc, argv);
return exitCode;
}

View File

@@ -17,15 +17,14 @@
*/
//==============================================================================
#ifndef BEAST_MAIN_H_INCLUDED
#define BEAST_MAIN_H_INCLUDED
/** Represents a command line program's entry point.
#ifndef BEAST_CORE_MAIN_H_INCLUDED
#define BEAST_CORE_MAIN_H_INCLUDED
/** Represents a command line program's entry point
To use this, derive your class from @ref Main and implement the
function run ();
*/
class BEAST_API Main : public Uncopyable
class Main : public Uncopyable
{
public:
Main ();
@@ -70,10 +69,10 @@ protected:
virtual int run (int argc, char const* const* argv) = 0;
private:
void runStartupUnitTests ();
int runStartupUnitTests ();
private:
static Static::Storage <Atomic <Main*>, Main> s_instance;
static Main* s_instance;
};
#endif