46 const std::vector<uint8_t> &
blob() const noexcept {
return data_; }
58 traits::PropertyType
type() const noexcept {
return type_; }
61 std::vector<uint8_t> data_;
86 const std::map<std::string, PropertyValue> &values);
90 static void deserialize_string(
void *ptr,
const PropertyValue &value);
91 static void deserialize_integer(
void *ptr,
const PropertyValue &value);
92 static void deserialize_double(
void *ptr,
const PropertyValue &value);
93 static void deserialize_boolean(
void *ptr,
const PropertyValue &value);
94 static void deserialize_tristate(
void *ptr,
const PropertyValue &value);
95 static void deserialize_string_array(
void *ptr,
const PropertyValue &value);
96 static void deserialize_enum_value(
void *ptr,
const PropertyValue &value,
97 std::string_view enum_type);
98 static void deserialize_enum_array(
void *ptr,
const PropertyValue &value,
99 std::string_view enum_type);
100 static void deserialize_object_array(
void *ptr,
const PropertyValue &value,
119 template <
typename T>
120 static std::map<std::string, PropertyValue>
130 static PropertyValue serialize_string_array(
const void *ptr);
132 std::string_view enum_type);
134 std::string_view enum_type);
142 T &obj,
const std::map<std::string, PropertyValue> &values) {
145 for (
size_t i = 0; i < Traits::property_count(); ++i) {
146 const auto &desc = Traits::properties()[i];
151 : desc.leksikon_guid;
152 auto it = values.find(lookup_key);
153 if (it == values.end()) {
158 void *field_ptr =
reinterpret_cast<char *
>(&obj) + desc.offset;
163 deserialize_string(field_ptr, it->second);
166 deserialize_integer(field_ptr, it->second);
169 deserialize_double(field_ptr, it->second);
172 deserialize_boolean(field_ptr, it->second);
175 deserialize_tristate(field_ptr, it->second);
178 deserialize_string_array(field_ptr, it->second);
181 deserialize_enum_value(field_ptr, it->second, Traits::struct_name());
184 deserialize_enum_array(field_ptr, it->second, Traits::struct_name());
187 deserialize_object_array(field_ptr, it->second, desc);
196 std::map<std::string, PropertyValue> values;
198 for (
size_t i = 0; i < Traits::property_count(); ++i) {
199 const auto &desc = Traits::properties()[i];
200 const void *field_ptr =
201 reinterpret_cast<const char *
>(&obj) + desc.offset;
208 value = serialize_string(field_ptr);
211 value = serialize_integer(field_ptr);
214 value = serialize_double(field_ptr);
217 value = serialize_boolean(field_ptr);
220 value = serialize_tristate(field_ptr);
223 value = serialize_string_array(field_ptr);
226 value = serialize_enum_value(field_ptr, Traits::struct_name());
229 value = serialize_enum_array(field_ptr, Traits::struct_name());
232 value = serialize_object_array(field_ptr, desc);
239 : desc.leksikon_guid;
240 values.emplace(store_key, std::move(value));
Deserializer for converting database values to C++ structs.
static void deserialize(T &obj, const std::map< std::string, PropertyValue > &values)
Deserialize a struct from property value map.
Type-erased property value holder.
traits::PropertyType type() const noexcept
Get property type.
std::string_view as_string() const noexcept
Get BLOB as string view (for String, Integer, Double, etc.).
PropertyValue(const void *blob_data, size_t blob_size, traits::PropertyType type)
Construct from raw BLOB data.
const std::vector< uint8_t > & blob() const noexcept
Get raw BLOB data.
PropertyValue(std::string_view str, traits::PropertyType type)
Construct from string (for convenience).
Serializer for converting C++ structs to database values.
static std::map< std::string, PropertyValue > serialize(const T &obj)
Serialize a struct to property value map.
PropertyType
Property type enumeration for MaterialPassport serialization.
@ Boolean
std::optional<bool>
@ EnumValue
Enum values (Material, etc.).
@ EnumArray
std::vector<EnumType>
@ StringArray
std::vector<std::string>
@ Integer
std::optional<int>
@ TriState
TriState enum (yes/no/unknown).
@ Double
std::optional<double>
@ ObjectArray
std::vector<StructType> (nested objects)
Property metadata descriptor.
Trait interface for property metadata.