From fc71e9930b491efb12612a08a2792c6e0746e2fb Mon Sep 17 00:00:00 2001 From: Kruno Tomola Fabro Date: Sun, 28 Aug 2016 18:04:00 +0100 Subject: [PATCH] commit before changing profile.cpp --- include/barrier/barrier.hpp | 5 +- include/barrier/common.hpp | 10 +- include/query_engine/hardcode/queries.hpp | 11 -- poc/isolation/header.cpp | 5 +- src/barrier/barrier.cpp | 153 +++++++++------------- 5 files changed, 68 insertions(+), 116 deletions(-) diff --git a/include/barrier/barrier.hpp b/include/barrier/barrier.hpp index 1f712d8dd..d86dbce82 100644 --- a/include/barrier/barrier.hpp +++ b/include/barrier/barrier.hpp @@ -14,6 +14,8 @@ namespace barrier // barrier class defined here. // ************ Here should be forward declarations of Sized barrier classes +class DbAccessor; // DONE // .cpp + class VertexAccessor; // DONE // .cpp class EdgeAccessor; // DONE // .cpp @@ -40,8 +42,7 @@ class BoltSerializer; // DONE // .cpp class Label; // DONE // .cpp class EdgeType; // DONE // .cpp -class Db; -class DbAccessor; // DONE // .cpp +class Db; // DONE // .cpp class VertexPropertyFamily; // DONE // .cpp class EdgePropertyFamily; // DONE // .cpp diff --git a/include/barrier/common.hpp b/include/barrier/common.hpp index 538f00db6..75b2bdbe6 100644 --- a/include/barrier/common.hpp +++ b/include/barrier/common.hpp @@ -102,11 +102,8 @@ protected: // with T which it holds where T is original class from memgraph. template Sized(T &&d) - : data(value_as< - typename std::aligned_storage::type>( - std::move(d))) { - + new (ptr_as(&data)) T(std::move(d)); static_assert(size_B == sizeof(T), "Border class size mismatch"); static_assert(alignment_B == alignof(T), "Border class aligment mismatch"); @@ -117,11 +114,8 @@ protected: // with T which it holds where T is original class from memgraph. template Sized(const T &&d) - : data(value_as< - const typename std::aligned_storage::type>( - std::move(d))) { - + new (ptr_as(&data)) T(std::move(d)); static_assert(size_B == sizeof(T), "Border class size mismatch"); static_assert(alignment_B == alignof(T), "Border class aligment mismatch"); diff --git a/include/query_engine/hardcode/queries.hpp b/include/query_engine/hardcode/queries.hpp index 5e0f7a04b..df042073c 100644 --- a/include/query_engine/hardcode/queries.hpp +++ b/include/query_engine/hardcode/queries.hpp @@ -3,17 +3,6 @@ #include #include -// #include "database/db.hpp" -// #include "database/db_accessor.cpp" -// #include "database/db_accessor.hpp" -// #include "query_engine/query_stripper.hpp" -// #include "query_engine/util.hpp" -// #include "storage/indexes/impl/nonunique_unordered_index.cpp" -// #include "storage/model/properties/property.hpp" -// #include "storage/model/properties/property_family.hpp" -// #include "utils/command_line/arguments.hpp" -// #include "utils/iterator/iterator.hpp" - #include "barrier/barrier.hpp" using namespace std; diff --git a/poc/isolation/header.cpp b/poc/isolation/header.cpp index 337949626..a483622a2 100644 --- a/poc/isolation/header.cpp +++ b/poc/isolation/header.cpp @@ -39,10 +39,7 @@ sha::Accessor &sha::Accessor::operator=(sha::Accessor &&other) return *this; } -int sha::Accessor::get_prop(sha::Name &name) -{ - return as<::Accessor>().data; -} +int sha::Accessor::get_prop(sha::Name &name) { return as<::Accessor>().data; } sha::Accessor sha::Db::access() { diff --git a/src/barrier/barrier.cpp b/src/barrier/barrier.cpp index 6f38804f1..bad485470 100644 --- a/src/barrier/barrier.cpp +++ b/src/barrier/barrier.cpp @@ -69,6 +69,32 @@ { \ return ptr_as(l); \ } +#define DESTRUCTOR(x, y) \ + x::~x() { HALF_CALL(~y()); } +#define COPY_CONSTRUCTOR(x, y) \ + x::x(const x &other) : Sized(y(trans(other))) {} +#define MOVE_CONSTRUCTOR(x) \ + x::x(x &&other) : Sized(trans(std::move(other))) {} +#define MOVE_CONST_CONSTRUCTOR(x) \ + x::x(x const &&other) : Sized(trans(std::move(other))) {} + +// For certain classes trans evaluates into ref which doesnt work for Sized +// constructor. This Move forces type. +#define MOVE_CONSTRUCTOR_FORCED(x, y) \ + x::x(x &&other) : Sized(value_as(std::move(other))) {} + +#define COPY_OPERATOR(x) \ + x &x::operator=(const x &other) \ + { \ + HALF_CALL(operator=(trans(other))); \ + return *this; \ + } +#define MOVE_OPERATOR(x) \ + x &x::operator=(x &&other) \ + { \ + HALF_CALL(operator=(trans(std::move(other)))); \ + return *this; \ + } #define VALID_CONSTRUCTION(x, y) \ template <> \ @@ -152,7 +178,8 @@ TRANSFORM_REF(VertexPropertyKey, ::VertexPropertyFamily::PropertyType::PropertyFamilyKey); TRANSFORM_REF(EdgePropertyKey, ::EdgePropertyFamily::PropertyType::PropertyFamilyKey); -TRANSFORM_REF(VertexIterator, IteratorBase *); +TRANSFORM_REF(VertexIterator, + std::unique_ptr>); TRANSFORM_REF(EdgeIterator, std::unique_ptr>); TRANSFORM_REF(VertexAccessIterator, vertex_access_iterator_t); @@ -185,9 +212,19 @@ TRANSFORM_VALUE(EdgePropertyKey, TRANSFORM_VALUE(VertexPropertyKey, ::VertexPropertyFamily::PropertyType::PropertyFamilyKey); TRANSFORM_VALUE_ONE(VertexAccessIterator, vertex_access_iterator_t); +MOVE_CONSTRUCTOR_FORCED(VertexAccessIterator, vertex_access_iterator_t); TRANSFORM_VALUE_ONE(OutEdgesIterator, out_edge_iterator_t); +MOVE_CONSTRUCTOR_FORCED(OutEdgesIterator, out_edge_iterator_t); TRANSFORM_VALUE_ONE(InEdgesIterator, in_edge_iterator_t); -TRANSFORM_VALUE_ONE(VertexIterator, IteratorBase *); +MOVE_CONSTRUCTOR_FORCED(InEdgesIterator, in_edge_iterator_t); +TRANSFORM_VALUE_ONE(VertexIterator, + std::unique_ptr>); +MOVE_CONSTRUCTOR_FORCED(VertexIterator, + std::unique_ptr>); +TRANSFORM_VALUE_ONE(EdgeIterator, + std::unique_ptr>); +MOVE_CONSTRUCTOR_FORCED(EdgeIterator, + std::unique_ptr>); template TRANSFORM_VALUE_ONE_RAW( @@ -247,12 +284,7 @@ INSTANTIATE_FOR_PROPERTY(FOR_ALL_PROPS_delete_EdgePropertyType) INSTANTIATE_FOR_PROPERTY(FOR_ALL_PROPS_delete_VertexPropertyType) // ***************** Label -VertexIndex &Label::index() const -{ - auto &index = HALF_CALL(index()); - IndexBase &ib = index; - return trans(ib); -} +VertexIndex &Label::index() const { return CALL(index()); } // **************** EdgeType EdgeIndex &EdgeType::index() const { return CALL(index()); } @@ -262,8 +294,7 @@ template VertexIterator VertexIndex::for_range(DbAccessor &t, Border from, Border to) { - // auto ret = THIS->for_range(trans(t), std::move(from), std::move(to)); - return CALL(for_range(trans(t), std::move(from), std::move(to)).release()); + return CALL(for_range(trans(t), std::move(from), std::move(to))); } template @@ -299,8 +330,7 @@ Order EdgeIndex::order() } // ************************* DbAccessor - -DbAccessor::~DbAccessor() { THIS->~DbAccessor(); } +DESTRUCTOR(DbAccessor, DbAccessor); VertexAccessIterator DbAccessor::vertex_access() { @@ -393,29 +423,12 @@ bool DbAccessor::commit() { return HALF_CALL(commit()); } void DbAccessor::abort() { HALF_CALL(abort()); } // ************************** VertexAccessor -VertexAccessor::VertexAccessor(const VertexAccessor &other) - : Sized(::VertexAccessor(trans(other))) -{ -} -VertexAccessor::VertexAccessor(VertexAccessor &&other) : Sized(std::move(other)) -{ -} -VertexAccessor::VertexAccessor(VertexAccessor const &&other) - : Sized(std::move(other)) -{ -} -VertexAccessor::~VertexAccessor() { HALF_CALL(~VertexAccessor()); } - -VertexAccessor &VertexAccessor::operator=(const VertexAccessor &other) -{ - HALF_CALL(operator=(trans(other))); - return *this; -} -VertexAccessor &VertexAccessor::operator=(VertexAccessor &&other) -{ - HALF_CALL(operator=(trans(std::move(other)))); - return *this; -} +DUP(VertexAccessor, COPY_CONSTRUCTOR); +MOVE_CONSTRUCTOR(VertexAccessor); +MOVE_CONST_CONSTRUCTOR(VertexAccessor); +DESTRUCTOR(VertexAccessor, VertexAccessor); +COPY_OPERATOR(VertexAccessor); +MOVE_OPERATOR(VertexAccessor); size_t VertexAccessor::out_degree() const { return HALF_CALL(out_degree()); } @@ -523,26 +536,12 @@ bool operator!=(const VertexAccessor &a, const VertexAccessor &b) } // ************************** EdgeAccessor -EdgeAccessor::EdgeAccessor(const EdgeAccessor &other) - : Sized(::EdgeAccessor(trans(other))) -{ -} -EdgeAccessor::EdgeAccessor(EdgeAccessor &&other) : Sized(std::move(other)) {} -EdgeAccessor::EdgeAccessor(EdgeAccessor const &&other) : Sized(std::move(other)) -{ -} -EdgeAccessor::~EdgeAccessor() { HALF_CALL(~EdgeAccessor()); } - -EdgeAccessor &EdgeAccessor::operator=(const EdgeAccessor &other) -{ - HALF_CALL(operator=(trans(other))); - return *this; -} -EdgeAccessor &EdgeAccessor::operator=(EdgeAccessor &&other) -{ - HALF_CALL(operator=(trans(std::move(other)))); - return *this; -} +DUP(EdgeAccessor, COPY_CONSTRUCTOR); +MOVE_CONSTRUCTOR(EdgeAccessor); +MOVE_CONST_CONSTRUCTOR(EdgeAccessor); +DESTRUCTOR(EdgeAccessor, EdgeAccessor); +COPY_OPERATOR(EdgeAccessor); +MOVE_OPERATOR(EdgeAccessor); void EdgeAccessor::edge_type(const EdgeType &edge_type) { @@ -623,25 +622,15 @@ bool operator!=(const EdgeAccessor &a, const EdgeAccessor &b) } // ************************* VertexIterator -VertexIterator::VertexIterator(VertexIterator &&other) : Sized(std::move(other)) -{ - trans(other) = nullptr; -} - -VertexIterator::~VertexIterator() -{ - if (*THIS != nullptr) delete (*THIS); -} +DESTRUCTOR(VertexIterator, unique_ptr); Option VertexIterator::next() { - return ((*THIS)->next()).map(); + return HALF_CALL(get()->next()).map(); } // ************************* EdgeIterator -EdgeIterator::EdgeIterator(EdgeIterator &&other) : Sized(std::move(other)) {} - -EdgeIterator::~EdgeIterator() { HALF_CALL(~unique_ptr()); } +DESTRUCTOR(EdgeIterator, unique_ptr); Option EdgeIterator::next() { @@ -649,12 +638,7 @@ Option EdgeIterator::next() } // ************************* OutEdgesIterator -OutEdgesIterator::OutEdgesIterator(OutEdgesIterator &&other) - : Sized(std::move(other)) -{ -} - -OutEdgesIterator::~OutEdgesIterator() { HALF_CALL(~out_edge_iterator_t()); } +DESTRUCTOR(OutEdgesIterator, out_edge_iterator_t); Option OutEdgesIterator::next() { @@ -662,12 +646,7 @@ Option OutEdgesIterator::next() } // ************************* InEdgesIterator -InEdgesIterator::InEdgesIterator(InEdgesIterator &&other) - : Sized(std::move(other)) -{ -} - -InEdgesIterator::~InEdgesIterator() { HALF_CALL(~in_edge_iterator_t()); } +DESTRUCTOR(InEdgesIterator, in_edge_iterator_t); Option InEdgesIterator::next() { @@ -675,15 +654,7 @@ Option InEdgesIterator::next() } // ************************* VertexAccessIterator -VertexAccessIterator::VertexAccessIterator(VertexAccessIterator &&other) - : Sized(std::move(other)) -{ -} - -VertexAccessIterator::~VertexAccessIterator() -{ - HALF_CALL(~vertex_access_iterator_t()); -} +DESTRUCTOR(VertexAccessIterator, vertex_access_iterator_t); Option VertexAccessIterator::next() { @@ -691,10 +662,10 @@ Option VertexAccessIterator::next() } // ************************* VertexPropertyKey -VertexPropertyKey::~VertexPropertyKey() { HALF_CALL(~PropertyFamilyKey()); } +DESTRUCTOR(VertexPropertyKey, PropertyFamilyKey); // ************************* EdgePropertyKey -EdgePropertyKey::~EdgePropertyKey() { HALF_CALL(~PropertyFamilyKey()); } +DESTRUCTOR(EdgePropertyKey, PropertyFamilyKey); // ************************* VertexPropertyFamily OptionPtr> VertexPropertyFamily::index()