Porytiles
Loading...
Searching...
No Matches
enum_member.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <string>
5
7
8namespace porytiles {
9
28 public:
36 EnumMember(std::string name, std::int64_t value, SourcePosition position)
37 : name_{std::move(name)}, value_{value}, has_explicit_value_{false}, position_{position}
38 {
39 }
40
49 EnumMember(std::string name, std::int64_t value, bool has_explicit_value, SourcePosition position)
50 : name_{std::move(name)}, value_{value}, has_explicit_value_{has_explicit_value}, position_{position}
51 {
52 }
53
59 [[nodiscard]] const std::string &name() const
60 {
61 return name_;
62 }
63
69 [[nodiscard]] std::int64_t int_value() const
70 {
71 return value_;
72 }
73
79 [[nodiscard]] bool has_explicit_value() const
80 {
81 return has_explicit_value_;
82 }
83
89 [[nodiscard]] const SourcePosition &position() const
90 {
91 return position_;
92 }
93
94 private:
95 std::string name_;
96 std::int64_t value_;
97 bool has_explicit_value_;
98 SourcePosition position_;
99};
100
101} // namespace porytiles
Represents a single member (constant) within a C enum declaration.
EnumMember(std::string name, std::int64_t value, SourcePosition position)
Constructs an EnumMember with an implicit (counter-based) value.
std::int64_t int_value() const
Returns the resolved integer value.
const SourcePosition & position() const
Returns the source position of the member.
const std::string & name() const
Returns the member name.
bool has_explicit_value() const
Checks if this member had an explicit value assignment.
EnumMember(std::string name, std::int64_t value, bool has_explicit_value, SourcePosition position)
Constructs an EnumMember with explicit value flag.
Represents a position within source content.