CodeContract.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #pragma once
  2. #include <cstdlib>
  3. #include <iostream>
  4. #ifndef VALID_REF
  5. #define VALID_REF(p) ((p) != 0)
  6. #define VALID_FN_REF(___3002) ((___3002) != 0)
  7. #endif
  8. #if defined NO_ASSERTS
  9. #ifndef ASSERT
  10. #define ASSERT(___1245)
  11. #endif
  12. #ifndef ASSERT_ONLY
  13. #define ASSERT_ONLY(___1245)
  14. #endif
  15. #else
  16. #ifndef ASSERT_ONLY
  17. #define ASSERT_ONLY(___1245) ___1245
  18. #endif
  19. #if defined NDEBUG
  20. #ifndef ASSERT
  21. template<class T> inline bool checkedAssert(T const& expr) { return (expr ? true : false); } inline bool checkedAssert(char const* expr) { return expr != 0; }
  22. #define ASSERT(___1245) \
  23. do \
  24. { \
  25. if (!checkedAssert(___1245)) \
  26. { \
  27. std::cerr << __FILE__ << ':' << __LINE__ << ':' << "Assertion '" << #___1245 << "' failed."; \
  28. abort(); \
  29. } \
  30. } while (0);
  31. #endif
  32. #else
  33. #ifndef ASSERT
  34. #include <assert.h>
  35. #define ASSERT(___1245) assert(___1245)
  36. #endif
  37. #endif
  38. #endif
  39. #if !defined ASSERT_ONLY_PARAM
  40. #define ASSERT_ONLY_PARAM(___2972) ASSERT_ONLY(___2972)
  41. #endif
  42. #if !defined INVARIANT
  43. #define INVARIANT(___1245) ASSERT(___1245)
  44. #endif
  45. #if !defined REQUIRE
  46. #define REQUIRE(___1245) ASSERT(___1245)
  47. #endif
  48. #if !defined ENSURE
  49. #define ENSURE(___1245) ASSERT(___1245)
  50. #endif
  51. #if !defined ___478
  52. #define ___478(___1245) ASSERT(___1245)
  53. #endif
  54. #ifdef VERIFY
  55. #undef VERIFY
  56. #endif
  57. #ifndef VERIFY
  58. #if defined NO_ASSERTS
  59. #define VERIFY(___1245) ((void)(___1245))
  60. #elif defined NDEBUG
  61. #define VERIFY(___1245) \
  62. do \
  63. { \
  64. if ((___1245) == 0) \
  65. { \
  66. std::cerr << __FILE__ << ':' << __LINE__ << ':' << "Assertion '" << #___1245 << "' failed."; \
  67. abort(); \
  68. } \
  69. } while(0);
  70. #else
  71. #define VERIFY(___1245) assert(___1245)
  72. #endif
  73. #endif
  74. #if !defined IMPLICATION
  75. #define IMPLICATION(___2894,___3258) (!(___2894) || (___3258))
  76. #endif
  77. #if !defined EQUIVALENCE
  78. #define EQUIVALENCE(___2894,___3258) ((___2894) == (___3258))
  79. #endif
  80. #define VALID_MAP_KEY(key,map) (map.find(key) != map.end())
  81. #if !defined VALID_REF_OR_NULL
  82. #define VALID_REF_OR_NULL(p) (VALID_REF(p) || p == 0)
  83. #endif
  84. #if !defined VALID_BOOLEAN
  85. #define VALID_BOOLEAN(b) ((b) == 1 || (b) == 0)
  86. #endif
  87. #if !defined VALID_ENUM
  88. #define VALID_ENUM(___4314, type) (0 <= (___4314) && (___4314) < END_##type)
  89. #endif
  90. #if !defined VALID_CLASS_ENUM
  91. #define VALID_CLASS_ENUM(e) (static_cast<std::decay<decltype((e))>::type>(0) <= (e) && (e) < std::decay<decltype((e))>::type::END_ENUM)
  92. #endif