mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 22:02:44 +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
					
				
					 1 changed files with 15 additions and 6 deletions
				
			
		|  | @ -12,7 +12,16 @@ from pathlib import Path | ||||||
| from typing import List, Optional, Type | 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 |     Byte = 1 | ||||||
|     ASCII = 2 |     ASCII = 2 | ||||||
|     UnsignedShort = 3 |     UnsignedShort = 3 | ||||||
|  | @ -26,12 +35,12 @@ class TIFFType(Enum): | ||||||
|     UTF8 = 129 |     UTF8 = 129 | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class Predictor(Enum): | class Predictor(EnumWithExportName): | ||||||
|     NoPrediction = 1 |     NoPrediction = 1 | ||||||
|     HorizontalDifferencing = 2 |     HorizontalDifferencing = 2 | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class Compression(Enum): | class Compression(EnumWithExportName): | ||||||
|     NoCompression = 1 |     NoCompression = 1 | ||||||
|     CCITT = 2 |     CCITT = 2 | ||||||
|     Group3Fax = 3 |     Group3Fax = 3 | ||||||
|  | @ -75,8 +84,8 @@ LICENSE = R"""/* | ||||||
|  */""" |  */""" | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def export_enum_to_cpp(e: Type[Enum], special_name: Optional[str] = None) -> str: | def export_enum_to_cpp(e: Type[EnumWithExportName], special_name: Optional[str] = None) -> str: | ||||||
|     output = f'enum class {special_name if special_name else e.__name__} {{\n' |     output = f'enum class {e.export_name()} {{\n' | ||||||
| 
 | 
 | ||||||
|     for entry in e: |     for entry in e: | ||||||
|         output += f'    {entry.name} = {entry.value},\n' |         output += f'    {entry.name} = {entry.value},\n' | ||||||
|  | @ -238,7 +247,7 @@ class Metadata; | ||||||
| 
 | 
 | ||||||
| namespace TIFF {{ | namespace TIFF {{ | ||||||
| 
 | 
 | ||||||
| {export_enum_to_cpp(TIFFType, 'Type')} | {export_enum_to_cpp(TIFFType)} | ||||||
| 
 | 
 | ||||||
| template<OneOf<u32, i32> x32> | template<OneOf<u32, i32> x32> | ||||||
| struct Rational {{ | struct Rational {{ | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Lucas CHOLLET
						Lucas CHOLLET