架构优化
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user