memgraph/poc/isolation/header.cpp

59 lines
1.2 KiB
C++
Raw Normal View History

2016-08-26 19:21:42 +08:00
#include "isolation/header.hpp"
#include "isolation/db.hpp"
template <class TO, class FROM>
TO &ref_as(FROM &ref)
{
return (*reinterpret_cast<TO *>(&ref));
}
2016-08-28 22:47:13 +08:00
// template <class TO, class FROM>
// TO value_as(FROM &&ref)
// {
// return std::move((*reinterpret_cast<TO *>(&ref)));
// }
2016-08-26 19:21:42 +08:00
2016-08-28 22:47:13 +08:00
sha::Accessor::Accessor(const sha::Accessor &other)
: Sized(sizeof(::Accessor), alignof(::Accessor))
2016-08-26 19:21:42 +08:00
{
2016-08-28 22:47:13 +08:00
as<::Accessor>() = other.as<::Accessor>();
2016-08-26 19:21:42 +08:00
}
2016-08-28 22:47:13 +08:00
sha::Accessor::Accessor(sha::Accessor &&other)
: Sized(sizeof(::Accessor), alignof(::Accessor))
2016-08-26 19:21:42 +08:00
{
2016-08-28 22:47:13 +08:00
as<::Accessor>() = value_as<::Accessor>(other);
2016-08-26 19:21:42 +08:00
}
2016-08-28 22:47:13 +08:00
sha::Accessor::~Accessor() { as<::Accessor>().~Accessor(); }
sha::Accessor &sha::Accessor::operator=(const sha::Accessor &other)
2016-08-26 19:21:42 +08:00
{
// TODO
return *this;
}
2016-08-28 22:47:13 +08:00
sha::Accessor &sha::Accessor::operator=(sha::Accessor &&other)
2016-08-26 19:21:42 +08:00
{
// TODO
return *this;
}
2016-08-29 01:04:00 +08:00
int sha::Accessor::get_prop(sha::Name &name) { return as<::Accessor>().data; }
2016-08-26 19:21:42 +08:00
sha::Accessor sha::Db::access()
{
2016-08-28 22:47:13 +08:00
auto &db = as<::Db>();
2016-08-26 19:21:42 +08:00
db.accessed++;
2016-08-28 22:47:13 +08:00
::Accessor acc;
2016-08-26 19:21:42 +08:00
acc.data = db.data;
2016-08-28 22:47:13 +08:00
return sha::Accessor(std::move(acc));
2016-08-26 19:21:42 +08:00
}
sha::Name &sha::Db::get_name(const char *str)
{
2016-08-28 22:47:13 +08:00
auto &db = as<::Db>();
2016-08-26 19:21:42 +08:00
db.accessed++;
return ref_as<sha::Name>(db.name);
}