color_id_macros.inc 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright 2019 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. // The following macros are used to declare both the color id enumerations and
  5. // the stringized names of the enumeration elements for use in dump_colors. To
  6. // stringize the element names, define STRINGIZE_COLOR_IDS prior to including
  7. // this file. This file is intended to be included just before and just after
  8. // the enumeration or string array declarations.
  9. #if !defined(COLOR_ID_MACROS_DEFINED)
  10. #define COLOR_ID_MACROS_DEFINED
  11. #if defined(STRINGIZE_COLOR_IDS)
  12. // Convert first token to string, throw away the rest.
  13. #define D1(enum_name) #enum_name
  14. #define D2(enum_name, enum_value) #enum_name
  15. #else // defined(STRINGIZE_COLOR_IDS)
  16. // Declare enum with optional assigned value.
  17. #define D1(enum_name) enum_name
  18. #define D2(enum_name, enum_value) enum_name = enum_value
  19. #endif // defined(STRINGIZE_COLOR_IDS)
  20. // Select which token in the declaration is the assigned value.
  21. // Use first and optional third token, ignore optional second.
  22. #define E1(enum_name) D1(enum_name)
  23. #define E2(enum_name, old_enum_name) D1(enum_name)
  24. #define E3(enum_name, old_enum_name, enum_value) D2(enum_name, enum_value)
  25. #define E_CPONLY(...) E(__VA_ARGS__)
  26. #define GET_E(_1, _2, _3, macro_name, ...) macro_name
  27. #define E(...) GET_E(__VA_ARGS__, E3, E2, E1)(__VA_ARGS__),
  28. #else // !defined(COLOR_ID_MACROS_DEFINED)
  29. #undef D1
  30. #undef D2
  31. #undef E1
  32. #undef E2
  33. #undef E3
  34. #undef E_CPONLY
  35. #undef GET_E
  36. #undef E
  37. #undef COLOR_ID_MACROS_DEFINED
  38. #endif // !defined(COLOR_ID_MACROS_DEFINED)