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

Represents a single member (constant) within a C enum declaration. More...

#include <enum_member.hpp>

Public Member Functions

 EnumMember (std::string name, std::int64_t value, SourcePosition position)
 Constructs an EnumMember with an implicit (counter-based) value.
 
 EnumMember (std::string name, std::int64_t value, bool has_explicit_value, SourcePosition position)
 Constructs an EnumMember with explicit value flag.
 
const std::string & name () const
 Returns the member name.
 
std::int64_t int_value () const
 Returns the resolved integer value.
 
bool has_explicit_value () const
 Checks if this member had an explicit value assignment.
 
const SourcePositionposition () const
 Returns the source position of the member.
 

Detailed Description

Represents a single member (constant) within a C enum declaration.

EnumMember captures the name and resolved value of an enum constant. Values may be explicitly assigned (e.g., FOO = 10) or implicitly assigned via counter (sequential from 0 or previous value + 1). The original source position is preserved for error reporting.

Example members this class can represent:

enum {
MB_NORMAL, // name="MB_NORMAL", value=0, explicit=false
MB_TALL_GRASS, // name="MB_TALL_GRASS", value=1, explicit=false
MB_INVALID = 0xFF, // name="MB_INVALID", value=255, explicit=true
};

Definition at line 27 of file enum_member.hpp.

Constructor & Destructor Documentation

◆ EnumMember() [1/2]

porytiles::EnumMember::EnumMember ( std::string  name,
std::int64_t  value,
SourcePosition  position 
)
inline

Constructs an EnumMember with an implicit (counter-based) value.

Parameters
nameThe member name
valueThe resolved integer value
positionThe source position of the member

Definition at line 36 of file enum_member.hpp.

◆ EnumMember() [2/2]

porytiles::EnumMember::EnumMember ( std::string  name,
std::int64_t  value,
bool  has_explicit_value,
SourcePosition  position 
)
inline

Constructs an EnumMember with explicit value flag.

Parameters
nameThe member name
valueThe resolved integer value
has_explicit_valueTrue if value was explicitly assigned with =
positionThe source position of the member

Definition at line 49 of file enum_member.hpp.

Member Function Documentation

◆ has_explicit_value()

bool porytiles::EnumMember::has_explicit_value ( ) const
inline

Checks if this member had an explicit value assignment.

Returns
True if the value was explicitly assigned with =

Definition at line 79 of file enum_member.hpp.

◆ int_value()

std::int64_t porytiles::EnumMember::int_value ( ) const
inline

Returns the resolved integer value.

Returns
The enum member value

Definition at line 69 of file enum_member.hpp.

◆ name()

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

Returns the member name.

Returns
A const reference to the name

Definition at line 59 of file enum_member.hpp.

◆ position()

const SourcePosition & porytiles::EnumMember::position ( ) const
inline

Returns the source position of the member.

Returns
A const reference to the source position

Definition at line 89 of file enum_member.hpp.


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