Develop Biology
The language of life
SanitizeMacros.h File Reference
#include "CacheMacros.h"
+ Include dependency graph for SanitizeMacros.h:
+ This graph shows which files directly or indirectly include this file:

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)
 

Macro Definition Documentation

◆ BIO_SANITIZE

#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.

◆ BIO_SANITIZE_AT_SAFETY_LEVEL_0

#define BIO_SANITIZE_AT_SAFETY_LEVEL_0 (   test,
  success,
  failure 
)
Value:
{ \
success; \
}

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.

◆ BIO_SANITIZE_AT_SAFETY_LEVEL_1

#define BIO_SANITIZE_AT_SAFETY_LEVEL_1 (   test,
  success,
  failure 
)
Value:
{ \
BIO_ASSERT(test); \
success; \
}

Definition at line 48 of file SanitizeMacros.h.

◆ BIO_SANITIZE_AT_SAFETY_LEVEL_2

#define BIO_SANITIZE_AT_SAFETY_LEVEL_2 (   test,
  success,
  failure 
)
Value:
if (test) \
{ \
success; \
} \
else \
{ \
failure; \
}

Definition at line 54 of file SanitizeMacros.h.

◆ BIO_SANITIZE_WITH_CACHE

#define BIO_SANITIZE_WITH_CACHE (   test,
  success,
  failure 
)
Value:
{ \
BIO_CACHE(test) \
BIO_SANITIZE( \
RESULT, \
BIO_SINGLE_ARG(success), \
BIO_SINGLE_ARG(failure)) \
}
#define BIO_SINGLE_ARG(...)
Definition: Macros.h:66

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:

  1. Make sure your success and/or failure expressions treat RESULT as the return type of your test expression.
  2. Do not use a test expression that returns a non-basic type if you are using C++98. Pointers are okay.

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.

◆ BIO_SANITIZE_WITH_CACHE_AT_SAFETY_LEVEL_0

#define BIO_SANITIZE_WITH_CACHE_AT_SAFETY_LEVEL_0 (   test,
  success,
  failure 
)
Value:
{ \
BIO_CACHE(test) \
BIO_SANITIZE_AT_SAFETY_LEVEL_0( \
RESULT, \
BIO_SINGLE_ARG(success), \
BIO_SINGLE_ARG(failure)) \
}

Definition at line 103 of file SanitizeMacros.h.

◆ BIO_SANITIZE_WITH_CACHE_AT_SAFETY_LEVEL_1

#define BIO_SANITIZE_WITH_CACHE_AT_SAFETY_LEVEL_1 (   test,
  success,
  failure 
)
Value:
{ \
BIO_CACHE(test) \
BIO_SANITIZE_AT_SAFETY_LEVEL_1( \
RESULT, \
BIO_SINGLE_ARG(success), \
BIO_SINGLE_ARG(failure)) \
}

Definition at line 112 of file SanitizeMacros.h.

◆ BIO_SANITIZE_WITH_CACHE_AT_SAFETY_LEVEL_2

#define BIO_SANITIZE_WITH_CACHE_AT_SAFETY_LEVEL_2 (   test,
  success,
  failure 
)
Value:
{ \
BIO_CACHE(test) \
BIO_SANITIZE_AT_SAFETY_LEVEL_2( \
RESULT, \
BIO_SINGLE_ARG(success), \
BIO_SINGLE_ARG(failure)) \
}

Definition at line 121 of file SanitizeMacros.h.