Go to the documentation of this file.00001
00002
00003
00004
00005
00006 #include "SgSystem.h"
00007
00008 #include <algorithm>
00009 #include <cassert>
00010 #include <cstdlib>
00011 #include <functional>
00012 #include <iostream>
00013 #include <limits>
00014 #include <list>
00015 #include "SgTime.h"
00016
00017 using namespace std;
00018
00019
00020
00021 namespace {
00022
00023 volatile bool s_userAbort = false;
00024
00025
00026
00027
00028
00029 list<SgAssertionHandler*>& AssertionHandlers()
00030 {
00031 static list<SgAssertionHandler*> s_assertionHandlers;
00032 return s_assertionHandlers;
00033 }
00034
00035 }
00036
00037
00038
00039 SgAssertionHandler::SgAssertionHandler()
00040 {
00041 AssertionHandlers().push_back(this);
00042 }
00043
00044 SgAssertionHandler::~SgAssertionHandler()
00045 {
00046 AssertionHandlers().remove(this);
00047 }
00048
00049
00050
00051 #ifndef NDEBUG
00052
00053
00054
00055 static bool s_assertContinue = (std::getenv("SMARTGAME_ASSERT_CONTINUE") != 0);
00056
00057 void SgHandleAssertion(const char* expr, const char* file, int line)
00058 {
00059
00060 cerr << "Assertion failed "
00061 << file << ':' << line << ": " << expr << '\n';
00062 for_each(AssertionHandlers().begin(), AssertionHandlers().end(),
00063 mem_fun(&SgAssertionHandler::Run));
00064 if (! s_assertContinue)
00065 abort();
00066 }
00067 #endif
00068
00069
00070
00071 void SgSetUserAbort(bool aborted)
00072 {
00073 s_userAbort = aborted;
00074 }
00075
00076 bool SgUserAbort()
00077 {
00078 return s_userAbort;
00079 }
00080
00081