| 1 | // Licensed to the .NET Foundation under one or more agreements. | 
|---|
| 2 | // The .NET Foundation licenses this file to you under the MIT license. | 
|---|
| 3 | // See the LICENSE file in the project root for more information. | 
|---|
| 4 | // NSENUMSHANDLEALLCASES.H - | 
|---|
| 5 | // | 
|---|
| 6 |  | 
|---|
| 7 | // | 
|---|
| 8 | // Meta-programming to ensure that all NFT cases are properly handled in switch statements that should handle all NFT types | 
|---|
| 9 | // | 
|---|
| 10 | // Uses of this header file are done by | 
|---|
| 11 | //  - #include the header before the case statement, probably at the top of the cpp file | 
|---|
| 12 | //  - #define NFT_CASE_VERIFICATION_TYPE_NAME(type) before the switch to give a descriptive name based on type. The type name string | 
|---|
| 13 | //     is the detail that gets used to find the switch statement that has a problem | 
|---|
| 14 | //  - Instead of using normal case statements, use NFT_CASE(type). See examples in class.cpp. | 
|---|
| 15 | //  - In a default: case statement, define NFT_VERIFY_ALL_CASES and then include this file again. | 
|---|
| 16 | // | 
|---|
| 17 | #ifndef NSENUMHANDLEALLCASES_H | 
|---|
| 18 | #define NSENUMHANDLEALLCASES_H | 
|---|
| 19 |  | 
|---|
| 20 | // Requiring all nft types to be handled is done by defining a variable in each case statement, and then in the default: statement | 
|---|
| 21 | // computing a value that depends on the value of all of those variables. | 
|---|
| 22 |  | 
|---|
| 23 | #ifdef _DEBUG | 
|---|
| 24 | #define NFT_CASE(type) case type: int NFT_CASE_VERIFICATION_TYPE_NAME(type); | 
|---|
| 25 |  | 
|---|
| 26 | #else | 
|---|
| 27 | #define NFT_CASE(type) case type: | 
|---|
| 28 | #endif | 
|---|
| 29 | #endif // NSENUMHANDLEALLCASES_H | 
|---|
| 30 |  | 
|---|
| 31 | #if defined(_DEBUG) && defined(NFT_VERIFY_ALL_CASES) | 
|---|
| 32 |  | 
|---|
| 33 | int *nftAccumulator = nullptr; | 
|---|
| 34 | do { | 
|---|
| 35 | #undef DEFINE_NFT | 
|---|
| 36 | #define DEFINE_NFT(type, size, WinRTSupported) nftAccumulator += (int)&NFT_CASE_VERIFICATION_TYPE_NAME(type), | 
|---|
| 37 | #include "nsenums.h" | 
|---|
| 38 | nftAccumulator = nullptr; | 
|---|
| 39 | } while (false); | 
|---|
| 40 | #undef DEFINE_NFT | 
|---|
| 41 | #endif // _DEBUG && NFT_VERIFY_ALL_CASES | 
|---|
| 42 | #undef NFT_VERIFY_ALL_CASES | 
|---|
| 43 | #undef NFT_CASE_VERIFICATION_TYPE_NAME | 
|---|
| 44 |  | 
|---|