Commit 6496415a authored by Waqar Ahmed's avatar Waqar Ahmed Committed by Tomaz Canabrava
Browse files

Make the Character/Character color classes constexpr

parent 304305f7
......@@ -62,11 +62,11 @@ public:
* @param _real Indicate whether this character really exists, or exists
* simply as place holder.
*/
explicit inline Character(uint _c = ' ',
CharacterColor _f = CharacterColor(COLOR_SPACE_DEFAULT, DEFAULT_FORE_COLOR),
CharacterColor _b = CharacterColor(COLOR_SPACE_DEFAULT, DEFAULT_BACK_COLOR),
RenditionFlags _r = DEFAULT_RENDITION,
bool _real = true)
explicit constexpr Character(uint _c = ' ',
CharacterColor _f = CharacterColor(COLOR_SPACE_DEFAULT, DEFAULT_FORE_COLOR),
CharacterColor _b = CharacterColor(COLOR_SPACE_DEFAULT, DEFAULT_BACK_COLOR),
RenditionFlags _r = DEFAULT_RENDITION,
bool _real = true)
: character(_c)
, rendition(_r)
, foregroundColor(_f)
......@@ -106,21 +106,21 @@ public:
/**
* returns true if the format (color, rendition flag) of the compared characters is equal
*/
bool equalsFormat(const Character &other) const;
constexpr bool equalsFormat(const Character &other) const;
/**
* Compares two characters and returns true if they have the same unicode character value,
* rendition and colors.
*/
friend bool operator==(const Character &a, const Character &b);
friend constexpr bool operator==(const Character &a, const Character &b);
/**
* Compares two characters and returns true if they have different unicode character values,
* renditions or colors.
*/
friend bool operator!=(const Character &a, const Character &b);
friend constexpr bool operator!=(const Character &a, const Character &b);
inline bool isSpace() const
constexpr bool isSpace() const
{
if (rendition & RE_EXTENDED_CHAR) {
return false;
......@@ -129,7 +129,7 @@ public:
}
}
inline int width() const
int width() const
{
return width(character);
}
......@@ -155,21 +155,21 @@ public:
}
};
inline bool operator==(const Character &a, const Character &b)
constexpr bool operator==(const Character &a, const Character &b)
{
return a.character == b.character && a.equalsFormat(b);
}
inline bool operator!=(const Character &a, const Character &b)
constexpr bool operator!=(const Character &a, const Character &b)
{
return !operator==(a, b);
}
inline bool Character::equalsFormat(const Character &other) const
constexpr bool Character::equalsFormat(const Character &other) const
{
return backgroundColor == other.backgroundColor && foregroundColor == other.foregroundColor && rendition == other.rendition;
}
}
Q_DECLARE_TYPEINFO(Konsole::Character, Q_MOVABLE_TYPE);
Q_DECLARE_TYPEINFO(Konsole::Character, Q_PRIMITIVE_TYPE);
#endif // CHARACTER_H
......@@ -92,7 +92,7 @@ class CharacterColor
public:
/** Constructs a new CharacterColor whose color and color space are undefined. */
CharacterColor()
constexpr CharacterColor()
: _colorSpace(COLOR_SPACE_UNDEFINED)
, _u(0)
, _v(0)
......@@ -110,7 +110,7 @@ public:
*
* TODO : Add documentation about available color spaces.
*/
CharacterColor(quint8 colorSpace, int co)
constexpr CharacterColor(quint8 colorSpace, int co)
: _colorSpace(colorSpace)
, _u(0)
, _v(0)
......@@ -137,11 +137,11 @@ public:
}
}
quint8 colorSpace() const
constexpr quint8 colorSpace() const
{
return _colorSpace;
}
void termColor(int *u, int *v, int *w)
constexpr void termColor(int *u, int *v, int *w)
{
*u = _u;
*v = _v;
......@@ -151,7 +151,7 @@ public:
/**
* Returns true if this character color entry is valid.
*/
bool isValid() const
constexpr bool isValid() const
{
return _colorSpace != COLOR_SPACE_UNDEFINED;
}
......@@ -178,18 +178,18 @@ public:
* The @p base is only used if this color is one of the 16 system colors, otherwise
* it is ignored.
*/
QColor color(const QColor *base) const;
constexpr QColor color(const QColor *base) const;
/**
* Compares two colors and returns true if they represent the same color value and
* use the same color space.
*/
friend bool operator==(const CharacterColor &a, const CharacterColor &b);
friend constexpr bool operator==(const CharacterColor &a, const CharacterColor &b);
/**
* Compares two colors and returns true if they represent different color values
* or use different color spaces.
*/
friend bool operator!=(const CharacterColor &a, const CharacterColor &b);
friend constexpr bool operator!=(const CharacterColor &a, const CharacterColor &b);
private:
quint8 _colorSpace;
......@@ -200,17 +200,17 @@ private:
quint8 _w;
};
inline bool operator==(const CharacterColor &a, const CharacterColor &b)
constexpr bool operator==(const CharacterColor &a, const CharacterColor &b)
{
return a._colorSpace == b._colorSpace && a._u == b._u && a._v == b._v && a._w == b._w;
}
inline bool operator!=(const CharacterColor &a, const CharacterColor &b)
constexpr bool operator!=(const CharacterColor &a, const CharacterColor &b)
{
return !operator==(a, b);
}
inline const QColor color256(quint8 u, const QColor *base)
constexpr QColor color256(quint8 u, const QColor *base)
{
// 0.. 16: system colors
if (u < 8) {
......@@ -236,7 +236,7 @@ inline const QColor color256(quint8 u, const QColor *base)
return QColor(gray, gray, gray);
}
inline QColor CharacterColor::color(const QColor *base) const
constexpr QColor CharacterColor::color(const QColor *base) const
{
switch (_colorSpace) {
case COLOR_SPACE_DEFAULT:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment