common.h 914 B

123456789101112131415161718192021222324252627282930313233
  1. /*
  2. * common.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "StdInc.h"
  12. namespace MMAI
  13. {
  14. // Enum-to-int need C++23 to use std::to_underlying
  15. // https://en.cppreference.com/w/cpp/utility/to_underlying
  16. #define EI(enum_value) static_cast<int>(enum_value)
  17. #define ASSERT(cond, msg) \
  18. if(!(cond)) \
  19. throw std::runtime_error(std::string("Assertion failed in ") + boost::filesystem::path(__FILE__).filename().string() + ": " + msg)
  20. #define THROW_FORMAT(message, formatting_elems) throw std::runtime_error(boost::str(boost::format(message) % formatting_elems))
  21. static const bool MMAI_VERBOSE = []()
  22. {
  23. const char * envvar = std::getenv("MMAI_VERBOSE");
  24. return envvar != nullptr && std::strcmp(envvar, "1") == 0;
  25. }();
  26. }