#pragma once #include #include "utils/option.hpp" #include "utils/option_ptr.hpp" #include "storage/model/properties/property_family.hpp" #include "storage/model/properties/stored_property.hpp" template using type_key_t = typename PropertyFamily::PropertyType::template PropertyTypeKey; template class Properties { public: using property_key = typename PropertyFamily::PropertyType::PropertyFamilyKey; template using type_key_t = typename PropertyFamily::PropertyType::template PropertyTypeKey; auto begin() const { return props.begin(); } auto cbegin() const { return props.cbegin(); } auto end() const { return props.end(); } auto cend() const { return props.cend(); } size_t size() const { return props.size(); } const StoredProperty &at(PropertyFamily &key) const; const StoredProperty &at(property_key &key) const; template OptionPtr at(type_key_t &key) const { auto f_key = key.family_key(); for (auto &prop : props) { if (prop.key == f_key) { return OptionPtr(&(prop.template as())); } } return OptionPtr(); } void set(StoredProperty &&value); void clear(property_key &key); void clear(PropertyFamily &key); template void accept(Handler &handler) const { for (auto &kv : props) kv.accept(handler); handler.finish(); } template void for_all(Handler handler) const { for (auto &kv : props) handler(kv); } private: using props_t = std::vector>; // TODO: more bytes can be saved if this is array with exact size as number // of elements. // TODO: even more bytes can be saved if this is one ptr to structure which // holds len followed by len sized array. props_t props; };