This commit is contained in:
2026-08-12 06:16:00 +08:00
parent a672f37fae
commit 42392bbb7e
10 changed files with 246 additions and 10 deletions
@@ -0,0 +1,17 @@
#include <structive/property/property.hpp>
struct Device {};
struct Type_Name_Category {};
template <int Value>
struct Type_Name {
using attribute_category = Type_Name_Category;
static constexpr bool single_valued = true;
static constexpr bool inheritable = false;
};
int main() {
auto schema = structive::object<Device>(
structive::type_metadata(Type_Name<1>{}, Type_Name<2>{}));
static_cast<void>(schema);
}
+30
View File
@@ -24,6 +24,23 @@ struct Test_Multi_Attribute {
};
template <int Value>
inline constexpr Test_Multi_Attribute<Value> test_multi{};
struct Test_Type_Action_Category {};
struct Test_Type_Action_Attribute {
using attribute_category = Test_Type_Action_Category;
static constexpr bool single_valued = false;
static constexpr bool inheritable = false;
std::string_view name;
};
inline constexpr auto test_type_action(std::string_view name) {
return Test_Type_Action_Attribute{name};
}
struct Test_Type_Name_Category {};
struct Test_Type_Name_Attribute {
using attribute_category = Test_Type_Name_Category;
static constexpr bool single_valued = true;
static constexpr bool inheritable = false;
std::string_view value;
};
struct Device : Property_Object<Device> {
Device() = default;
explicit Device(Property_Synchronization synchronization) : Property_Object(std::move(synchronization)) {}
@@ -37,6 +54,8 @@ template <>
struct structive::Type_Descriptor<Device> {
static auto get() {
return object<Device>(
type_metadata(Test_Type_Name_Attribute{"device"},
test_type_action("calibrate"), test_type_action("reset")),
synchronization(sync_all_independent, sync_group<&Device::min_speed, &Device::max_speed>("speed_range")),
field<&Device::temperature>(key<"temperature">, min_value<-50>, max_value<200>, unit<"C">, test_tag<7>, test_multi<3>, test_multi<5>),
field<&Device::pressure>(key<"pressure">),
@@ -207,6 +226,9 @@ int main() {
using Schema = type_descriptor_schema_t<Device>;
static_assert(Valid_Property_Schema<Schema>);
static_assert(Schema::property_count == 5);
static_assert(Schema::template type_attribute_count<Test_Type_Action_Category> == 2);
static_assert(Schema::template has_type_attribute<Test_Type_Action_Category>);
static_assert(Schema::template type_attribute_count<Test_Type_Name_Category> == 1);
using Immutable_Property = typename Schema::template property_type<4>;
static_assert(Immutable_Property::readable);
static_assert(!Immutable_Property::writable);
@@ -214,6 +236,14 @@ int main() {
REQUIRE(schema.template property<&Device::temperature>().key() == "temperature");
REQUIRE(schema.template property<&Device::min_speed>().key() == "minimum_speed");
REQUIRE(schema.template property<&Device::max_speed>().key() == "maximum_speed");
std::string type_actions;
schema.for_each_type_attribute<Test_Type_Action_Category>([&](const auto& action) {
if (!type_actions.empty())
type_actions += ',';
type_actions += action.name;
});
REQUIRE(type_actions == "calibrate,reset");
REQUIRE(schema.type_attribute<Test_Type_Name_Category>().value == "device");
using Temperature_Property = std::remove_cvref_t<decltype(schema.template property<&Device::temperature>())>;
static_assert(Temperature_Property::template has_attribute<Test_Tag_Category>);
static_assert(Temperature_Property::template attribute_count<Test_Tag_Category> == 1);