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 -
8 // Meta-programming to ensure that all NFT cases are properly handled in switch statements that should handle all NFT types
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.
17 #ifndef NSENUMHANDLEALLCASES_H
18 #define NSENUMHANDLEALLCASES_H
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.
24 #define NFT_CASE(type) case type: int NFT_CASE_VERIFICATION_TYPE_NAME(type);
27 #define NFT_CASE(type) case type:
29 #endif // NSENUMHANDLEALLCASES_H
31 #if defined(_DEBUG) && defined(NFT_VERIFY_ALL_CASES)
33 int *nftAccumulator = nullptr;
36 #define DEFINE_NFT(type, size, WinRTSupported) nftAccumulator += (int)&NFT_CASE_VERIFICATION_TYPE_NAME(type),
38 nftAccumulator = nullptr;
41 #endif // _DEBUG && NFT_VERIFY_ALL_CASES
42 #undef NFT_VERIFY_ALL_CASES
43 #undef NFT_CASE_VERIFICATION_TYPE_NAME