Files
Aethera/mcp/core/runtime/Renderable_Adapter.hpp
T
2026-08-28 10:11:40 +08:00

50 lines
2.1 KiB
C++

#pragma once
#include <nlohmann/json_fwd.hpp>
#include <structive/property/property.hpp>
#include <memory>
#include <string>
#include <string_view>
namespace aethera::web::detail {
enum struct Renderable_Field_Role {
prop,
state
};
template <Renderable_Field_Role Role>
struct Renderable_Field_Role_Attribute;
template <auto Member, structive::Fixed_String Key, structive::Fixed_String Description,
structive::Fixed_String Editor = "">
struct Prop_Field;
template <typename Tag, auto Member, structive::Fixed_String Key, structive::Fixed_String Description>
struct State_Field;
template <typename Object, typename... Fields>
struct Renderable_Adapter;
struct Renderable_Descriptor {
public:
virtual ~Renderable_Descriptor() = default;
[[nodiscard]] virtual std::string_view id() const noexcept = 0;
[[nodiscard]] virtual nlohmann::json schema() const = 0;
[[nodiscard]] virtual nlohmann::json state() const = 0;
[[nodiscard]] virtual nlohmann::json values() const = 0;
[[nodiscard]] virtual nlohmann::json write_prop(std::string_view key, const nlohmann::json& value) = 0;
};
template <typename Adapter>
struct Renderable_Descriptor_Model final : public Renderable_Descriptor {
public:
Renderable_Descriptor_Model(std::string id, std::string label, std::string kind, Adapter adapter);
[[nodiscard]] std::string_view id() const noexcept override;
[[nodiscard]] nlohmann::json schema() const override;
[[nodiscard]] nlohmann::json state() const override;
[[nodiscard]] nlohmann::json values() const override;
[[nodiscard]] nlohmann::json write_prop(std::string_view key, const nlohmann::json& value) override;
private:
std::string component_id;
std::string component_label;
std::string component_kind;
Adapter adapter; /* 与 Plot 内真实 Renderable 同生共死的无所有权协议视图。 */
};
template <typename Adapter>
[[nodiscard]] std::unique_ptr<Renderable_Descriptor> make_renderable_descriptor(
std::string id, std::string label, std::string kind, Adapter adapter);
}
#include "Renderable_Adapter.ipp"