StdInc.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * StdInc.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 "../Global.h"
  12. #define VCMI_EDITOR_VERSION "0.2"
  13. #define VCMI_EDITOR_NAME "VCMI Map Editor"
  14. #include <QtWidgets>
  15. #include <QStringList>
  16. #include <QSet>
  17. #include <QVector>
  18. #include <QList>
  19. #include <QString>
  20. #include <QFile>
  21. VCMI_LIB_USING_NAMESPACE
  22. using NumericPointer = typename std::conditional_t<sizeof(void *) == sizeof(unsigned long long),
  23. unsigned long long, unsigned int>;
  24. template<class Type>
  25. NumericPointer data_cast(Type * _pointer)
  26. {
  27. static_assert(sizeof(Type *) == sizeof(NumericPointer),
  28. "Cannot compile for that architecture, see NumericPointer definition");
  29. return reinterpret_cast<NumericPointer>(_pointer);
  30. }
  31. template<class Type>
  32. Type * data_cast(NumericPointer _numeric)
  33. {
  34. static_assert(sizeof(Type *) == sizeof(NumericPointer),
  35. "Cannot compile for that architecture, see NumericPointer definition");
  36. return reinterpret_cast<Type *>(_numeric);
  37. }
  38. inline QString pathToQString(const boost::filesystem::path & path)
  39. {
  40. #ifdef VCMI_WINDOWS
  41. return QString::fromStdWString(path.wstring());
  42. #else
  43. return QString::fromStdString(path.string());
  44. #endif
  45. }
  46. inline boost::filesystem::path qstringToPath(const QString & path)
  47. {
  48. #ifdef VCMI_WINDOWS
  49. return boost::filesystem::path(path.toStdWString());
  50. #else
  51. return boost::filesystem::path(path.toUtf8().data());
  52. #endif
  53. }