Porytiles
Loading...
Searching...
No Matches
header_behavior_map_provider.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <filesystem>
5#include <memory>
6#include <string>
7#include <unordered_map>
8
9#include "gsl/pointers"
10
17
18namespace porytiles {
19
43 public:
57 std::filesystem::path header_path,
58 gsl::not_null<const TextFormatter *> format,
59 gsl::not_null<const UserDiagnostics *> diag)
60 : header_path_{std::move(header_path)}, format_{format}, diag_{diag}
61 {
62 }
63
64 [[nodiscard]] ChainableResult<std::uint16_t> lookup(const std::string &behavior_name) const override;
65
66 [[nodiscard]] ChainableResult<std::string> lookup(std::uint16_t behavior_value) const override;
67
68 private:
69 ChainableResult<void> ensure_loaded() const;
70
88 template <typename Entry>
89 ChainableResult<void> try_add_behavior_entry(const Entry &entry) const;
90
91 std::filesystem::path header_path_;
92 const TextFormatter *format_;
93 const UserDiagnostics *diag_;
94 mutable bool loaded_{false};
95 mutable bool load_failed_{false};
96 mutable std::unique_ptr<CParserFacade> driver_;
97 mutable std::unordered_map<std::string, std::uint16_t> name_to_value_;
98 mutable std::unordered_map<std::uint16_t, std::string> value_to_name_;
99 mutable std::unordered_map<std::string, SourcePosition> name_to_position_;
100 mutable std::unordered_map<std::uint16_t, SourcePosition> value_to_position_;
101};
102
103} // namespace porytiles
Abstract interface for providing two-way metatile behavior mappings.
A result type that maintains a chainable sequence of errors for debugging and error reporting.
Loads behavior mappings from a C/C++ header file containing behavior definitions.
HeaderBehaviorMapProvider(std::filesystem::path header_path, 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::uint16_t > lookup(const std::string &behavior_name) const override
Looks up the numeric value for a behavior constant name.
Abstract base class for applying text styling with context-aware formatting.
Abstract class for structured error reporting and diagnostic output.