memgraph/include/storage/model/properties/property.hpp

55 lines
1.0 KiB
C++
Raw Normal View History

#pragma once
#include <cassert>
#include <memory>
2016-02-21 00:53:09 +08:00
#include <ostream>
#include <string>
#include <vector>
#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
class Null;
class Property
{
public:
using sptr = std::shared_ptr<Property>;
static const Null Null;
Property(Flags flags);
2015-10-14 02:17:45 +08:00
virtual bool operator==(const Property &other) const = 0;
bool operator!=(const Property &other) const;
2015-08-31 03:23:48 +08:00
template <class T>
bool is() const
2015-08-31 03:23: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
template <class T>
T &as()
2015-10-14 02:17:45 +08:00
{
assert(this->is<T>());
return *static_cast<T *>(this);
2015-10-14 02:17:45 +08:00
}
template <class T>
const T &as() const
{
assert(this->is<T>());
return *static_cast<const T *>(this);
}
2015-10-14 02:17:45 +08:00
virtual std::ostream &print(std::ostream &stream) const = 0;
2016-02-21 00:53:09 +08:00
friend std::ostream &operator<<(std::ostream &stream, const Property &prop);
const Flags flags;
2015-10-14 02:17:45 +08:00
};
using properties_t = std::vector<Property::sptr>;