/src/libtomahawk/thirdparty/kdsingleapplicationguard/kdtoolsglobal.cpp

http://github.com/tomahawk-player/tomahawk · C++ · 32 lines · 26 code · 6 blank · 0 comment · 12 complexity · 7415d1beede3dbe4de562432804b853d MD5 · raw file

  1. #include "kdtoolsglobal.h"
  2. #include <QByteArray>
  3. #include <algorithm>
  4. namespace {
  5. struct Version {
  6. unsigned char v[3];
  7. };
  8. static inline bool operator<( const Version & lhs, const Version & rhs ) {
  9. return std::lexicographical_compare( lhs.v, lhs.v + 3, rhs.v, rhs.v + 3 );
  10. }
  11. static inline bool operator==( const Version & lhs, const Version & rhs ) {
  12. return std::equal( lhs.v, lhs.v + 3, rhs.v );
  13. }
  14. KDTOOLS_MAKE_RELATION_OPERATORS( Version, static inline )
  15. }
  16. static Version kdParseQtVersion( const char * const version ) {
  17. if ( !version || qstrlen( version ) < 5 || version[1] != '.' || version[3] != '.' || ( version[5] != 0 && version[5] != '.' && version[5] != '-' ) )
  18. return Version(); // parse error
  19. const Version result = { { version[0] - '0', version[2] - '0', version[4] - '0' } };
  20. return result;
  21. }
  22. bool _kdCheckQtVersion_impl( int major, int minor, int patchlevel ) {
  23. static const Version actual = kdParseQtVersion( qVersion() ); // do this only once each run...
  24. const Version requested = { { major, minor, patchlevel } };
  25. return actual >= requested;
  26. }