pod.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/meta/pod.h
  3. // Purpose: Test if a type is POD
  4. // Author: Vaclav Slavik, Jaakko Salli
  5. // Created: 2010-06-14
  6. // Copyright: (c) wxWidgets team
  7. // Licence: wxWindows licence
  8. /////////////////////////////////////////////////////////////////////////////
  9. #ifndef _WX_META_POD_H_
  10. #define _WX_META_POD_H_
  11. #include "wx/defs.h"
  12. //
  13. // TODO: Use TR1 is_pod<> implementation where available. VC9 SP1 has it
  14. // in tr1 namespace, VC10 has it in std namespace. GCC 4.2 has it in
  15. // <tr1/type_traits>, while GCC 4.3 and later have it in <type_traits>.
  16. //
  17. // This macro declares something called "value" inside a class declaration.
  18. //
  19. // It has to be used because VC6 doesn't handle initialization of the static
  20. // variables in the class declaration itself while BCC5.82 doesn't understand
  21. // enums (it compiles the template fine but can't use it later)
  22. #if defined(__VISUALC__) && !wxCHECK_VISUALC_VERSION(7)
  23. #define wxDEFINE_TEMPLATE_BOOL_VALUE(val) enum { value = val }
  24. #else
  25. #define wxDEFINE_TEMPLATE_BOOL_VALUE(val) static const bool value = val
  26. #endif
  27. // Helper to decide if an object of type T is POD (Plain Old Data)
  28. template<typename T>
  29. struct wxIsPod
  30. {
  31. wxDEFINE_TEMPLATE_BOOL_VALUE(false);
  32. };
  33. // Macro to add wxIsPod<T> specialization for given type that marks it
  34. // as Plain Old Data:
  35. #define WX_DECLARE_TYPE_POD(type) \
  36. template<> struct wxIsPod<type> \
  37. { \
  38. wxDEFINE_TEMPLATE_BOOL_VALUE(true); \
  39. };
  40. WX_DECLARE_TYPE_POD(bool)
  41. WX_DECLARE_TYPE_POD(unsigned char)
  42. WX_DECLARE_TYPE_POD(signed char)
  43. WX_DECLARE_TYPE_POD(unsigned int)
  44. WX_DECLARE_TYPE_POD(signed int)
  45. WX_DECLARE_TYPE_POD(unsigned short int)
  46. WX_DECLARE_TYPE_POD(signed short int)
  47. WX_DECLARE_TYPE_POD(signed long int)
  48. WX_DECLARE_TYPE_POD(unsigned long int)
  49. WX_DECLARE_TYPE_POD(float)
  50. WX_DECLARE_TYPE_POD(double)
  51. WX_DECLARE_TYPE_POD(long double)
  52. #if wxWCHAR_T_IS_REAL_TYPE
  53. WX_DECLARE_TYPE_POD(wchar_t)
  54. #endif
  55. #ifdef wxLongLong_t
  56. WX_DECLARE_TYPE_POD(wxLongLong_t)
  57. WX_DECLARE_TYPE_POD(wxULongLong_t)
  58. #endif
  59. // Visual C++ 6.0 can't compile partial template specializations and as this is
  60. // only an optimization, we can live with pointers not being recognized as
  61. // POD types under VC6
  62. #if !defined(__VISUALC__) || wxCHECK_VISUALC_VERSION(7)
  63. // pointers are Plain Old Data:
  64. template<typename T>
  65. struct wxIsPod<T*>
  66. {
  67. static const bool value = true;
  68. };
  69. template<typename T>
  70. struct wxIsPod<const T*>
  71. {
  72. static const bool value = true;
  73. };
  74. #endif // !VC++ < 7
  75. #endif // _WX_META_POD_H_