make literal constexpr check configurable
This commit is contained in:
parent
44dd56542a
commit
2a0abed6d2
|
@ -63,6 +63,7 @@ OBJECTS_DIR = obj
|
||||||
RCC_DIR = rcc
|
RCC_DIR = rcc
|
||||||
|
|
||||||
QSK_CONFIG += QskDll
|
QSK_CONFIG += QskDll
|
||||||
|
QSK_CONFIG += QskRequireConstexprLiterals
|
||||||
|
|
||||||
linux {
|
linux {
|
||||||
|
|
||||||
|
|
|
@ -458,27 +458,26 @@ namespace QskRgb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define QSK_REQUIRE_CONSTEXPR_LITERAL 1
|
#ifdef QSK_REQUIRE_CONSTEXPR_LITERALS
|
||||||
#ifdef QSK_REQUIRE_CONSTEXPR_LITERAL
|
|
||||||
// RGBA hex string to QRgb with defaulted alpha = 0xFF
|
// RGBA hex string to QRgb with defaulted alpha = 0xFF
|
||||||
static_assert( "#123456"_rgba == 0xFF123456, "not constexpr" );
|
static_assert( "#123456"_rgba == 0xFF123456, "invalid or not constexpr" );
|
||||||
static_assert( "#123456"_argb == 0xFF123456, "not constexpr" );
|
static_assert( "#123456"_argb == 0xFF123456, "invalid or not constexpr" );
|
||||||
|
|
||||||
// ARGB hex string to QRgb with defaulted alpha = 0xFF
|
// ARGB hex string to QRgb with defaulted alpha = 0xFF
|
||||||
static_assert( "#AA112233"_argb == 0xAA112233, "not constexpr" );
|
static_assert( "#AA112233"_argb == 0xAA112233, "invalid or not constexpr" );
|
||||||
static_assert( "#112233AA"_rgba == 0xAA112233, "not constexpr" );
|
static_assert( "#112233AA"_rgba == 0xAA112233, "invalid or not constexpr" );
|
||||||
|
|
||||||
// RGBA hex literal to QRgb with defaulted alpha = 0xFF
|
// RGBA hex literal to QRgb with defaulted alpha = 0xFF
|
||||||
static_assert( 0x112233_rgba == 0xFF112233, "" );
|
static_assert( 0x112233_rgba == 0xFF112233, "invalid or not constexpr" );
|
||||||
static_assert( 0xaabbcc_rgba == 0xFFAABBCC, "" );
|
static_assert( 0xaabbcc_rgba == 0xFFAABBCC, "invalid or not constexpr" );
|
||||||
static_assert( 0xAABBCC_rgba == 0xFFAABBCC, "" );
|
static_assert( 0xAABBCC_rgba == 0xFFAABBCC, "invalid or not constexpr" );
|
||||||
static_assert( 0x112233aa_rgba == 0xaa112233, "" );
|
static_assert( 0x112233aa_rgba == 0xaa112233, "invalid or not constexpr" );
|
||||||
|
|
||||||
// ARGB hex literal to QRgb with defaulted alpha = 0xFF
|
// ARGB hex literal to QRgb with defaulted alpha = 0xFF
|
||||||
static_assert( 0x112233_argb == 0xFF112233, "" );
|
static_assert( 0x112233_argb == 0xFF112233, "invalid or not constexpr" );
|
||||||
static_assert( 0xaabbcc_argb == 0xFFAABBCC, "" );
|
static_assert( 0xaabbcc_argb == 0xFFAABBCC, "invalid or not constexpr" );
|
||||||
static_assert( 0xAABBCC_argb == 0xFFAABBCC, "" );
|
static_assert( 0xAABBCC_argb == 0xFFAABBCC, "invalid or not constexpr" );
|
||||||
static_assert( 0x112233aa_argb == 0x112233aa, "" );
|
static_assert( 0x112233aa_argb == 0x112233aa, "invalid or not constexpr" );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -493,8 +492,7 @@ namespace QskRgb
|
||||||
const auto g = ( argb >> ( len == max ? 16 : 8 ) ) & 0xFF;
|
const auto g = ( argb >> ( len == max ? 16 : 8 ) ) & 0xFF;
|
||||||
const auto b = ( argb >> ( len == max ? 8 : 0 ) ) & 0xFF;
|
const auto b = ( argb >> ( len == max ? 8 : 0 ) ) & 0xFF;
|
||||||
const auto a = ( len == max ? argb & 0xFF : 0xFF );
|
const auto a = ( len == max ? argb & 0xFF : 0xFF );
|
||||||
const auto color = QColor{ r, g, b, a };
|
return { r, g, b, a };
|
||||||
return color;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QSK_EXPORT constexpr QColor operator""_argb(
|
QSK_EXPORT constexpr QColor operator""_argb(
|
||||||
|
@ -506,8 +504,7 @@ namespace QskRgb
|
||||||
const auto g = ( argb >> 8 ) & 0xFF;
|
const auto g = ( argb >> 8 ) & 0xFF;
|
||||||
const auto b = ( argb >> 0 ) & 0xFF;
|
const auto b = ( argb >> 0 ) & 0xFF;
|
||||||
const auto a = ( len == max ? argb >> 24 : 0xFF ) & 0xFF;
|
const auto a = ( len == max ? argb >> 24 : 0xFF ) & 0xFF;
|
||||||
const auto color = QColor{ r, g, b, a };
|
return { r, g, b, a };
|
||||||
return color;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// converts a hex literal from '0xRRGGBB[AA]' to a QColor
|
// converts a hex literal from '0xRRGGBB[AA]' to a QColor
|
||||||
|
|
|
@ -8,6 +8,7 @@ greaterThan( QT_MAJOR_VERSION, 5 ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
contains(QSK_CONFIG, QskDll): DEFINES += QSK_MAKEDLL
|
contains(QSK_CONFIG, QskDll): DEFINES += QSK_MAKEDLL
|
||||||
|
contains(QSK_CONFIG, QskRequireConstexprLiterals): DEFINES += QSK_REQUIRE_CONSTEXPR_LITERALS
|
||||||
|
|
||||||
QSK_SUBDIRS = common graphic nodes controls layouts dialogs inputpanel
|
QSK_SUBDIRS = common graphic nodes controls layouts dialogs inputpanel
|
||||||
INCLUDEPATH *= $${QSK_SUBDIRS}
|
INCLUDEPATH *= $${QSK_SUBDIRS}
|
||||||
|
|
|
@ -56,25 +56,6 @@ void QskRgbLiterals::qrgbLiterals_data()
|
||||||
void QskRgbLiterals::qrgbLiterals()
|
void QskRgbLiterals::qrgbLiterals()
|
||||||
{
|
{
|
||||||
using namespace QskRgb::literals::qrgb;
|
using namespace QskRgb::literals::qrgb;
|
||||||
|
|
||||||
#ifdef QSK_REQUIRE_CONSTEXPR_LITERAL
|
|
||||||
static_assert( "#123456"_rgba == 0xFF123456, "not constexpr" );
|
|
||||||
static_assert( "#123456"_argb == 0xFF123456, "not constexpr" );
|
|
||||||
|
|
||||||
static_assert( "#AA112233"_argb == 0xAA112233, "not constexpr" );
|
|
||||||
static_assert( "#112233AA"_rgba == 0xAA112233, "not constexpr" );
|
|
||||||
|
|
||||||
static_assert( 0x112233_rgba == 0xFF112233, "not constexpr" );
|
|
||||||
static_assert( 0xaabbcc_rgba == 0xFFAABBCC, "not constexpr" );
|
|
||||||
static_assert( 0xAABBCC_rgba == 0xFFAABBCC, "not constexpr" );
|
|
||||||
static_assert( 0x112233aa_rgba == 0xaa112233, "not constexpr" );
|
|
||||||
|
|
||||||
static_assert( 0x112233_argb == 0xFF112233, "not constexpr" );
|
|
||||||
static_assert( 0xaabbcc_argb == 0xFFAABBCC, "not constexpr" );
|
|
||||||
static_assert( 0xAABBCC_argb == 0xFFAABBCC, "not constexpr" );
|
|
||||||
static_assert( 0x112233aa_argb == 0x112233aa, "not constexpr" );
|
|
||||||
#endif
|
|
||||||
|
|
||||||
QFETCH( QRgb, actual );
|
QFETCH( QRgb, actual );
|
||||||
QFETCH( QRgb, expected );
|
QFETCH( QRgb, expected );
|
||||||
QCOMPARE( actual, expected );
|
QCOMPARE( actual, expected );
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
class QskRgbLiterals final : public QObject
|
class QskRgbLiterals final : public QObject
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#include "test_QskRgbLiterals.h"
|
#include "tests_main.h"
|
||||||
#include <QTest>
|
#include <QTest>
|
||||||
|
|
||||||
QTEST_APPLESS_MAIN( QskRgbLiterals )
|
QTEST_APPLESS_MAIN( QskRgbLiterals )
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "test_QskRgbLiterals.h"
|
Loading…
Reference in New Issue