OpenXLSX 1.12.1
Modern C++ Excel Library (Fork of OpenXLSX by Kenneth Troldal Balslev)
Loading...
Searching...
No Matches
XLColor.hpp
Go to the documentation of this file.
1/*
2 * OpenXLSX-NX - Modern High-Performance C++ Excel Library
3 *
4 * Original work Copyright (c) 2018-2025, Kenneth Troldal Balslev and OpenXLSX contributors
5 * Modified work Copyright (c) 2026, Curry Tang and OpenXLSX-NX contributors
6 *
7 * Distributed under the BSD 3-Clause License.
8 * See LICENSE.md in the project root or https://opensource.org/licenses/BSD-3-Clause
9 */
10
11#ifndef OPENXLSX_XLCOLOR_HPP
12#define OPENXLSX_XLCOLOR_HPP
13
14#ifdef _MSC_VER // conditionally enable MSVC specific pragmas to avoid other compilers warning about unknown pragmas
15# pragma warning(push)
16# pragma warning(disable : 4251)
17# pragma warning(disable : 4275)
18#endif // _MSC_VER
19
20// ===== External Includes ===== //
21#include <cstdint> // Pull request #276
22#include <string>
23
24// ===== OpenXLSX Includes ===== //
25#include "OpenXLSX-Exports.hpp"
26
27namespace OpenXLSX
28{
31 class OPENXLSX_EXPORT XLColor
32 {
33 friend bool operator==(const XLColor& lhs, const XLColor& rhs);
34 friend bool operator!=(const XLColor& lhs, const XLColor& rhs);
35
36 public:
41
45 XLColor(uint8_t alpha, uint8_t red, uint8_t green, uint8_t blue);
46
50 XLColor(uint8_t red, uint8_t green, uint8_t blue);
51
55 explicit XLColor(std::string_view hexCode);
56
57 XLColor(const XLColor& other);
58
59 XLColor(XLColor&& other) noexcept;
60
62
63 XLColor& operator=(const XLColor& other);
64
65 XLColor& operator=(XLColor&& other) noexcept;
66
70 void set(uint8_t alpha, uint8_t red, uint8_t green, uint8_t blue);
71
75 void set(uint8_t red = 0, uint8_t green = 0, uint8_t blue = 0);
76
80 void set(std::string_view hexCode);
81
85 [[nodiscard]] uint8_t alpha() const;
86
90 [[nodiscard]] uint8_t red() const;
91
95 [[nodiscard]] uint8_t green() const;
96
100 [[nodiscard]] uint8_t blue() const;
101
105 [[nodiscard]] std::string hex() const;
106
107 private:
108 uint8_t m_alpha{255};
109
110 uint8_t m_red{0};
111
112 uint8_t m_green{0};
113
114 uint8_t m_blue{0};
115 };
116
117} // namespace OpenXLSX
118
119namespace OpenXLSX
120{
124 inline bool operator==(const XLColor& lhs, const XLColor& rhs)
125 { return lhs.alpha() == rhs.alpha() and lhs.red() == rhs.red() and lhs.green() == rhs.green() and lhs.blue() == rhs.blue(); }
126
130 inline bool operator!=(const XLColor& lhs, const XLColor& rhs) { return !(lhs == rhs); }
131
132} // namespace OpenXLSX
133
134#ifdef _MSC_VER // conditionally enable MSVC specific pragmas to avoid other compilers warning about unknown pragmas
135# pragma warning(pop)
136#endif // _MSC_VER
137
138#endif // OPENXLSX_XLCOLOR_HPP
XLColor & operator=(const XLColor &other)
uint8_t red() const
Retrieves the red channel value.
Definition XLColor.cpp:130
void set(uint8_t alpha, uint8_t red, uint8_t green, uint8_t blue)
Sets explicit ARGB channels.
Definition XLColor.cpp:70
XLColor(XLColor &&other) noexcept
uint8_t alpha() const
Retrieves the alpha (opacity) channel value.
Definition XLColor.cpp:125
std::string hex() const
Returns the 8-character ARGB hex string representation used in OOXML (e.g., "FFFF0000").
Definition XLColor.cpp:147
XLColor()
Default constructor. Initializes to opaque black (A=255, R=0, G=0, B=0).
uint8_t blue() const
Retrieves the blue channel value.
Definition XLColor.cpp:140
friend bool operator!=(const XLColor &lhs, const XLColor &rhs)
Checks if two colors differ in any of their ARGB channels.
Definition XLColor.hpp:130
friend bool operator==(const XLColor &lhs, const XLColor &rhs)
Checks if two colors have identical ARGB channels.
Definition XLColor.hpp:124
uint8_t green() const
Retrieves the green channel value.
Definition XLColor.cpp:135
XLColor & operator=(XLColor &&other) noexcept
XLColor(const XLColor &other)
Definition IXLCellProvider.hpp:24
bool operator==(const XLCell &lhs, const XLCell &rhs)
Definition XLCell.hpp:314
bool operator!=(const XLCell &lhs, const XLCell &rhs)
Definition XLCell.hpp:321