2
0

WinIncludes.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. //===- WinIncludes.h --------------------------------------------*- C++ -*-===//
  2. ///////////////////////////////////////////////////////////////////////////////
  3. // //
  4. // WinIncludes.h //
  5. // Copyright (C) Microsoft Corporation. All rights reserved. //
  6. // This file is distributed under the University of Illinois Open Source //
  7. // License. See LICENSE.TXT for details. //
  8. // //
  9. ///////////////////////////////////////////////////////////////////////////////
  10. #pragma once
  11. #ifdef _MSC_VER
  12. #define NOATOM 1
  13. #define NOGDICAPMASKS 1
  14. #define NOMETAFILE 1
  15. #define NOMINMAX 1
  16. #define NOOPENFILE 1
  17. #define NORASTEROPS 1
  18. #define NOSCROLL 1
  19. #define NOSOUND 1
  20. #define NOSYSMETRICS 1
  21. #define NOWH 1
  22. #define NOCOMM 1
  23. #define NOKANJI 1
  24. #define NOCRYPT 1
  25. #define NOMCX 1
  26. #define WIN32_LEAN_AND_MEAN 1
  27. #define VC_EXTRALEAN 1
  28. #define NONAMELESSSTRUCT 1
  29. #include <windows.h>
  30. #include <unknwn.h>
  31. #include <atlbase.h> // atlbase.h needs to come before strsafe.h
  32. #include <strsafe.h>
  33. #include <intsafe.h>
  34. #include <ObjIdl.h>
  35. // Support older atlbase.h if needed
  36. #ifndef _ATL_DECLSPEC_ALLOCATOR
  37. #define _ATL_DECLSPEC_ALLOCATOR
  38. #endif
  39. /// Swap two ComPtr classes.
  40. template <class T> void swap(CComHeapPtr<T> &a, CComHeapPtr<T> &b) {
  41. T *c(a.m_pData);
  42. a.m_pData = b.m_pData;
  43. b.m_pData = c;
  44. }
  45. #else // _MSC_VER
  46. #include "dxc/Support/WinAdapter.h"
  47. #ifdef __cplusplus
  48. // Define operator overloads to enable bit operations on enum values that are
  49. // used to define flags. Use DEFINE_ENUM_FLAG_OPERATORS(YOUR_TYPE) to enable these
  50. // operators on YOUR_TYPE.
  51. extern "C++" {
  52. template <size_t S>
  53. struct _ENUM_FLAG_INTEGER_FOR_SIZE;
  54. template <>
  55. struct _ENUM_FLAG_INTEGER_FOR_SIZE<1>
  56. {
  57. typedef int8_t type;
  58. };
  59. template <>
  60. struct _ENUM_FLAG_INTEGER_FOR_SIZE<2>
  61. {
  62. typedef int16_t type;
  63. };
  64. template <>
  65. struct _ENUM_FLAG_INTEGER_FOR_SIZE<4>
  66. {
  67. typedef int32_t type;
  68. };
  69. // used as an approximation of std::underlying_type<T>
  70. template <class T>
  71. struct _ENUM_FLAG_SIZED_INTEGER
  72. {
  73. typedef typename _ENUM_FLAG_INTEGER_FOR_SIZE<sizeof(T)>::type type;
  74. };
  75. }
  76. #define DEFINE_ENUM_FLAG_OPERATORS(ENUMTYPE) \
  77. extern "C++" { \
  78. inline ENUMTYPE operator | (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)a) | ((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)b)); } \
  79. inline ENUMTYPE &operator |= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type &)a) |= ((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)b)); } \
  80. inline ENUMTYPE operator & (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)a) & ((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)b)); } \
  81. inline ENUMTYPE &operator &= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type &)a) &= ((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)b)); } \
  82. inline ENUMTYPE operator ~ (ENUMTYPE a) { return ENUMTYPE(~((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)a)); } \
  83. inline ENUMTYPE operator ^ (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)a) ^ ((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)b)); } \
  84. inline ENUMTYPE &operator ^= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type &)a) ^= ((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)b)); } \
  85. }
  86. #else
  87. #define DEFINE_ENUM_FLAG_OPERATORS(ENUMTYPE) // NOP, C allows these operators.
  88. #endif
  89. #endif // _MSC_VER