Actual source code: petscadvancedmacros.h
1: #pragma once
3: #include <petscmacros.h>
5: /* ------------------------------ Like petscmacros.h but advanced ------------------------------ */
7: #define PETSC_IF_INTERNAL_0(result_if_true, ...) __VA_ARGS__
8: #define PETSC_IF_INTERNAL_1(result_if_true, ...) result_if_true
10: /*
11: PetscIf - Conditionally expand to the second or remaining args
13: No Fortran Support
15: Input Parameters:
16: + cond - Preprocessor conditional
17: . result_if_true - Result of macro expansion if cond expands to 1
18: - __VA_ARGS__ - Result of macro expansion if cond expands to 0
20: Notes:
21: cond must be defined and expand (not evaluate!) to either integer literal 0 or 1. Must have
22: at least 1 argument for __VA_ARGS__, but it may expand empty.
24: Example usage:
25: .vb
26: void myFunction(int,char*);
27: #define MY_VAR 1
28: PetscIf(MY_VAR,"hello","goodbye") -> "hello"
29: PetscIf(MY_VAR,myFunction,PetscExpandToNothing)(1,"hello") -> myFunction(1,"hello")
31: #define MY_VAR 0
32: PetscIf(MY_VAR,"hello",func<type1,type2>()) -> func<type1,type2>()
33: PetscIf(MY_VAR,myFunction,PetscExpandToNothing)(1,"hello") -> *nothing*
34: .ve
36: Level: intermediate
38: .seealso: `PetscIfPetscDefined()`, `PetscConcat()`, `PetscExpandToNothing()`, `PetscCompl()`
39: */
40: #define PetscIf(cond, result_if_true, ...) PetscConcat_(PETSC_IF_INTERNAL_, cond)(result_if_true, __VA_ARGS__)
42: /*
43: PetscIfPetscDefined - Like PetscIf(), but passes cond through PetscDefined() first
45: No Fortran Support
47: Input Parameters:
48: + cond - Condition passed to PetscDefined()
49: . result_if_true - Result of macro expansion if PetscDefined(cond) expands to 1
50: - __VA_ARGS__ - Result of macro expansion if PetscDefined(cond) expands to 0
52: Notes:
53: cond must satisfy all conditions for PetscDefined(). Must have at least 1 argument for
54: __VA_ARGS__, but it may expand empty.
56: Example usage:
57: .vb
58: #define PETSC_HAVE_FOO 1
59: PetscIfPetscDefined(HAVE_FOO,foo,bar) -> foo
61: #undef PETSC_HAVE_FOO
62: PetscIfPetscDefined(HAVE_FOO,foo,bar,baz,bop) -> bar,baz,bop
63: .ve
65: Level: intermediate
67: .seealso: `PetscIf()`, `PetscDefined()`, `PetscConcat()`, `PetscExpand()`, `PetscCompl()`
68: */
69: #define PetscIfPetscDefined(cond, result_if_true, ...) PetscIf(PetscDefined(cond), result_if_true, __VA_ARGS__)