MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
StateDecoder.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "Fabric.hpp"
4
5namespace MayaFlux::Nexus {
6
7/**
8 * @class StateDecoder
9 * @brief Patches Fabric state from a previously encoded EXR + JSON schema pair.
10 *
11 * v1 scope: reads {base_path}.exr (schema v2) and patches Emitters, Sensors,
12 * and Agents by id. Dispatches per Kind; entities present in the schema but
13 * absent from the Fabric are logged and counted in missing_count(). Optional
14 * fields (color, size) are only patched when the schema records a non-null
15 * value. Callable name mismatches between schema and live entity are warned
16 * but do not abort the patch.
17 */
18class MAYAFLUX_API StateDecoder {
19public:
20 StateDecoder() = default;
21 ~StateDecoder() = default;
22
23 StateDecoder(const StateDecoder&) = delete;
27
28 /**
29 * @brief Result of a reconstruct() call.
30 */
32 int constructed { 0 };
33 int patched { 0 };
34 int skipped { 0 };
35 std::vector<std::string> warnings;
36 };
37
38 /**
39 * @brief Decode and apply to @p fabric.
40 * @param fabric Target fabric. Must already contain entities with
41 * ids matching the schema.
42 * @param base_path Path stem without extension, same value passed to
43 * StateEncoder::encode.
44 * @return True on success. Partial patches (some ids missing) still
45 * return true; failures are logged.
46 */
47 [[nodiscard]] bool decode(Fabric& fabric, const std::string& base_path);
48
49 /**
50 * @brief Patch existing entities and construct missing ones from schema.
51 *
52 * Entities whose id exists in the fabric are patched in place. Missing
53 * entities are constructed, their callables resolved via the fabric's
54 * function registry (no-op fallback with warning if absent), and wired.
55 * Supported wiring kinds for v2: every, move_to, commit_driven.
56 * Unsupported kinds (on, use, bind) fall back to commit_driven + warning.
57 * Hard failure (bad schema, unreadable EXR, dimension mismatch) sets
58 * last_error() and returns a zeroed result.
59 *
60 * @param fabric Target fabric. May be empty, partial, or full.
61 * @param base_path Path stem without extension.
62 * @return Counts and per-entity warnings.
63 */
64 [[nodiscard]] ReconstructionResult reconstruct(Fabric& fabric, const std::string& base_path);
65
66 /**
67 * @brief Last error message, empty if no error.
68 */
69 [[nodiscard]] const std::string& last_error() const { return m_last_error; }
70
71 /**
72 * @brief Number of Emitters actually patched on the last decode call.
73 */
74 [[nodiscard]] size_t patched_count() const { return m_patched_count; }
75
76 /**
77 * @brief Number of ids present in the schema but missing from the fabric.
78 */
79 [[nodiscard]] size_t missing_count() const { return m_missing_count; }
80
81private:
82 std::string m_last_error;
83 size_t m_patched_count { 0 };
84 size_t m_missing_count { 0 };
85};
86
87} // namespace MayaFlux::Nexus
Orchestrates spatial indexing and scheduling for Nexus objects.
Definition Fabric.hpp:37
const std::string & last_error() const
Last error message, empty if no error.
StateDecoder(const StateDecoder &)=delete
StateDecoder & operator=(StateDecoder &&)=default
size_t patched_count() const
Number of Emitters actually patched on the last decode call.
StateDecoder(StateDecoder &&)=default
size_t missing_count() const
Number of ids present in the schema but missing from the fabric.
StateDecoder & operator=(const StateDecoder &)=delete
Patches Fabric state from a previously encoded EXR + JSON schema pair.