Enzo
Loading...
Searching...
No Matches
ParameterSerializable.h
1#pragma once
2#include "Engine/Core/Types.h"
3#include "Engine/Parameter/Parameter.h"
4#include <cereal/types/optional.hpp>
5#include <cereal/types/string.hpp>
6#include <cereal/types/vector.hpp>
7#include <optional>
8#include <string>
9#include <vector>
10
11namespace enzo::nt {
12class Node;
13}
14
16{
17 std::string name;
18 std::vector<enzo::floatT> floatValues;
19 std::vector<enzo::intT> intValues;
20 std::vector<std::string> stringValues;
21 // One optional expression per component, parallel to the value vector. An
22 // empty slot means the component uses its literal value.
23 std::vector<std::optional<std::string>> expressions;
24 // Multiparm parameters such as ramps store nothing flat. Each instance is a
25 // list of field models, so the structure nests one level per instance.
26 std::vector<std::vector<ParameterSerializable>> instances;
27
28 bool operator==(const ParameterSerializable& other) const = default;
29
30 template <class Archive> void serialize(Archive& ar)
31 {
32 ar(CEREAL_NVP(name),
33 CEREAL_NVP(floatValues),
34 CEREAL_NVP(intValues),
35 CEREAL_NVP(stringValues),
36 CEREAL_NVP(expressions),
37 CEREAL_NVP(instances));
38 }
39};
40
41// Capture a parameter's live state into a serializable model. Multiparms recurse
42// one model per instance field, flat parameters store their value vector.
43ParameterSerializable toSerializable(enzo::prm::Parameter& parameter);
44
45// Snapshots a flat parameter from its name and values without a live Parameter.
46ParameterSerializable toSerializable(std::string name, const enzo::prm::PrmValues& values);
47
48// Write a serialized model back onto a live parameter. Multiparms reconcile their
49// instance count to the model before writing each field by name.
50void applySerializable(enzo::prm::Parameter& parameter, const ParameterSerializable& model);
51
52// Writes each model onto the node's parameter of the same name. A model naming a
53// parameter the node lacks is skipped.
54void applySerializable(enzo::nt::Node& node, const std::vector<ParameterSerializable>& models);
Basic attribute, parameter, and node types for Enzo.
The unique runtime representation of a node.
Definition Node.h:18
Definition Parameter.h:19
Definition ParameterSerializable.h:16