Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenlib/BLI_utildefines.h
| Show First 20 Lines • Show All 787 Lines • ▼ Show 20 Lines | |||||
| /** Useful for debugging. */ | /** Useful for debugging. */ | ||||
| #define AT __FILE__ ":" STRINGIFY(__LINE__) | #define AT __FILE__ ":" STRINGIFY(__LINE__) | ||||
| /** No-op for expressions we don't want to instantiate, but must remain valid. */ | /** No-op for expressions we don't want to instantiate, but must remain valid. */ | ||||
| #define EXPR_NOP(expr) (void)(0 ? ((void)(expr), 1) : 0) | #define EXPR_NOP(expr) (void)(0 ? ((void)(expr), 1) : 0) | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | |||||
| /** \name CPP Enum Operators | |||||
| * \{ */ | |||||
| #ifdef __cplusplus | |||||
| // Define operator overloads to enable bit operations on enum values that are | |||||
| // used to define flags. Use BLI_ENUM_FLAG_OPERATORS(YOUR_TYPE) to enable these | |||||
| // operators on YOUR_TYPE. | |||||
| # define BLI_ENUM_FLAG_OPERATORS(ENUMTYPE) \ | |||||
brecht: I would name this `BLI_ENUM_FLAG_OPERATORS`. | |||||
| constexpr ENUMTYPE operator|(ENUMTYPE a, ENUMTYPE b) \ | |||||
| { \ | |||||
| return static_cast<ENUMTYPE>(static_cast<unsigned int>(a) | static_cast<unsigned int>(b)); \ | |||||
| } \ | |||||
| BLI_INLINE ENUMTYPE &operator|=(ENUMTYPE &a, ENUMTYPE b) \ | |||||
| { \ | |||||
| a = a | b; \ | |||||
| return a; \ | |||||
| } \ | |||||
| constexpr ENUMTYPE operator&(ENUMTYPE a, ENUMTYPE b) \ | |||||
| { \ | |||||
| return static_cast<ENUMTYPE>(static_cast<unsigned int>(a) & static_cast<unsigned int>(b)); \ | |||||
| } \ | |||||
| BLI_INLINE ENUMTYPE &operator&=(ENUMTYPE &a, ENUMTYPE b) \ | |||||
| { \ | |||||
| a = a & b; \ | |||||
| return a; \ | |||||
| } \ | |||||
| constexpr ENUMTYPE operator~(ENUMTYPE a) \ | |||||
| { \ | |||||
| return static_cast<ENUMTYPE>(~static_cast<unsigned int>(a)); \ | |||||
| } \ | |||||
| constexpr ENUMTYPE operator^(ENUMTYPE a, ENUMTYPE b) \ | |||||
| { \ | |||||
| return static_cast<ENUMTYPE>(static_cast<unsigned int>(a) ^ static_cast<unsigned int>(b)); \ | |||||
| } \ | |||||
| BLI_INLINE ENUMTYPE &operator^=(ENUMTYPE &a, ENUMTYPE b) \ | |||||
| { \ | |||||
| a = a ^ b; \ | |||||
| return a; \ | |||||
| } | |||||
| #else /* __cplusplus */ | |||||
Done Inline ActionsAdd an #else here and define an empty macro. That way we don't have to add #ifdef __cplusplus wherever this is used. brecht: Add an `#else` here and define an empty macro. That way we don't have to add `#ifdef… | |||||
| # define BLI_ENUM_FLAG_OPERATORS(ENUMTYPE) | |||||
| #endif /* __cplusplus */ | |||||
| /** \} */ | |||||
| #ifdef __cplusplus | #ifdef __cplusplus | ||||
LazyDodoUnsubmitted Not Done Inline Actions30+ line un-debuggable macro, is there any way this can be turned into a template so it is atleast debuggable? LazyDodo: 30+ line un-debuggable macro, is there any way this can be turned into a template so it is… | |||||
| } | } | ||||
| #endif | #endif | ||||
| #endif /* __BLI_UTILDEFINES_H__ */ | #endif /* __BLI_UTILDEFINES_H__ */ | ||||
I would name this BLI_ENUM_FLAG_OPERATORS.