class.hpp 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #ifndef BOOST_DESCRIBE_CLASS_HPP_INCLUDED
  2. #define BOOST_DESCRIBE_CLASS_HPP_INCLUDED
  3. // Copyright 2020 Peter Dimov
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // https://www.boost.org/LICENSE_1_0.txt
  6. #include <boost/describe/detail/config.hpp>
  7. #if !defined(BOOST_DESCRIBE_CXX14)
  8. #define BOOST_DESCRIBE_CLASS(C, Bases, Public, Protected, Private)
  9. #define BOOST_DESCRIBE_STRUCT(C, Bases, Members)
  10. #else
  11. #include <boost/describe/detail/bases.hpp>
  12. #include <boost/describe/detail/members.hpp>
  13. #include <type_traits>
  14. namespace boost
  15. {
  16. namespace describe
  17. {
  18. #if defined(_MSC_VER) && !defined(__clang__)
  19. #define BOOST_DESCRIBE_PP_UNPACK(...) __VA_ARGS__
  20. #define BOOST_DESCRIBE_CLASS(C, Bases, Public, Protected, Private) \
  21. friend BOOST_DESCRIBE_BASES(C, BOOST_DESCRIBE_PP_UNPACK Bases) \
  22. friend BOOST_DESCRIBE_PUBLIC_MEMBERS(C, BOOST_DESCRIBE_PP_UNPACK Public) \
  23. friend BOOST_DESCRIBE_PROTECTED_MEMBERS(C, BOOST_DESCRIBE_PP_UNPACK Protected) \
  24. friend BOOST_DESCRIBE_PRIVATE_MEMBERS(C, BOOST_DESCRIBE_PP_UNPACK Private)
  25. #define BOOST_DESCRIBE_STRUCT(C, Bases, Members) \
  26. static_assert(std::is_class<C>::value || std::is_union<C>::value, "BOOST_DESCRIBE_STRUCT should only be used with class types"); \
  27. BOOST_DESCRIBE_BASES(C, BOOST_DESCRIBE_PP_UNPACK Bases) \
  28. BOOST_DESCRIBE_PUBLIC_MEMBERS(C, BOOST_DESCRIBE_PP_UNPACK Members) \
  29. BOOST_DESCRIBE_PROTECTED_MEMBERS(C) \
  30. BOOST_DESCRIBE_PRIVATE_MEMBERS(C)
  31. #else
  32. #if defined(__GNUC__) && __GNUC__ >= 8
  33. # define BOOST_DESCRIBE_PP_UNPACK(...) __VA_OPT__(,) __VA_ARGS__
  34. #else
  35. # define BOOST_DESCRIBE_PP_UNPACK(...) , ##__VA_ARGS__
  36. #endif
  37. #define BOOST_DESCRIBE_BASES_(...) BOOST_DESCRIBE_BASES(__VA_ARGS__)
  38. #define BOOST_DESCRIBE_PUBLIC_MEMBERS_(...) BOOST_DESCRIBE_PUBLIC_MEMBERS(__VA_ARGS__)
  39. #define BOOST_DESCRIBE_PROTECTED_MEMBERS_(...) BOOST_DESCRIBE_PROTECTED_MEMBERS(__VA_ARGS__)
  40. #define BOOST_DESCRIBE_PRIVATE_MEMBERS_(...) BOOST_DESCRIBE_PRIVATE_MEMBERS(__VA_ARGS__)
  41. #define BOOST_DESCRIBE_CLASS(C, Bases, Public, Protected, Private) \
  42. BOOST_DESCRIBE_MAYBE_UNUSED friend BOOST_DESCRIBE_BASES_(C BOOST_DESCRIBE_PP_UNPACK Bases) \
  43. BOOST_DESCRIBE_MAYBE_UNUSED friend BOOST_DESCRIBE_PUBLIC_MEMBERS_(C BOOST_DESCRIBE_PP_UNPACK Public) \
  44. BOOST_DESCRIBE_MAYBE_UNUSED friend BOOST_DESCRIBE_PROTECTED_MEMBERS_(C BOOST_DESCRIBE_PP_UNPACK Protected) \
  45. BOOST_DESCRIBE_MAYBE_UNUSED friend BOOST_DESCRIBE_PRIVATE_MEMBERS_(C BOOST_DESCRIBE_PP_UNPACK Private)
  46. #define BOOST_DESCRIBE_STRUCT(C, Bases, Members) \
  47. static_assert(std::is_class<C>::value || std::is_union<C>::value, "BOOST_DESCRIBE_STRUCT should only be used with class types"); \
  48. BOOST_DESCRIBE_MAYBE_UNUSED BOOST_DESCRIBE_BASES_(C BOOST_DESCRIBE_PP_UNPACK Bases) \
  49. BOOST_DESCRIBE_MAYBE_UNUSED BOOST_DESCRIBE_PUBLIC_MEMBERS_(C BOOST_DESCRIBE_PP_UNPACK Members) \
  50. BOOST_DESCRIBE_MAYBE_UNUSED BOOST_DESCRIBE_PROTECTED_MEMBERS_(C) \
  51. BOOST_DESCRIBE_MAYBE_UNUSED BOOST_DESCRIBE_PRIVATE_MEMBERS_(C)
  52. #endif
  53. } // namespace describe
  54. } // namespace boost
  55. #endif // !defined(BOOST_DESCRIBE_CXX14)
  56. #endif // #ifndef BOOST_DESCRIBE_CLASS_HPP_INCLUDED