Toast Engine
Loading...
Searching...
No Matches
data.hpp
Go to the documentation of this file.
1
7
8#pragma once
9
10#include "core_types.hpp"
11#include "data_value.hpp"
12#include "schema.hpp"
13
14namespace assets {
15
16class TOAST_API Data : public Asset, public ISaveable {
17public:
19 struct KeepAllKeysTag { };
20
21 static constexpr KeepAllKeysTag keep_all_keys {};
22
23 explicit Data(const toml::table& table, Handle<Schema> schema = {});
24
27 Data(const toml::table& table, Handle<Schema> schema, KeepAllKeysTag);
28
29 [[nodiscard]]
30 auto type() const -> std::string_view override {
31 return "data";
32 }
33
34 [[nodiscard]]
35 auto operator[](std::string_view k) -> DataValue& {
36 return m_root[k];
37 }
38
39 [[nodiscard]]
40 auto operator[](std::string_view k) const -> const DataValue& {
41 return m_root[k];
42 }
43
44 [[nodiscard]]
45 auto contains(std::string_view k) const -> bool {
46 return m_root.contains(k);
47 }
48
49 [[nodiscard]]
50 auto root() const -> const DataValue& {
51 return m_root;
52 }
53
54 [[nodiscard]]
55 auto schema() const -> const Handle<Schema>& {
56 return m_schema;
57 }
58
59 [[nodiscard]]
60 auto serialize(SaveMode mode) const -> std::vector<uint8_t> override;
61
63 virtual void reload(const toml::table& table);
64
65protected:
66 virtual void onReloaded() { }
67
70 bool m_keep_all_keys = false;
71
72private:
73 static auto buildRoot(const toml::table& table, const Schema* schema) -> DataValue;
74};
75
76}
Typed value for TOML files.
Definition data_value.hpp:50
Definition data.hpp:16
DataValue m_root
Object DataValue holding all fields.
Definition data.hpp:68
Handle< Schema > m_schema
optional
Definition data.hpp:69
Type-safe smart pointer for assets.
Definition core_types.hpp:149
Inherit from this class to allow an asset to be saved.
Definition core_types.hpp:33
Asset wrapping a parsed .schema.json.
Definition schema.hpp:60
Base types for the asset system.
Recursive typed value for schema-driven TOML data assets.
@ root
The node is currently in use within world::root_node.
Definition node.hpp:55
Used as "reflection data" for Data types.
Tag type for the keep-all-keys constructor.
Definition data.hpp:19