2015-08-30 07:12:46 +08:00
|
|
|
#ifndef MEMGRAPH_STORAGE_MODEL_PROPERTIES_PROPERTY_HPP
|
|
|
|
#define MEMGRAPH_STORAGE_MODEL_PROPERTIES_PROPERTY_HPP
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
|
2015-09-13 17:34:17 +08:00
|
|
|
namespace model
|
2015-08-31 03:23:48 +08:00
|
|
|
{
|
|
|
|
|
2015-08-30 07:12:46 +08:00
|
|
|
class Property
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
using sptr = std::shared_ptr<Property>;
|
|
|
|
|
2015-10-12 02:59:27 +08:00
|
|
|
template <class T, class... Args>
|
|
|
|
static Property::sptr make(Args&&... args)
|
|
|
|
{
|
|
|
|
return std::shared_ptr<Property>(new T(std::forward<Args>(args)...));
|
|
|
|
}
|
|
|
|
|
|
|
|
Property() = default;
|
|
|
|
virtual ~Property() = default;
|
|
|
|
|
2015-08-30 07:12:46 +08:00
|
|
|
virtual void dump(std::string& buffer) = 0;
|
2015-08-31 03:23:48 +08:00
|
|
|
|
|
|
|
template <class T>
|
|
|
|
T* as()
|
|
|
|
{
|
|
|
|
// return dynamic_cast<T*>(this);
|
|
|
|
|
|
|
|
// http://stackoverflow.com/questions/579887/how-expensive-is-rtti
|
|
|
|
// so... typeid is 20x faster! but there are some caveats, use with
|
|
|
|
// caution. read CAREFULLY what those people are saying.
|
|
|
|
// should be ok to use in this situation because all types used by
|
|
|
|
// this comparison are local and compile together with this code
|
|
|
|
// and we're compiling it only for linux with gcc/clang and we will
|
|
|
|
// not use any classes from third party libraries in this function.
|
|
|
|
if(typeid(T*) == typeid(this))
|
|
|
|
return static_cast<T*>(this);
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
2015-08-30 07:12:46 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
class Value : public Property
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Value(T value) : value(value) {}
|
|
|
|
T value;
|
|
|
|
};
|
|
|
|
|
2015-08-31 03:23:48 +08:00
|
|
|
}
|
|
|
|
|
2015-08-30 07:12:46 +08:00
|
|
|
#endif
|