qmsetup_global.h 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #ifndef QMSETUP_GLOBAL_H
  2. #define QMSETUP_GLOBAL_H
  3. // Export define
  4. #ifdef _WIN32
  5. # define QMSETUP_DECL_EXPORT __declspec(dllexport)
  6. # define QMSETUP_DECL_IMPORT __declspec(dllimport)
  7. #else
  8. # define QMSETUP_DECL_EXPORT __attribute__((visibility("default")))
  9. # define QMSETUP_DECL_IMPORT __attribute__((visibility("default")))
  10. #endif
  11. // Qt style P-IMPL
  12. #define QMSETUP_DECL_PRIVATE(Class) \
  13. inline Class##Private *d_func() { \
  14. return reinterpret_cast<Class##Private *>(d_ptr.get()); \
  15. } \
  16. inline const Class##Private *d_func() const { \
  17. return reinterpret_cast<const Class##Private *>(d_ptr.get()); \
  18. } \
  19. friend class Class##Private;
  20. #define QMSETUP_DECL_PUBLIC(Class) \
  21. inline Class *q_func() { \
  22. return static_cast<Class *>(q_ptr); \
  23. } \
  24. inline const Class *q_func() const { \
  25. return static_cast<const Class *>(q_ptr); \
  26. } \
  27. friend class Class;
  28. #define QM_D(Class) Class##Private *const d = d_func()
  29. #define QM_Q(Class) Class *const q = q_func()
  30. // Some classes do not permit copies to be made of an object.
  31. #define QMSETUP_DISABLE_COPY(Class) \
  32. Class(const Class &) = delete; \
  33. Class &operator=(const Class &) = delete;
  34. #define QMSETUP_DISABLE_MOVE(Class) \
  35. Class(Class &&) = delete; \
  36. Class &operator=(Class &&) = delete;
  37. #define QMSETUP_DISABLE_COPY_MOVE(Class) \
  38. QMSETUP_DISABLE_COPY(Class) \
  39. QMSETUP_DISABLE_MOVE(Class)
  40. // Logging functions
  41. #ifndef QMSETUP_TRACE
  42. # ifdef QMSETUP_YES_TRACE
  43. # define QMSETUP_TRACE_(fmt, ...) \
  44. printf("%s:%d:trace: " fmt "%s\n", __FILE__, __LINE__, __VA_ARGS__)
  45. # define QMSETUP_TRACE(...) QMSETUP_TRACE_(__VA_ARGS__, "")
  46. # else
  47. # define QMSETUP_TRACE(...)
  48. # endif
  49. #endif
  50. #ifndef QMSETUP_DEBUG
  51. # ifndef QMSETUP_NO_DEBUG
  52. # define QMSETUP_DEBUG_(fmt, ...) \
  53. printf("%s:%d:debug: " fmt "%s\n", __FILE__, __LINE__, __VA_ARGS__)
  54. # define QMSETUP_DEBUG(...) QMSETUP_DEBUG_(__VA_ARGS__, "")
  55. # else
  56. # define QMSETUP_DEBUG(...)
  57. # endif
  58. #endif
  59. #ifndef QMSETUP_WARNING
  60. # ifndef QMSETUP_NO_WARNING
  61. # define QMSETUP_WARNING_(fmt, ...) \
  62. printf("%s:%d:warning: " fmt "%s\n", __FILE__, __LINE__, __VA_ARGS__)
  63. # define QMSETUP_WARNING(...) QMSETUP_WARNING_(__VA_ARGS__, "")
  64. # else
  65. # define QMSETUP_WARNING(...)
  66. # endif
  67. #endif
  68. #ifndef QMSETUP_FATAL
  69. # ifndef QMSETUP_NO_FATAL
  70. # define QMSETUP_FATAL_(fmt, ...) \
  71. (fprintf(stderr, "%s:%d:fatal: " fmt "%s\n", __FILE__, __LINE__, __VA_ARGS__), std::abort())
  72. # define QMSETUP_FATAL(...) QMSETUP_FATAL_(__VA_ARGS__, "")
  73. # else
  74. # define QMSETUP_FATAL(...)
  75. # endif
  76. #endif
  77. // Utils
  78. #define QM_UNUSED(X) (void) X;
  79. #endif // QMSETUP_GLOBAL_H