2016-07-05 11:01:22 +08:00
|
|
|
#pragma once
|
|
|
|
|
2016-08-23 02:03:45 +08:00
|
|
|
#include <unordered_map>
|
2016-07-05 11:01:22 +08:00
|
|
|
|
|
|
|
#include "storage/model/properties/property.hpp"
|
2016-08-18 22:34:36 +08:00
|
|
|
#include "storage/model/properties/property_family.hpp"
|
|
|
|
#include "utils/option.hpp"
|
|
|
|
|
2016-08-25 22:29:45 +08:00
|
|
|
template <class TG>
|
|
|
|
using prop_key_t = typename PropertyFamily<TG>::PropertyType::PropertyFamilyKey;
|
2016-08-18 22:34:36 +08:00
|
|
|
|
2016-08-25 22:29:45 +08:00
|
|
|
template <class TG, class T>
|
|
|
|
using type_key_t =
|
|
|
|
typename PropertyFamily<TG>::PropertyType::template PropertyTypeKey<T>;
|
2016-07-05 11:01:22 +08:00
|
|
|
|
2016-08-25 22:29:45 +08:00
|
|
|
template <class TG>
|
2016-07-05 11:01:22 +08:00
|
|
|
class Properties
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
using sptr = std::shared_ptr<Properties>;
|
|
|
|
|
2016-08-25 22:29:45 +08:00
|
|
|
using prop_key_t =
|
|
|
|
typename PropertyFamily<TG>::PropertyType::PropertyFamilyKey;
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
using type_key_t =
|
|
|
|
typename PropertyFamily<TG>::PropertyType::template PropertyTypeKey<T>;
|
|
|
|
|
2016-08-18 22:34:36 +08:00
|
|
|
auto begin() const { return props.begin(); }
|
2016-08-08 04:19:04 +08:00
|
|
|
auto cbegin() const { return props.cbegin(); }
|
|
|
|
|
2016-08-18 22:34:36 +08:00
|
|
|
auto end() const { return props.end(); }
|
2016-08-08 04:19:04 +08:00
|
|
|
auto cend() const { return props.cend(); }
|
|
|
|
|
2016-08-18 22:34:36 +08:00
|
|
|
size_t size() const { return props.size(); }
|
|
|
|
|
2016-08-25 22:29:45 +08:00
|
|
|
const Property &at(PropertyFamily<TG> &key) const;
|
2016-08-20 01:40:04 +08:00
|
|
|
|
2016-08-18 22:34:36 +08:00
|
|
|
const Property &at(prop_key_t &key) const;
|
2016-08-08 04:19:04 +08:00
|
|
|
|
2016-08-18 22:34:36 +08:00
|
|
|
template <class T>
|
|
|
|
auto at(type_key_t<T> &key) const;
|
2016-07-05 11:01:22 +08:00
|
|
|
|
|
|
|
template <class T, class... Args>
|
2016-08-18 22:34:36 +08:00
|
|
|
void set(type_key_t<T> &key, Args &&... args);
|
2016-07-05 11:01:22 +08:00
|
|
|
|
2016-08-18 22:34:36 +08:00
|
|
|
void set(prop_key_t &key, Property::sptr value);
|
2016-07-05 11:01:22 +08:00
|
|
|
|
2016-08-18 22:34:36 +08:00
|
|
|
void clear(prop_key_t &key);
|
2016-07-05 11:01:22 +08:00
|
|
|
|
2016-08-25 22:29:45 +08:00
|
|
|
void clear(PropertyFamily<TG> &key);
|
2016-08-20 01:40:04 +08:00
|
|
|
|
2016-07-05 11:01:22 +08:00
|
|
|
template <class Handler>
|
2016-08-18 22:34:36 +08:00
|
|
|
void accept(Handler &handler) const
|
2016-07-05 11:01:22 +08:00
|
|
|
{
|
2016-08-18 22:34:36 +08:00
|
|
|
for (auto &kv : props)
|
2016-07-05 11:01:22 +08:00
|
|
|
handler.handle(kv.first, *kv.second);
|
|
|
|
|
|
|
|
handler.finish();
|
|
|
|
}
|
|
|
|
|
2016-08-23 02:03:45 +08:00
|
|
|
template <class Handler>
|
|
|
|
void for_all(Handler handler) const
|
|
|
|
{
|
|
|
|
for (auto &kv : props)
|
|
|
|
handler(kv.first, kv.second);
|
|
|
|
}
|
|
|
|
|
2016-07-05 11:01:22 +08:00
|
|
|
private:
|
2016-08-23 02:03:45 +08:00
|
|
|
using props_t =
|
2016-08-25 22:29:45 +08:00
|
|
|
std::unordered_map<prop_key_t, Property::sptr, PropertyHash<TG>>;
|
2016-07-05 11:01:22 +08:00
|
|
|
props_t props;
|
|
|
|
};
|