2015-12-08 04:51:55 +08:00
|
|
|
#pragma once
|
2015-08-30 07:12:46 +08:00
|
|
|
|
2016-02-14 00:59:48 +08:00
|
|
|
#include <cassert>
|
2016-08-18 22:34:36 +08:00
|
|
|
#include <memory>
|
2016-02-21 00:53:09 +08:00
|
|
|
#include <ostream>
|
2016-08-18 22:34:36 +08:00
|
|
|
#include <string>
|
2016-07-02 05:05:03 +08:00
|
|
|
#include <vector>
|
2015-08-30 07:12:46 +08:00
|
|
|
|
2016-08-18 22:34:36 +08:00
|
|
|
#include "storage/model/properties/flags.hpp"
|
2015-10-14 02:17:45 +08:00
|
|
|
#include "utils/underlying_cast.hpp"
|
2015-08-31 03:23:48 +08:00
|
|
|
|
2016-02-14 00:59:48 +08:00
|
|
|
class Null;
|
|
|
|
|
|
|
|
class Property
|
2015-08-30 07:12:46 +08:00
|
|
|
{
|
2016-02-14 00:59:48 +08:00
|
|
|
public:
|
2015-08-30 07:12:46 +08:00
|
|
|
using sptr = std::shared_ptr<Property>;
|
|
|
|
|
2016-02-14 00:59:48 +08:00
|
|
|
static const Null Null;
|
|
|
|
|
2016-07-05 11:01:22 +08:00
|
|
|
Property(Flags flags);
|
2015-10-14 02:17:45 +08:00
|
|
|
|
2016-08-18 22:34:36 +08:00
|
|
|
virtual bool operator==(const Property &other) const = 0;
|
2016-02-14 00:59:48 +08:00
|
|
|
|
2016-08-18 22:34:36 +08:00
|
|
|
bool operator!=(const Property &other) const;
|
2015-08-31 03:23:48 +08:00
|
|
|
|
|
|
|
template <class T>
|
2016-02-14 00:59:48 +08:00
|
|
|
bool is() const
|
2015-08-31 03:23:48 +08:00
|
|
|
{
|
2016-02-14 00:59:48 +08:00
|
|
|
return underlying_cast(flags) & underlying_cast(T::type);
|
2015-08-31 03:23:48 +08:00
|
|
|
}
|
2015-10-14 02:17:45 +08:00
|
|
|
|
2016-02-14 00:59:48 +08:00
|
|
|
template <class T>
|
2016-08-18 22:34:36 +08:00
|
|
|
T &as()
|
2015-10-14 02:17:45 +08:00
|
|
|
{
|
2016-02-14 00:59:48 +08:00
|
|
|
assert(this->is<T>());
|
2016-08-18 22:34:36 +08:00
|
|
|
return *static_cast<T *>(this);
|
2015-10-14 02:17:45 +08:00
|
|
|
}
|
2015-08-30 07:12:46 +08:00
|
|
|
|
2016-02-14 00:59:48 +08:00
|
|
|
template <class T>
|
2016-08-18 22:34:36 +08:00
|
|
|
const T &as() const
|
2016-02-14 00:59:48 +08:00
|
|
|
{
|
|
|
|
assert(this->is<T>());
|
2016-08-18 22:34:36 +08:00
|
|
|
return *static_cast<const T *>(this);
|
2016-02-14 00:59:48 +08:00
|
|
|
}
|
2015-10-14 02:17:45 +08:00
|
|
|
|
2016-08-18 22:34:36 +08:00
|
|
|
virtual std::ostream &print(std::ostream &stream) const = 0;
|
2016-02-21 00:53:09 +08:00
|
|
|
|
2016-08-18 22:34:36 +08:00
|
|
|
friend std::ostream &operator<<(std::ostream &stream, const Property &prop);
|
2016-07-05 11:01:22 +08:00
|
|
|
|
2016-02-14 00:59:48 +08:00
|
|
|
const Flags flags;
|
2015-10-14 02:17:45 +08:00
|
|
|
};
|
|
|
|
|
2016-07-02 05:05:03 +08:00
|
|
|
using properties_t = std::vector<Property::sptr>;
|