Porytiles
Loading...
Searching...
No Matches
porytiles::Field Class Reference

One named bit-field within a metatile attribute layout. More...

#include <metatile_attribute_schema.hpp>

Public Member Functions

 Field (std::string name, std::uint32_t mask, std::uint32_t default_value=0, std::optional< ProviderDefinition > provider=std::nullopt, std::optional< FieldRole > role=std::nullopt)
 Constructs a field from a name, mask, and optional default value, provider definition, and role.
 
const std::string & name () const
 
std::uint32_t mask () const
 
std::uint32_t default_value () const
 
std::uint32_t offset () const
 Returns the bit offset of the field's least-significant bit.
 
std::uint32_t width () const
 Returns the number of bits the field occupies.
 
std::uint32_t max_value () const
 Returns the largest value the field can hold.
 
bool has_provider () const
 
const std::optional< FieldRole > & role () const
 
bool packs_layer_type () const
 Reports whether this field carries the layer_type role.
 
const ProviderDefinitionprovider_definition () const
 Returns the field's provider definition.
 

Detailed Description

One named bit-field within a metatile attribute layout.

A field pairs a name with the mask of bits it occupies inside the packed attribute word. The mask is the single source of truth for the field's position and size: the offset, width, and maximum storable value are all derived from it. A field may also carry a provider definition describing how its values are named in a base-game header, and an optional role marking it as a field whose values Porytiles manages (see FieldRole).

A Field is a passive carrier and does not validate itself. Layout rules (contiguous non-zero mask, in-range, non-overlapping, default fits) are enforced when a Field is placed into a Schema via Schema::create. Deriving offset() or max_value() from a zero mask is meaningless, so those accessors document a non-zero-mask precondition that Schema::create guarantees for every field it accepts.

Invariant
For a Field obtained from a created Schema, mask() is a single contiguous run of at least one bit.

Definition at line 216 of file metatile_attribute_schema.hpp.

Constructor & Destructor Documentation

◆ Field()

porytiles::Field::Field ( std::string  name,
std::uint32_t  mask,
std::uint32_t  default_value = 0,
std::optional< ProviderDefinition provider = std::nullopt,
std::optional< FieldRole role = std::nullopt 
)
inline

Constructs a field from a name, mask, and optional default value, provider definition, and role.

Parameters
nameThe field name
maskThe bits this field occupies within the packed attribute word
default_valueThe value used when the field is absent from a metatile's attribute
providerAn optional description of how this field's named values are declared
roleAn optional semantic role marking a field whose values Porytiles manages

Definition at line 225 of file metatile_attribute_schema.hpp.

Member Function Documentation

◆ default_value()

std::uint32_t porytiles::Field::default_value ( ) const
inline

Definition at line 246 of file metatile_attribute_schema.hpp.

◆ has_provider()

bool porytiles::Field::has_provider ( ) const
inline

Definition at line 281 of file metatile_attribute_schema.hpp.

◆ mask()

std::uint32_t porytiles::Field::mask ( ) const
inline

Definition at line 241 of file metatile_attribute_schema.hpp.

◆ max_value()

std::uint32_t porytiles::Field::max_value ( ) const
inline

Returns the largest value the field can hold.

This is the mask shifted down to bit zero, which is the single source of truth for the range checks that Schema::create and the provider-backed enum loading apply.

Precondition
mask() must not be zero. Guaranteed for any field inside a created Schema.
Returns
The maximum value representable in the field's width

Definition at line 276 of file metatile_attribute_schema.hpp.

◆ name()

const std::string & porytiles::Field::name ( ) const
inline

Definition at line 236 of file metatile_attribute_schema.hpp.

◆ offset()

std::uint32_t porytiles::Field::offset ( ) const
inline

Returns the bit offset of the field's least-significant bit.

Precondition
mask() must not be zero. Guaranteed for any field inside a created Schema.
Returns
The number of low-order zero bits in the mask

Definition at line 255 of file metatile_attribute_schema.hpp.

◆ packs_layer_type()

bool porytiles::Field::packs_layer_type ( ) const
inline

Reports whether this field carries the layer_type role.

The layer_type-role field receives each metatile's layer type when attributes are packed. Its per-metatile value comes from MetatileAttribute::layer_type() (inferred at compile time or pinned through the CSV's trailing "pin::layer_type" column), never from a normal CSV value column.

Returns
true when the field's role is FieldRole::layer_type

Definition at line 299 of file metatile_attribute_schema.hpp.

◆ provider_definition()

const ProviderDefinition & porytiles::Field::provider_definition ( ) const
inline

Returns the field's provider definition.

Precondition
has_provider() must be true.
Returns
A const reference to the provider definition

Definition at line 308 of file metatile_attribute_schema.hpp.

◆ role()

const std::optional< FieldRole > & porytiles::Field::role ( ) const
inline

Definition at line 286 of file metatile_attribute_schema.hpp.

◆ width()

std::uint32_t porytiles::Field::width ( ) const
inline

Returns the number of bits the field occupies.

Returns
The population count of the mask

Definition at line 263 of file metatile_attribute_schema.hpp.


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