3#include "AttributeRegistry.hpp"
4#include "AttributeTypes.hpp"
9#include <unordered_map>
21inline const std::unordered_map<AttributeGroup, std::vector<Attribute>>& ATTRIBUTE_GROUPS =
22 attributes::registry::attributeGroups();
42 std::unordered_map<AttributeKey, int>
indexMap;
60 std::unordered_map<AttributeKey, int>
map;
62 for (
int d = -delta;
d <= delta; ++
d) {
63 for (std::size_t
i = 0;
i < attributes.size(); ++
i) {
67 throw std::invalid_argument(
68 "AttributeNamesWithDelta::create received duplicate attribute " +
116 std::string name(attributes::registry::name(attr));
119 name +=
"_ASC_" + std::to_string(-delta);
120 }
else if (delta > 0) {
121 name +=
"_DESC_" + std::to_string(delta);
170 std::unordered_map<Attribute, int>
map;
172 for (
auto attr : attributes) {
175 throw std::invalid_argument(
176 "AttributeNames::fromList received duplicate attribute " +
187 auto it = ATTRIBUTE_GROUPS.find(
group);
188 if (
it == ATTRIBUTE_GROUPS.end()) {
189 throw std::invalid_argument(
"Unknown attribute group.");
226 return std::string(attributes::registry::name(attr));
237 return std::string(attributes::registry::description(attr));
247 return attributes::registry::parse(
str);
Layout object for buffers that store several (attribute, delta) combinations per node.
AttributeNamesWithDelta(std::unordered_map< AttributeKey, int > &&map)
Constructs a layout from an already validated offset map.
int linearIndex(int nodeIndex, Attribute attr, int delta) const
Returns the linear index in the flat buffer for a given node and delta-augmented attribute.
int getIndex(AttributeKey attrKey) const
Returns the per-node offset associated with a composite delta key.
static std::string toString(Attribute attr, int delta)
Returns a human-readable label for an attribute at a given delta.
int linearIndex(int nodeIndex, AttributeKey attrKey) const
Convenience overload taking an AttributeKey.
static AttributeNamesWithDelta create(int delta, const std::vector< Attribute > &attributes)
Builds the canonical dense layout for all deltas in [-delta, delta].
std::unordered_map< AttributeKey, int > indexMap
Maps each (attribute, delta) key to its per-node offset.
int getIndex(Attribute attr, int delta) const
Returns the per-node offset associated with (attr, delta).
const int NUM_ATTRIBUTES
Number of delta-augmented entries stored for each node.
static std::string toString(AttributeKey attrKey)
Returns a human-readable label for a composite key.
Layout object that maps scalar attributes to flat-buffer offsets.
static std::string describe(Attribute attr)
Returns a user-facing description of an attribute.
static std::string toString(Attribute attr)
Returns the stable symbolic name associated with attr.
static AttributeNames fromList(const std::vector< Attribute > &attributes)
Builds a dense layout from an explicit attribute list.
static AttributeNames fromGroup(AttributeGroup group)
Builds a layout from a public attribute group.
int getIndex(Attribute attr) const
Returns the per-node offset associated with attr.
static std::optional< Attribute > parse(const std::string &str)
Parses a stable symbolic attribute name.
int linearIndex(int nodeIndex, Attribute attr) const
Returns the linear index in the flat buffer for (node, attr).
const int NUM_ATTRIBUTES
Number of scalar attributes stored for each node.
int offset(Attribute attr) const
Returns the per-node offset associated with attr.
AttributeNames(std::unordered_map< Attribute, int > &&map)
Constructs a layout from an already validated offset map.
std::unordered_map< Attribute, int > indexMap
Maps each requested attribute to its per-node offset.
bool contains(Attribute attr) const noexcept
Returns whether this layout contains attr.
Composite key used to index delta-augmented attribute layouts.
Owning result for one computed scalar attribute layout and buffer.
std::vector< Real > second
Flat per-node attribute buffer indexed through first.