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
26 public:
32 EnumMember(std::string name, std::int64_t value, SourcePosition position)
33 : name_{std::move(name)}, value_{value}, has_explicit_value_{false}, position_{position}
34 {
35 }
36
43 EnumMember(std::string name, std::int64_t value, bool has_explicit_value, SourcePosition position)
44 : name_{std::move(name)}, value_{value}, has_explicit_value_{has_explicit_value}, position_{position}
45 {
46 }
47
51 [[nodiscard]] const std::string &name() const
52 {
53 return name_;
54 }
55
59 [[nodiscard]] std::int64_t int_value() const
60 {
61 return value_;
62 }
63
67 [[nodiscard]] bool has_explicit_value() const
68 {
69 return has_explicit_value_;
70 }
71
75 [[nodiscard]] const SourcePosition &position() const
76 {
77 return position_;
78 }
79
80 private:
81 std::string name_;
82 std::int64_t value_;
83 bool has_explicit_value_;
84 SourcePosition position_;
85};
86
87} // 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.