CodeContract.h 3.5 KB

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