OpenXLSX 1.9.1
Loading...
Searching...
No Matches
XLColor.hpp
Go to the documentation of this file.
1#ifndef OPENXLSX_XLCOLOR_HPP
2#define OPENXLSX_XLCOLOR_HPP
3
4#ifdef _MSC_VER // conditionally enable MSVC specific pragmas to avoid other compilers warning about unknown pragmas
5# pragma warning(push)
6# pragma warning(disable : 4251)
7# pragma warning(disable : 4275)
8#endif // _MSC_VER
9
10// ===== External Includes ===== //
11#include <cstdint> // Pull request #276
12#include <string>
13
14// ===== OpenXLSX Includes ===== //
15#include "OpenXLSX-Exports.hpp"
16
17namespace OpenXLSX
18{
21 class OPENXLSX_EXPORT XLColor
22 {
23 friend bool operator==(const XLColor& lhs, const XLColor& rhs);
24 friend bool operator!=(const XLColor& lhs, const XLColor& rhs);
25
26 public:
31
35 XLColor(uint8_t alpha, uint8_t red, uint8_t green, uint8_t blue);
36
40 XLColor(uint8_t red, uint8_t green, uint8_t blue);
41
45 explicit XLColor(std::string_view hexCode);
46
47 XLColor(const XLColor& other);
48
49 XLColor(XLColor&& other) noexcept;
50
52
53 XLColor& operator=(const XLColor& other);
54
55 XLColor& operator=(XLColor&& other) noexcept;
56
60 void set(uint8_t alpha, uint8_t red, uint8_t green, uint8_t blue);
61
65 void set(uint8_t red = 0, uint8_t green = 0, uint8_t blue = 0);
66
70 void set(std::string_view hexCode);
71
75 [[nodiscard]] uint8_t alpha() const;
76
80 [[nodiscard]] uint8_t red() const;
81
85 [[nodiscard]] uint8_t green() const;
86
90 [[nodiscard]] uint8_t blue() const;
91
95 [[nodiscard]] std::string hex() const;
96
97 private:
98 uint8_t m_alpha{255};
99
100 uint8_t m_red{0};
101
102 uint8_t m_green{0};
103
104 uint8_t m_blue{0};
105 };
106
107} // namespace OpenXLSX
108
109namespace OpenXLSX
110{
114 inline bool operator==(const XLColor& lhs, const XLColor& rhs)
115 { return lhs.alpha() == rhs.alpha() and lhs.red() == rhs.red() and lhs.green() == rhs.green() and lhs.blue() == rhs.blue(); }
116
120 inline bool operator!=(const XLColor& lhs, const XLColor& rhs) { return !(lhs == rhs); }
121
122} // namespace OpenXLSX
123
124#ifdef _MSC_VER // conditionally enable MSVC specific pragmas to avoid other compilers warning about unknown pragmas
125# pragma warning(pop)
126#endif // _MSC_VER
127
128#endif // OPENXLSX_XLCOLOR_HPP
Definition XLColor.hpp:22
XLColor & operator=(const XLColor &other)
uint8_t red() const
Retrieves the red channel value.
Definition XLColor.cpp:120
XLColor(XLColor &&other) noexcept
uint8_t alpha() const
Retrieves the alpha (opacity) channel value.
Definition XLColor.cpp:115
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:130
uint8_t green() const
Retrieves the green channel value.
Definition XLColor.cpp:125
XLColor & operator=(XLColor &&other) noexcept
XLColor(const XLColor &other)
Definition IZipArchive.hpp:18
bool operator==(const XLCell &lhs, const XLCell &rhs)
Definition XLCell.hpp:304
bool operator!=(const XLCell &lhs, const XLCell &rhs)
Definition XLCell.hpp:311