Macro.hpp 5.0 KB

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