https://bugs.documentfoundation.org/show_bug.cgi?id=169155
Bug ID: 169155
Summary: Use o3tl::enumarray to simplify data arrays
Product: LibreOffice
Version: unspecified
Hardware: All
OS: All
Status: UNCONFIRMED
Severity: normal
Priority: medium
Component: LibreOffice
Assignee: [email protected]
Reporter: [email protected]
In LibreOffice C++ code, there are many cases when you want to use some string
literals or even numerical values as some data that you need to use in C++
code. Traditionally, in the code inherited from the old C days, these were
defined as symbolic constants using #define and char* or other literals.
Using modern C++ in LibreOffice, one may use o3tl::enumarray to create such
arrays of values.
Example
Using #define, you may have seen definitions like this:
const char[] FRAME_PROPNAME_ASCII_DISPATCHRECORDERSUPPLIER =
"DispatchRecorderSupplier";
const char[] FRAME_PROPNAME_ASCII_ISHIDDEN = "IsHidden";
inline constexpr OUString FRAME_PROPNAME_ASCII_LAYOUTMANAGER = "LayoutManager";
And also, the relevant states:
#define FRAME_PROPHANDLE_DISPATCHRECORDERSUPPLIER 0
#define FRAME_PROPHANDLE_ISHIDDEN 1
You may turn that into:
enum class FramePropNameASCII
{
DispatcherRecorderSupplier,
IsHidden,
LAST=IsHidden
}
Don't forget to add LAST. It is required.
And then:
constexpr o3tl::enumarray<FramePropNameASCII, OUString> FramePropName = {
u"DispatchRecorderSupplier"_ustr,
u"IsHidden"_ustr
};
The names will be more readable this way. The usage is quite easy. For example,
one can use [] to access the relevant string literal.
--
You are receiving this mail because:
You are the assignee for the bug.