Add SetAssertFunction.

This commit is contained in:
vng 2011-07-03 12:53:14 +03:00 committed by Alex Zolotarev
parent bbfac69edc
commit f15f79bdcc
3 changed files with 14 additions and 3 deletions

View file

@ -35,7 +35,7 @@ void InitSystemLog()
void InitAssertLog()
{
OnAssertFailed = &AndroidAssertMessage;
SetAssertFunction(&AndroidAssertMessage);
}
}

View file

@ -8,8 +8,13 @@
namespace my
{
// Called when ASSERT, CHECK or VERIFY failed.
extern void (*OnAssertFailed)(SrcPoint const &, string const &);
typedef void (*AssertFailedFn)(SrcPoint const &, string const &);
extern AssertFailedFn OnAssertFailed;
/// @return Pointer to previous message function.
AssertFailedFn SetAssertFunction(AssertFailedFn fn);
}
// TODO: Evaluate X only once in CHECK().
#define CHECK(X, msg) if (X) {} else { \
::my::OnAssertFailed(SRC(), ::my::impl::MergeMsg("CHECK("#X")", ::my::impl::Message msg));}

View file

@ -32,5 +32,11 @@ namespace my
#endif
}
void (*OnAssertFailed)(SrcPoint const &, string const &) = &OnAssertFailedDefault;
AssertFailedFn OnAssertFailed = &OnAssertFailedDefault;
AssertFailedFn SetAssertFunction(AssertFailedFn fn)
{
std::swap(OnAssertFailed, fn);
return fn;
}
}