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: Level: intermediate
22: Note:
23: `cond` must be defined and expand (not evaluate!) to either integer literal 0 or 1. Must have
24: at least 1 argument for `__VA_ARGS__`, but it may expand empty.
26: Example usage:
27: .vb
28: void myFunction(int,char*);
29: #define MY_VAR 1
30: PetscIf(MY_VAR,"hello","goodbye") -> "hello"
31: PetscIf(MY_VAR,myFunction,PetscExpandToNothing)(1,"hello") -> myFunction(1,"hello")
33: #define MY_VAR 0
34: PetscIf(MY_VAR,"hello",func<type1,type2>()) -> func<type1,type2>()
35: PetscIf(MY_VAR,myFunction,PetscExpandToNothing)(1,"hello") -> *nothing*
36: .ve
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: Level: intermediate
54: Note:
55: `cond` must satisfy all conditions for `PetscDefined()`. It must have at least 1 argument for
56: `__VA_ARGS__`, but it may expand empty.
58: Example usage:
59: .vb
60: #define PETSC_HAVE_FOO 1
61: PetscIfPetscDefined(HAVE_FOO,foo,bar) -> foo
63: #undef PETSC_HAVE_FOO
64: PetscIfPetscDefined(HAVE_FOO,foo,bar,baz,bop) -> bar,baz,bop
65: .ve
67: .seealso: `PetscIf()`, `PetscDefined()`, `PetscConcat()`, `PetscExpand()`, `PetscCompl()`
68: */
69: #define PetscIfPetscDefined(cond, result_if_true, ...) PetscIf(PetscDefined(cond), result_if_true, __VA_ARGS__)