Actual source code: petscadvancedmacros.h

  1: #ifndef PETSCADVANCEDMACROS_H
  2: #define PETSCADVANCEDMACROS_H

  4: #include <petscmacros.h>

  6: /* ------------------------------ Like petscmacros.h but advanced ------------------------------ */

  8: #define PETSC_IF_INTERNAL_0(result_if_true, ...) __VA_ARGS__
  9: #define PETSC_IF_INTERNAL_1(result_if_true, ...) result_if_true

 11: /*
 12:   PetscIf - Conditionally expand to the second or remaining args

 14:   No Fortran Support

 16:   Input Parameters:
 17: + cond           - Preprocessor conditional
 18: . result_if_true - Result of macro expansion if cond expands to 1
 19: - __VA_ARGS__    - Result of macro expansion if cond expands to 0

 21:   Notes:
 22:   cond must be defined and expand (not evaluate!) to either integer literal 0 or 1. Must have
 23:   at least 1 argument for __VA_ARGS__, but it may expand empty.

 25:   Example usage:
 26: .vb
 27:   void myFunction(int,char*);
 28:   #define MY_VAR 1
 29:   PetscIf(MY_VAR,"hello","goodbye") -> "hello"
 30:   PetscIf(MY_VAR,myFunction,PetscExpandToNothing)(1,"hello") -> myFunction(1,"hello")

 32:   #define MY_VAR 0
 33:   PetscIf(MY_VAR,"hello",func<type1,type2>()) -> func<type1,type2>()
 34:   PetscIf(MY_VAR,myFunction,PetscExpandToNothing)(1,"hello") -> *nothing*
 35: .ve

 37:   Level: intermediate

 39: .seealso: `PetscIfPetscDefined()`, `PetscConcat()`, `PetscExpandToNothing()`, `PetscCompl()`
 40: */
 41: #define PetscIf(cond, result_if_true, ...) PetscConcat_(PETSC_IF_INTERNAL_, cond)(result_if_true, __VA_ARGS__)

 43: /*
 44:   PetscIfPetscDefined - Like PetscIf(), but passes cond through PetscDefined() first

 46:   No Fortran Support

 48:   Input Parameters:
 49: + cond           - Condition passed to PetscDefined()
 50: . result_if_true - Result of macro expansion if PetscDefined(cond) expands to 1
 51: - __VA_ARGS__    - Result of macro expansion if PetscDefined(cond) expands to 0

 53:   Notes:
 54:   cond must satisfy all conditions for PetscDefined(). Must have at least 1 argument for
 55:   __VA_ARGS__, but it may expand empty.

 57:   Example usage:
 58: .vb
 59:   #define PETSC_HAVE_FOO 1
 60:   PetscIfPetscDefined(HAVE_FOO,foo,bar) -> foo

 62:   #undef PETSC_HAVE_FOO
 63:   PetscIfPetscDefined(HAVE_FOO,foo,bar,baz,bop) -> bar,baz,bop
 64: .ve

 66:   Level: intermediate

 68: .seealso: `PetscIf()`, `PetscDefined()`, `PetscConcat()`, `PetscExpand()`, `PetscCompl()`
 69: */
 70: #define PetscIfPetscDefined(cond, result_if_true, ...) PetscIf(PetscDefined(cond), result_if_true, __VA_ARGS__)

 72: #endif /* PETSCADVANCEDMACROS_H */