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: Input Parameters:
15: + cond - Preprocessor conditional
16: . result_if_true - Result of macro expansion if cond expands to 1
17: - __VA_ARGS__ - Result of macro expansion if cond expands to 0
19: Notes:
20: Not available from Fortran, requires variadic macro support, definition is disabled by
21: defining PETSC_SKIP_VARIADIC_MACROS.
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: Level: intermediate
40: .seealso: `PetscIfPetscDefined()`, `PetscConcat()`, `PetscExpandToNothing()`, `PetscCompl()`
41: */
42: #define PetscIf(cond, result_if_true, ...) PetscConcat_(PETSC_IF_INTERNAL_, cond)(result_if_true, __VA_ARGS__)
44: /*
45: PetscIfPetscDefined - Like PetscIf(), but passes cond through PetscDefined() first
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: Not available from Fortran, requires variadic macro support, definition is disabled by
54: defining PETSC_SKIP_VARIADIC_MACROS.
56: cond must satisfy all conditions for PetscDefined(). Must have at least 1 argument for
57: __VA_ARGS__, but it may expand empty.
59: Example usage:
60: .vb
61: #define PETSC_HAVE_FOO 1
62: PetscIfPetscDefined(HAVE_FOO,foo,bar) -> foo
64: #undef PETSC_HAVE_FOO
65: PetscIfPetscDefined(HAVE_FOO,foo,bar,baz,bop) -> bar,baz,bop
66: .ve
68: Level: intermediate
70: .seealso: `PetscIf()`, `PetscDefined()`, `PetscConcat()`, `PetscExpand()`, `PetscCompl()`
71: */
72: #define PetscIfPetscDefined(cond, result_if_true, ...) PetscIf(PetscDefined(cond), result_if_true, __VA_ARGS__)
74: #endif /* PETSCADVANCEDMACROS_H */