载入中...
搜索中...
未找到
AttributeTable.h
浏览该文件的文档.
1#pragma once
2
3#include "common/Result.h"
4
5#include <cstdint>
6#include <optional>
7#include <string>
8#include <string_view>
9#include <unordered_map>
10#include <variant>
11#include <vector>
12
13namespace eve::procgen {
14
17 float x = 0.f;
18 float y = 0.f;
19 float z = 0.f;
20};
21
23enum class ProcgenAttributeType : std::uint8_t { Float, Int, Bool, Vector, String };
24
34public:
36 [[nodiscard]] std::size_t rowCount() const noexcept;
38 void resize(std::size_t rows);
40 [[nodiscard]] std::size_t appendRow();
47 [[nodiscard]] Result<std::size_t> appendRowFrom(const AttributeTable& source, std::size_t sourceRow);
49 [[nodiscard]] Result<void> clearRow(std::size_t row);
51 void clear() noexcept;
52
54 [[nodiscard]] std::size_t columnCount() const noexcept;
56 [[nodiscard]] std::string_view columnName(std::size_t index) const noexcept;
58 [[nodiscard]] std::optional<ProcgenAttributeType> typeOf(std::string_view name) const;
60 [[nodiscard]] bool has(std::size_t row, std::string_view name) const;
61
67 [[nodiscard]] Result<void> renameColumn(std::string_view from, std::string_view to);
72 [[nodiscard]] Result<void> removeColumn(std::string_view name);
78 [[nodiscard]] Result<void> copyColumn(std::string_view from, std::string_view to);
79
81 [[nodiscard]] Result<void> setFloat(std::size_t row, std::string_view name, float value);
83 [[nodiscard]] Result<void> setInt(std::size_t row, std::string_view name, std::int64_t value);
85 [[nodiscard]] Result<void> setBool(std::size_t row, std::string_view name, bool value);
87 [[nodiscard]] Result<void> setVector(std::size_t row, std::string_view name, ProcgenAttributeVector value);
89 [[nodiscard]] Result<void> setString(std::size_t row, std::string_view name, std::string value);
90
92 [[nodiscard]] std::optional<float> getFloat(std::size_t row, std::string_view name) const;
94 [[nodiscard]] std::optional<std::int64_t> getInt(std::size_t row, std::string_view name) const;
96 [[nodiscard]] std::optional<bool> getBool(std::size_t row, std::string_view name) const;
98 [[nodiscard]] std::optional<ProcgenAttributeVector> getVector(std::size_t row, std::string_view name) const;
100 [[nodiscard]] std::optional<std::string_view> getString(std::size_t row, std::string_view name) const;
101
102private:
103 using FloatColumn = std::vector<std::optional<float>>;
104 using IntColumn = std::vector<std::optional<std::int64_t>>;
105 using BoolColumn = std::vector<std::optional<bool>>;
106 using VectorColumn = std::vector<std::optional<ProcgenAttributeVector>>;
107 using StringColumn = std::vector<std::optional<std::string>>;
108 using Storage = std::variant<FloatColumn, IntColumn, BoolColumn, VectorColumn, StringColumn>;
109 struct Column {
110 ProcgenAttributeType type = ProcgenAttributeType::Float;
111 Storage storage = FloatColumn{};
112 };
113
114 template <class T>
115 [[nodiscard]] Result<void> set(std::size_t row, std::string_view name, ProcgenAttributeType type, T value);
116 template <class T>
117 [[nodiscard]] std::optional<T> get(std::size_t row, std::string_view name, ProcgenAttributeType type) const;
118 [[nodiscard]] Result<Column*> ensureColumn(std::string_view name, ProcgenAttributeType type);
119
120 std::size_t rows_ = 0;
121 std::unordered_map<std::string, Column> columns_;
122 std::vector<std::string> order_;
123};
124
126[[nodiscard]] std::string_view procgenAttributeTypeName(ProcgenAttributeType type) noexcept;
127
128} // namespace eve::procgen
double value
std::string from
#define EVENGINE_API_DOMAINS
Definition Export.h:110
int rows
HexCoordinates to
Cell the unit walks towards on this segment.
Definition HexUnits.cpp:64
std::string name
Move-only, checked operation results for the common layer.
uint32_t index
const UnitySourceAsset & source
Move-only operation result carrying either a value or Status.
Definition Result.h:155
Schema-bearing column store aligned with a PointSet's point rows.
ProcgenAttributeType
Closed set of column types supported by procedural point metadata.
std::string_view procgenAttributeTypeName(ProcgenAttributeType type) noexcept
Return the stable script/persistence name for an attribute type.
Compact three-component value used by typed procedural metadata.