Porytiles
Loading...
Searching...
No Matches
header_enum_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
18
19namespace porytiles {
20
47 public:
59 std::filesystem::path header_path,
60 EnumDefinition definition,
61 gsl::not_null<const TextFormatter *> format,
62 gsl::not_null<const UserDiagnostics *> diag)
63 : header_path_{std::move(header_path)}, definition_{std::move(definition)}, format_{format}, diag_{diag}
64 {
65 }
66
67 [[nodiscard]] ChainableResult<std::uint32_t> lookup(const std::string &name) const override;
68
69 [[nodiscard]] ChainableResult<std::string> lookup(std::uint32_t value) const override;
70
71 private:
72 ChainableResult<void> ensure_loaded() const;
73
90 template <typename Entry>
91 ChainableResult<void> try_add_entry(const Entry &entry) const;
92
93 std::filesystem::path header_path_;
94 EnumDefinition definition_;
95 const TextFormatter *format_;
96 const UserDiagnostics *diag_;
97 mutable bool loaded_{false};
98 mutable bool load_failed_{false};
99 mutable std::unique_ptr<CParserFacade> driver_;
100 mutable std::unordered_map<std::string, std::uint32_t> name_to_value_;
101 mutable std::unordered_map<std::uint32_t, std::string> value_to_name_;
102 mutable std::unordered_map<std::string, SourcePosition> name_to_position_;
103 mutable std::unordered_map<std::uint32_t, SourcePosition> value_to_position_;
104};
105
122[[nodiscard]] ProviderMap build_provider_map(
123 const std::filesystem::path &project_root,
124 const Schema &schema,
125 gsl::not_null<const TextFormatter *> format,
126 gsl::not_null<const UserDiagnostics *> diag);
127
128} // namespace porytiles
A result type that maintains a chainable sequence of errors for debugging and error reporting.
Abstract interface for providing two-way name/value mappings for an enumerated attribute field.
Loads a field's name/value mappings from a C/C++ header used by a decomp project.
ChainableResult< std::uint32_t > lookup(const std::string &name) const override
Looks up the numeric value for a constant name.
HeaderEnumMapProvider(std::filesystem::path header_path, EnumDefinition definition, gsl::not_null< const TextFormatter * > format, gsl::not_null< const UserDiagnostics * > diag)
Constructs a provider that will load from the specified header file.
Abstract base class for applying text styling with context-aware formatting.
Abstract class for structured error reporting and diagnostic output.
std::string name
std::map< std::string, std::unique_ptr< EnumMapProvider >, std::less<> > ProviderMap
Maps schema field names to the provider that names that field's values.
ProviderMap build_provider_map(const std::filesystem::path &project_root, const Schema &schema, gsl::not_null< const TextFormatter * > format, gsl::not_null< const UserDiagnostics * > diag)
Builds a header provider for every provider-backed field in a schema.
The self-contained description a header enum provider needs to scan and validate values.