PageRenderTime 122ms CodeModel.GetById 61ms app.highlight 6ms RepoModel.GetById 54ms app.codeStats 0ms

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