Bug 169155 - Use o3tl::enumarray to simplify data arrays
Summary: Use o3tl::enumarray to simplify data arrays
Status: UNCONFIRMED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: LibreOffice (show other bugs)
Version:
(earliest affected)
unspecified
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-10-30 15:05 UTC by Hossein
Modified: 2025-10-30 15:05 UTC (History)
0 users

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Hossein 2025-10-30 15:05:36 UTC
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.