Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Utilities
Konsole
Commits
6496415a
Commit
6496415a
authored
Oct 30, 2021
by
Waqar Ahmed
Committed by
Tomaz Canabrava
Nov 15, 2021
Browse files
Make the Character/Character color classes constexpr
parent
304305f7
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/characters/Character.h
View file @
6496415a
...
...
@@ -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_
MOVABL
E_TYPE
);
Q_DECLARE_TYPEINFO
(
Konsole
::
Character
,
Q_
PRIMITIV
E_TYPE
);
#endif // CHARACTER_H
src/characters/CharacterColor.h
View file @
6496415a
...
...
@@ -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
)
const
expr
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
:
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment