enumgen.h (2873B)
1 /* 2 * 3 * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. 4 * 5 * Copyright 2007-2019 Broadcom Inc. All rights reserved. 6 * 7 * File: enumgen.h 8 * Purpose: Defines a set of Macros for managing enums and associated 9 * string arrays. 10 */ 11 #ifndef _ENUMGEN_H 12 #define _ENUMGEN_H 13 14 /* Enum typedef and Enum name strings generation Macros */ 15 #define SHR_G_ENUM_BEGIN(etype) typedef enum etype##e { 16 #define SHR_G_ENUM_END(etype) } etype##t 17 #define SHR_G_ENTRY(e) SHR_G_MAKE_STR(e) 18 #define SHR_G_NAME_BEGIN(etype) { 19 #define SHR_G_NAME_END(etype) } 20 #define SHR_G_MAKE_ENUM(e) \ 21 SHR_G_ENUM_BEGIN(e) \ 22 SHR_G_ENTRIES(dont_care) \ 23 SHR_G_ENUM_END(e) 24 25 26 /* These set of macros helps to keep the defined enums in sync with their string 27 * name array by requiring all modification in one place. 28 * To create a enum of type enum_type_t and an associated string array 29 * initializer ENUM_TYPE_NAME_INIALIZER use code described in template below 30 * and modify it suitably. For example the template code below defines - 31 typedef enum enum_type_e { 32 enum_type_zero, 33 enum_type_entry1, 34 enum_type_entry2, 35 enum_type_count 36 } enum_type_t ; 37 38 #define ENUM_TYPE_NAME_INITIALIZER { "zero" , \ 39 "entry1" , \ 40 "entry2" , \ 41 "count" } ; 42 43 */ 44 45 #if 0 /* Template code begin */ 46 47 #include "enumgen.h" 48 49 /* New additions are made below this line */ 50 #define SHR_G_ENTRIES(PFX, DC) /* DO NOT CHANGE */ \ 51 SHR_G_ENTRY(PFX, zero), /* DO NOT CHANGE */ \ 52 SHR_G_ENTRY(PFX, entry1), /* ===### Your entries here ###=== */ \ 53 SHR_G_ENTRY(PFX, entry2), /* ===### Your entries here ###=== */ \ 54 SHR_G_ENTRY(PFX, count) /* DO NOT CHANGE */ 55 /* New additions are made above this line*/ 56 57 /* Make the enums */ 58 #undef SHR_G_MAKE_STR /* DO NOT CHANGE */ 59 #define SHR_G_MAKE_STR(a) a /* DO NOT CHANGE */ 60 SHR_G_MAKE_ENUM(enum_type_); /* ===### Change enum_type_ ###=== */ 61 62 /* Make the string array */ 63 #undef SHR_G_MAKE_STR /* DO NOT CHANGE */ 64 #define SHR_G_MAKE_STR(a) #a /* DO NOT CHANGE */ 65 #define ENUM_TYPE_NAME_INITIALIZER /* ===### Change ENUM_TYPE_ ###=== */ \ 66 SHR_G_NAME_BEGIN(dont_care) /* DO NOT CHANGE */ \ 67 SHR_G_ENTRIES(, dont_care) /* DO NOT CHANGE */ \ 68 SHR_G_NAME_END(dont_care) /* DO NOT CHANGE */ 69 70 #endif /* Template code end */ 71 72 #endif /* !_ENUMGEN_H */