mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-30 03:20:28 +00:00
LibGfx/TIFF: Add an intrinsic way to get the exportable name of Enums
The `TIFFType` enum is exported with a different name to C++. This change of behavior was handled by manually setting the parameter of a function. However, we will soon need the exported name in more places, so let's make it a property of the Enum itself.
This commit is contained in:
parent
1d345109c4
commit
f00e9540d5
Notes:
sideshowbarker
2024-07-16 23:52:10 +09:00
Author: https://github.com/LucasChollet Commit: https://github.com/SerenityOS/serenity/commit/f00e9540d5 Pull-request: https://github.com/SerenityOS/serenity/pull/22139 Reviewed-by: https://github.com/nico ✅
1 changed files with 15 additions and 6 deletions
|
@ -12,7 +12,16 @@ from pathlib import Path
|
|||
from typing import List, Optional, Type
|
||||
|
||||
|
||||
class TIFFType(Enum):
|
||||
class EnumWithExportName(Enum):
|
||||
@classmethod
|
||||
def export_name(cls) -> str:
|
||||
return cls.__name__
|
||||
|
||||
|
||||
class TIFFType(EnumWithExportName):
|
||||
@classmethod
|
||||
def export_name(cls) -> str:
|
||||
return "Type"
|
||||
Byte = 1
|
||||
ASCII = 2
|
||||
UnsignedShort = 3
|
||||
|
@ -26,12 +35,12 @@ class TIFFType(Enum):
|
|||
UTF8 = 129
|
||||
|
||||
|
||||
class Predictor(Enum):
|
||||
class Predictor(EnumWithExportName):
|
||||
NoPrediction = 1
|
||||
HorizontalDifferencing = 2
|
||||
|
||||
|
||||
class Compression(Enum):
|
||||
class Compression(EnumWithExportName):
|
||||
NoCompression = 1
|
||||
CCITT = 2
|
||||
Group3Fax = 3
|
||||
|
@ -75,8 +84,8 @@ LICENSE = R"""/*
|
|||
*/"""
|
||||
|
||||
|
||||
def export_enum_to_cpp(e: Type[Enum], special_name: Optional[str] = None) -> str:
|
||||
output = f'enum class {special_name if special_name else e.__name__} {{\n'
|
||||
def export_enum_to_cpp(e: Type[EnumWithExportName], special_name: Optional[str] = None) -> str:
|
||||
output = f'enum class {e.export_name()} {{\n'
|
||||
|
||||
for entry in e:
|
||||
output += f' {entry.name} = {entry.value},\n'
|
||||
|
@ -238,7 +247,7 @@ class Metadata;
|
|||
|
||||
namespace TIFF {{
|
||||
|
||||
{export_enum_to_cpp(TIFFType, 'Type')}
|
||||
{export_enum_to_cpp(TIFFType)}
|
||||
|
||||
template<OneOf<u32, i32> x32>
|
||||
struct Rational {{
|
||||
|
|
Loading…
Reference in a new issue