架构优化

This commit is contained in:
2026-08-11 12:40:28 +08:00
parent e91f134f16
commit 8d4714f691
17 changed files with 210 additions and 107 deletions
@@ -0,0 +1,14 @@
#include <structive/property/property.hpp>
using namespace structive;
struct Device {};
int main() {
auto schema = object<Device>(
computed_property<Device, int>(depends_on_keys<"right">, [](const auto& view) {
return view.template get<"right">();
}, key<"left">),
computed_property<Device, int>(depends_on_keys<"left">, [](const auto& view) {
return view.template get<"left">();
}, key<"right">)
);
static_cast<void>(schema);
}
@@ -0,0 +1,9 @@
#include <structive/property/property.hpp>
struct Device {
int value{};
};
struct Invalid_Metadata {};
int main() {
auto schema = structive::object<Device>(structive::field<&Device::value>(structive::key<"value">, Invalid_Metadata{}));
static_cast<void>(schema);
}
@@ -0,0 +1,20 @@
#include <structive/property/property.hpp>
struct Device {
int value{};
};
struct Accessor {
using object_type = Device;
using value_type = int;
using storage_identity = void;
static constexpr bool readable = true;
static constexpr bool writable = false;
static constexpr bool synchronized_view_read = false;
static constexpr bool trusted_object_access = false;
int read(const Device& device) const {
return device.value;
}
};
int main() {
structive::Property_Descriptor<Accessor, structive::Key_Attribute<"value">> descriptor;
static_cast<void>(descriptor);
}
+24 -1
View File
@@ -69,7 +69,10 @@ struct structive::Type_Descriptor<Computed_Device> {
}, key<"double_span">),
computed_property<Computed_Device, int>(depends_on<&Computed_Device::fixed_offset>, [](const auto& view) {
return view.template get<&Computed_Device::fixed_offset>() * 2;
}, key<"fixed_twice">)
}, key<"fixed_twice">),
computed_property<Computed_Device, int>(depends_on<>, [](const auto&) {
return 42;
}, key<"constant">)
);
}
};
@@ -211,6 +214,21 @@ int main() {
multi_sum += std::remove_cvref_t<decltype(attribute)>::value;
});
REQUIRE(multi_sum == 8);
std::size_t metadata_count = 0;
std::size_t attribute_count = 0;
std::size_t constraint_count = 0;
schema.template property<&Device::temperature>().for_each_metadata([&](const auto&) {
++metadata_count;
});
schema.template property<&Device::temperature>().for_each_attribute([&](const auto&) {
++attribute_count;
});
schema.template property<&Device::temperature>().for_each_constraint([&](const auto&) {
++constraint_count;
});
REQUIRE(metadata_count == 7);
REQUIRE(attribute_count == 5);
REQUIRE(constraint_count == 2);
const auto& empty_schema = type_descriptor<Empty_Device>();
static_assert(type_descriptor_schema_t<Empty_Device>::property_count == 0);
REQUIRE(empty_schema.synchronization_plan().property_rules().empty());
@@ -284,13 +302,18 @@ int main() {
REQUIRE(computed.lock_slot<&Computed_Device::fixed_offset>() == Resolved_Synchronization_View::unsynchronized_slot);
constexpr auto double_span_index = schema_property_index_v<Computed_Schema, "double_span">;
constexpr auto fixed_twice_index = schema_property_index_v<Computed_Schema, "fixed_twice">;
constexpr auto constant_index = schema_property_index_v<Computed_Schema, "constant">;
static_assert(schema_dependency_graph_acyclic<Computed_Schema>());
static_assert(schema_property_dependency_count_v<Computed_Schema, constant_index> == 0);
REQUIRE(computed.resolved_synchronization().slot(speed_span_index) == computed.lock_slot<&Computed_Device::min_speed>());
REQUIRE(computed.resolved_synchronization().slot(speed_span_index) == computed.lock_slot<&Computed_Device::max_speed>());
REQUIRE(computed.resolved_synchronization().slot(double_span_index) == computed.resolved_synchronization().slot(speed_span_index));
REQUIRE(computed.resolved_synchronization().slot(fixed_twice_index) == Resolved_Synchronization_View::unsynchronized_slot);
REQUIRE(computed.resolved_synchronization().slot(constant_index) == Resolved_Synchronization_View::unsynchronized_slot);
REQUIRE(computed.read<"speed_span">() == 95);
REQUIRE(computed.read<"double_span">() == 190);
REQUIRE(computed.read<"fixed_twice">() == 10);
REQUIRE(computed.read<"constant">() == 42);
computed.write<&Computed_Device::min_speed>(20);
REQUIRE(computed.read<"speed_span">() == 85);
REQUIRE(computed.read<"double_span">() == 170);