Porytiles
Loading...
Searching...
No Matches
porytiles::HeaderEnumMapProvider Class Referencefinal

Loads a field's name/value mappings from a C/C++ header used by a decomp project. More...

#include <header_enum_map_provider.hpp>

Inheritance diagram for porytiles::HeaderEnumMapProvider:
[legend]
Collaboration diagram for porytiles::HeaderEnumMapProvider:
[legend]

Public Member Functions

 HeaderEnumMapProvider (std::filesystem::path header_path, EnumDefinition definition, gsl::not_null< const TextFormatter * > format, gsl::not_null< const UserDiagnostics * > diag)
 Constructs a provider that will load from the specified header file.
 
ChainableResult< std::uint32_t > lookup (const std::string &name) const override
 Looks up the numeric value for a constant name.
 
ChainableResult< std::string > lookup (std::uint32_t value) const override
 Looks up the constant name for a numeric value.
 
- Public Member Functions inherited from porytiles::EnumMapProvider
virtual ~EnumMapProvider ()=default
 

Detailed Description

Loads a field's name/value mappings from a C/C++ header used by a decomp project.

One provider serves one field. What field it serves, which header it reads, the shared name prefix, the names to skip, and the acceptable declaration styles all come from the EnumDefinition passed at construction, so a single class covers behavior, terrain, encounter, and any future field. Two declaration styles are understood:

Define format:

#define MB_NORMAL 0x00
#define MB_TALL_GRASS 0x02

Enum format:

MB_NORMAL,
MB_TALL_GRASS, // optional comment

In the enum format, values are assigned sequentially starting from 0. Both formats support decimal and hexadecimal values (for define format). The EnumDefinition's HeaderFormat selects which styles are read: defines only, enums only, or either (defines first, then enums). During the scan, names that lack the definition's prefix, names in the definition's skip set, and values that exceed the field's maximum are silently ignored, so an unrelated or over-wide constant in a shared header is simply not a mapping. The provider loads lazily on first lookup and caches the result.

Definition at line 46 of file header_enum_map_provider.hpp.

Constructor & Destructor Documentation

◆ HeaderEnumMapProvider()

porytiles::HeaderEnumMapProvider::HeaderEnumMapProvider ( std::filesystem::path  header_path,
EnumDefinition  definition,
gsl::not_null< const TextFormatter * >  format,
gsl::not_null< const UserDiagnostics * >  diag 
)
inline

Constructs a provider that will load from the specified header file.

The provider reads mappings from the given header lazily when first accessed via lookup(), then caches them for subsequent lookups. The EnumDefinition fully determines what is scanned and how.

Parameters
header_pathThe path to the header declaring this field's value names
definitionThe resolved description of the field's prefix, cap, skip set, format, and display name
formatThe text formatter for styled output
diagThe user diagnostics for error reporting

Definition at line 58 of file header_enum_map_provider.hpp.

Member Function Documentation

◆ lookup() [1/2]

ChainableResult< std::uint32_t > porytiles::HeaderEnumMapProvider::lookup ( const std::string &  name) const
overridevirtual

Looks up the numeric value for a constant name.

Parameters
nameThe value constant name (e.g. "MB_NORMAL")
Returns
The numeric value if found, or an error describing why the lookup failed

Implements porytiles::EnumMapProvider.

Definition at line 167 of file header_enum_map_provider.cpp.

◆ lookup() [2/2]

ChainableResult< std::string > porytiles::HeaderEnumMapProvider::lookup ( std::uint32_t  value) const
overridevirtual

Looks up the constant name for a numeric value.

Parameters
valueThe numeric value
Returns
The constant name if found, or an error describing why the lookup failed

Implements porytiles::EnumMapProvider.

Definition at line 196 of file header_enum_map_provider.cpp.


The documentation for this class was generated from the following files: