Macro.hpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /**
  2. * @file common/Macro.hpp
  3. * @author The ARTIS Development Team
  4. * See the AUTHORS or Authors.txt file
  5. */
  6. /*
  7. * ARTIS - the multimodeling and simulation environment
  8. * This file is a part of the ARTIS environment
  9. *
  10. * Copyright (C) 2013-2022 ULCO http://www.univ-littoral.fr
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation, either version 3 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. */
  25. #ifndef COMMON_MACRO_HPP
  26. #define COMMON_MACRO_HPP
  27. #define DOUBLEESCAPE(a) #a
  28. #define ESCAPEQUOTE(a) DOUBLEESCAPE(a)
  29. #define ITEM(index, var) { index, \
  30. std::string(ESCAPEQUOTE(index)), \
  31. var }
  32. #define UNWRAP_ITEM(...) ITEM __VA_ARGS__
  33. #define LIST_16(L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12, L13, L14, L15, L16) { UNWRAP_ITEM(L1), UNWRAP_ITEM(L2), UNWRAP_ITEM(L3), UNWRAP_ITEM(L4), UNWRAP_ITEM(L5), UNWRAP_ITEM(L6), UNWRAP_ITEM(L7), UNWRAP_ITEM(L8), UNWRAP_ITEM(L9), UNWRAP_ITEM(L10), UNWRAP_ITEM(L11), UNWRAP_ITEM(L12), UNWRAP_ITEM(L13), UNWRAP_ITEM(L14), UNWRAP_ITEM(L15), UNWRAP_ITEM(L16) }
  34. #define LIST_15(L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12, L13, L14, L15) { UNWRAP_ITEM(L1), UNWRAP_ITEM(L2), UNWRAP_ITEM(L3), UNWRAP_ITEM(L4), UNWRAP_ITEM(L5), UNWRAP_ITEM(L6), UNWRAP_ITEM(L7), UNWRAP_ITEM(L8), UNWRAP_ITEM(L9), UNWRAP_ITEM(L10), UNWRAP_ITEM(L11), UNWRAP_ITEM(L12), UNWRAP_ITEM(L13), UNWRAP_ITEM(L14), UNWRAP_ITEM(L15) }
  35. #define LIST_14(L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12, L13, L14) { UNWRAP_ITEM(L1), UNWRAP_ITEM(L2), UNWRAP_ITEM(L3), UNWRAP_ITEM(L4), UNWRAP_ITEM(L5), UNWRAP_ITEM(L6), UNWRAP_ITEM(L7), UNWRAP_ITEM(L8), UNWRAP_ITEM(L9), UNWRAP_ITEM(L10), UNWRAP_ITEM(L11), UNWRAP_ITEM(L12), UNWRAP_ITEM(L13), UNWRAP_ITEM(L14) }
  36. #define LIST_13(L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12, L13) { UNWRAP_ITEM(L1), UNWRAP_ITEM(L2), UNWRAP_ITEM(L3), UNWRAP_ITEM(L4), UNWRAP_ITEM(L5), UNWRAP_ITEM(L6), UNWRAP_ITEM(L7), UNWRAP_ITEM(L8), UNWRAP_ITEM(L9), UNWRAP_ITEM(L10), UNWRAP_ITEM(L11), UNWRAP_ITEM(L12), UNWRAP_ITEM(L13) }
  37. #define LIST_12(L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12) { UNWRAP_ITEM(L1), UNWRAP_ITEM(L2), UNWRAP_ITEM(L3), UNWRAP_ITEM(L4), UNWRAP_ITEM(L5), UNWRAP_ITEM(L6), UNWRAP_ITEM(L7), UNWRAP_ITEM(L8), UNWRAP_ITEM(L9), UNWRAP_ITEM(L10), UNWRAP_ITEM(L11), UNWRAP_ITEM(L12) }
  38. #define LIST_11(L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11) { UNWRAP_ITEM(L1), UNWRAP_ITEM(L2), UNWRAP_ITEM(L3), UNWRAP_ITEM(L4), UNWRAP_ITEM(L5), UNWRAP_ITEM(L6), UNWRAP_ITEM(L7), UNWRAP_ITEM(L8), UNWRAP_ITEM(L9), UNWRAP_ITEM(L10), UNWRAP_ITEM(L11) }
  39. #define LIST_10(L1, L2, L3, L4, L5, L6, L7, L8, L9, L10) { UNWRAP_ITEM(L1), UNWRAP_ITEM(L2), UNWRAP_ITEM(L3), UNWRAP_ITEM(L4), UNWRAP_ITEM(L5), UNWRAP_ITEM(L6), UNWRAP_ITEM(L7), UNWRAP_ITEM(L8), UNWRAP_ITEM(L9), UNWRAP_ITEM(L10) }
  40. #define LIST_9(L1, L2, L3, L4, L5, L6, L7, L8, L9) { UNWRAP_ITEM(L1), UNWRAP_ITEM(L2), UNWRAP_ITEM(L3), UNWRAP_ITEM(L4), UNWRAP_ITEM(L5), UNWRAP_ITEM(L6), UNWRAP_ITEM(L7), UNWRAP_ITEM(L8), UNWRAP_ITEM(L9) }
  41. #define LIST_8(L1, L2, L3, L4, L5, L6, L7, L8) { UNWRAP_ITEM(L1), UNWRAP_ITEM(L2), UNWRAP_ITEM(L3), UNWRAP_ITEM(L4), UNWRAP_ITEM(L5), UNWRAP_ITEM(L6), UNWRAP_ITEM(L7), UNWRAP_ITEM(L8) }
  42. #define LIST_7(L1, L2, L3, L4, L5, L6, L7) { UNWRAP_ITEM(L1), UNWRAP_ITEM(L2), UNWRAP_ITEM(L3), UNWRAP_ITEM(L4), UNWRAP_ITEM(L5), UNWRAP_ITEM(L6), UNWRAP_ITEM(L7) }
  43. #define LIST_6(L1, L2, L3, L4, L5, L6) { UNWRAP_ITEM(L1), UNWRAP_ITEM(L2), UNWRAP_ITEM(L3), UNWRAP_ITEM(L4), UNWRAP_ITEM(L5), UNWRAP_ITEM(L6) }
  44. #define LIST_5(L1, L2, L3, L4, L5) { UNWRAP_ITEM(L1), UNWRAP_ITEM(L2), UNWRAP_ITEM(L3), UNWRAP_ITEM(L4), UNWRAP_ITEM(L5) }
  45. #define LIST_4(L1, L2, L3, L4) { UNWRAP_ITEM(L1), UNWRAP_ITEM(L2), UNWRAP_ITEM(L3), UNWRAP_ITEM(L4) }
  46. #define LIST_3(L1, L2, L3) { UNWRAP_ITEM(L1), UNWRAP_ITEM(L2), UNWRAP_ITEM(L3) }
  47. #define LIST_2(L1, L2) { UNWRAP_ITEM(L1), UNWRAP_ITEM(L2) }
  48. #define LIST_1(L1) { UNWRAP_ITEM(L1) }
  49. #define EXPAND(X) X
  50. #define PP_NARG(...) EXPAND( PP_NARG_(__VA_ARGS__, PP_RSEQ_N()) )
  51. #define PP_NARG_(...) EXPAND( PP_ARG_N(__VA_ARGS__) )
  52. #define PP_ARG_N(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10_, _11, _12, _13, _14, _15, _16, N, ...) N
  53. #define PP_RSEQ_N() 16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0
  54. #define LIST_(N) LIST_##N
  55. #define LIST_EVAL(N) LIST_(N)
  56. #define UNWRAP2(...) EXPAND( LIST_EVAL(EXPAND( PP_NARG(__VA_ARGS__) ))(__VA_ARGS__) )
  57. #endif