wavelength 1.0.0
Loading...
Searching...
No Matches
datanode.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <string>
5#include <string_view>
6#include <vector>
7
9namespace Tools::Ark {
10
16struct DataNode {
18 enum class Type : std::uint8_t {
19 Int = 0,
20 Symbol = 1,
21 Float = 2,
22 Array = 3,
23 };
24
26 std::uint32_t value = 0;
27 std::string symbol;
28 std::vector<DataNode> children;
29 std::uint16_t line = 0;
30 std::uint16_t sorted = 0;
31 std::int32_t file = 0;
32
39 static DataNode makeInt(std::int32_t value);
40
47 static DataNode makeSymbol(std::string symbol);
48
55 static DataNode makeFloat(float value);
56
64 static DataNode makeArray(std::uint16_t line, std::int32_t file);
65
72 [[nodiscard]] bool isKeyed(std::string_view key) const;
73
80 DataNode *findArray(std::string_view key);
81
83 [[nodiscard]] const DataNode *findArray(std::string_view key) const;
84
91 [[nodiscard]] int indexOf(std::string_view key) const;
92
98 template <typename Map>
99 void remapFiles(const Map &map) {
100 if (type != Type::Array) {
101 return;
102 }
103 file = map(file);
104 for (auto &child : children) {
105 child.remapFiles(map);
106 }
107 }
108
115 bool operator==(const DataNode &other) const = default;
116};
117
118} // namespace Tools::Ark
Readers and writers of Harmonix archives and compiled DataArray files.
Definition arkreader.h:14
One element of a DataArray, as a compiled DataArray file stores it.
Definition datanode.h:16
const DataNode * findArray(std::string_view key) const
Find a child array by the symbol that opens it, the way DataArray::FindArray does.
std::uint16_t line
Definition datanode.h:29
std::uint32_t value
Definition datanode.h:26
std::vector< DataNode > children
Definition datanode.h:28
static DataNode makeSymbol(std::string symbol)
Make a symbol element.
Type type
Definition datanode.h:25
bool isKeyed(std::string_view key) const
Report whether the element is an array whose first element is a symbol.
std::string symbol
Definition datanode.h:27
std::int32_t file
Definition datanode.h:31
Type
Kind of element, numbered as the two-bit tags of the compiled file.
Definition datanode.h:18
@ Symbol
Definition datanode.h:20
@ Int
Definition datanode.h:19
@ Float
Definition datanode.h:21
@ Array
Definition datanode.h:22
std::uint16_t sorted
Definition datanode.h:30
int indexOf(std::string_view key) const
Find the index of a child array by the symbol that opens it.
static DataNode makeArray(std::uint16_t line, std::int32_t file)
Make an empty array element.
static DataNode makeFloat(float value)
Make a float element.
void remapFiles(const Map &map)
Change the file index of the element and of every array below it.
Definition datanode.h:99
static DataNode makeInt(std::int32_t value)
Make an integer element.
bool operator==(const DataNode &other) const =default
Compare two elements, their kinds, values, and arrays.
DataNode * findArray(std::string_view key)
Find a child array by the symbol that opens it, the way DataArray::FindArray does.