Develop Biology
The language of life
|
#include "CacheMacros.h"
Go to the source code of this file.
Macros | |
#define | BIO_SANITIZE(test, success, failure) BIO_SANITIZE_AT_SAFETY_LEVEL_2(test, BIO_SINGLE_ARG(success), BIO_SINGLE_ARG(failure)) |
#define | BIO_SANITIZE_AT_SAFETY_LEVEL_0(test, success, failure) |
#define | BIO_SANITIZE_AT_SAFETY_LEVEL_1(test, success, failure) |
#define | BIO_SANITIZE_AT_SAFETY_LEVEL_2(test, success, failure) |
#define | BIO_SANITIZE_WITH_CACHE(test, success, failure) |
#define | BIO_SANITIZE_WITH_CACHE_AT_SAFETY_LEVEL_0(test, success, failure) |
#define | BIO_SANITIZE_WITH_CACHE_AT_SAFETY_LEVEL_1(test, success, failure) |
#define | BIO_SANITIZE_WITH_CACHE_AT_SAFETY_LEVEL_2(test, success, failure) |
#define BIO_SANITIZE | ( | test, | |
success, | |||
failure | |||
) | BIO_SANITIZE_AT_SAFETY_LEVEL_2(test, BIO_SINGLE_ARG(success), BIO_SINGLE_ARG(failure)) |
Definition at line 70 of file SanitizeMacros.h.
#define BIO_SANITIZE_AT_SAFETY_LEVEL_0 | ( | test, | |
success, | |||
failure | |||
) |
BIO_SANITIZE evaluates the current BIO_SAFETY_LEVEL and performs the appropriate checks. A lower BIO_SAFETY_LEVEL will mean faster run speed but a higher chance of crashing. NOTE: "auto" in the examples below is only available after c++11 and should be substituted with the appropriate type.
This is basically (test) ? (success) : (failure)
IMPORTANT: Do not declare variables within any statement (test, success, & failure). Any variables declared will go out of scope and won't be accessible to you.
BIO_SANITIZE should be usable in the following ways (and the variations thereof): BIO_SANITIZE(some_test(), some_test()->do_something(), ) BIO_SANITIZE(myVar, myVar->do_something(), do_something_else()) auto myVar; BIO_SANITIZE(some_test(), myVar = some_test(), myVar = 0) auto myOtherVar; BIO_SANITIZE(myVar, myOtherVar = myVar->do_something(), myOtherVar = 0)
Definition at line 43 of file SanitizeMacros.h.
#define BIO_SANITIZE_AT_SAFETY_LEVEL_1 | ( | test, | |
success, | |||
failure | |||
) |
Definition at line 48 of file SanitizeMacros.h.
#define BIO_SANITIZE_AT_SAFETY_LEVEL_2 | ( | test, | |
success, | |||
failure | |||
) |
Definition at line 54 of file SanitizeMacros.h.
#define BIO_SANITIZE_WITH_CACHE | ( | test, | |
success, | |||
failure | |||
) |
For more intensive tests, the result can be cached in a variable called RESULT of the given type.
You can access the cached result of TEST in the variable RESULT. THIS CAN GO HORRIBLY WRONG!!!!! C++11 is safe and should throw compiler errors if you mess up but C++98 requires the use of a ByteStream hack around the auto keyword. This should be safe when using built in types and pointers but THE BEHAVIOR OF ANYTHING ELSE IS UNDEFINED.
To make sure this is safe, do the following:
The above examples can be rewritten as: BIO_SANITIZE_WITH_CACHE(some_test(), RESULT->do_something(), ); BIO_SANITIZE_WITH_CACHE(myVar, myVar->do_something(), do_something_else()); auto myVar; BIO_SANITIZE_WITH_CACHE(some_test(), myVar = RESULT, myVar = 0); auto myOtherVar; BIO_SANITIZE_WITH_CACHE(myVar, myOtherVar = myVar->do_something(), myOtherVar = 0);
Just as with BIO_SANITIZE, "auto" may only be used with c++11 or greater and should be replaced with the appropriate type. NOTE: when using myVar->methods(), we don't use RESULT so that any mutating (i.e. non-const) operations are applied to myVar and not lost when RESULT goes out of scope.
Definition at line 94 of file SanitizeMacros.h.
#define BIO_SANITIZE_WITH_CACHE_AT_SAFETY_LEVEL_0 | ( | test, | |
success, | |||
failure | |||
) |
Definition at line 103 of file SanitizeMacros.h.
#define BIO_SANITIZE_WITH_CACHE_AT_SAFETY_LEVEL_1 | ( | test, | |
success, | |||
failure | |||
) |
Definition at line 112 of file SanitizeMacros.h.
#define BIO_SANITIZE_WITH_CACHE_AT_SAFETY_LEVEL_2 | ( | test, | |
success, | |||
failure | |||
) |
Definition at line 121 of file SanitizeMacros.h.