Porytiles
Loading...
Searching...
No Matches
operand_bundle.cpp
Go to the documentation of this file.
2
3#include <algorithm>
4#include <vector>
5
6namespace porytiles2 {
7
8// -- Range-for support --
10{
11 return config_.begin();
12}
13
15{
16 return config_.end();
17}
18
20{
21 return config_.begin();
22}
23
25{
26 return config_.end();
27}
28
30{
31 return config_.cbegin();
32}
33
35{
36 return config_.cend();
37}
38// -- Range-for support --
39
40std::optional<std::any> OperandBundle::get(const std::string &key) const
41{
42 if (!contains(key)) {
43 return std::nullopt;
44 }
45 return std::optional{config_.at(key)};
46}
47
48std::size_t OperandBundle::size() const
49{
50 return config_.size();
51}
52
53void OperandBundle::put(const std::string &key, const std::any &value)
54{
55 config_.insert_or_assign(key, value);
56}
57
58bool OperandBundle::contains(const std::string &key) const
59{
60 return config_.contains(key);
61}
62
63std::optional<std::type_index> OperandBundle::type_index_of(const std::string &key) const
64{
65 if (!contains(key)) {
66 return std::nullopt;
67 }
68 return config_.at(key).type();
69}
70
71bool OperandBundle::satisfies_declarations(const std::vector<OperandDeclaration> &declarations) const
72{
73 return std::ranges::all_of(declarations, [this](const auto &decl) {
74 return contains(decl.key()) && decl.expected_type() == type_index_of(decl.key());
75 });
76}
77
78} // namespace porytiles2
void put(const std::string &key, const std::any &value)
Stores an operand value with the given key.
std::unordered_map< std::string, std::any >::iterator iterator
const_iterator cbegin() const noexcept
std::unordered_map< std::string, std::any >::const_iterator const_iterator
const_iterator cend() const noexcept
bool contains(const std::string &key) const
Checks if an operand with the given key exists.
std::size_t size() const
Returns the number of operands stored in the bundle.
iterator end() noexcept
std::optional< std::type_index > type_index_of(const std::string &key) const
Retrieves the runtime type information for an operand.
std::optional< std::any > get(const std::string &key) const
Retrieves an operand value as std::any.
bool satisfies_declarations(const std::vector< OperandDeclaration > &declarations) const
Validates that the bundle satisfies a set of operand declarations.
iterator begin() noexcept