From e18cb7b4c7c21d7f6fe84f9221f9550f4c4c49c7 Mon Sep 17 00:00:00 2001 From: Teon Banek Date: Thu, 8 Aug 2019 13:57:54 +0200 Subject: [PATCH] Make Result constructors implicit Reviewers: mferencevic, mtomic, msantl Reviewed By: mferencevic Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D2293 --- src/storage/v2/edge_accessor.cpp | 14 ++++----- src/storage/v2/storage.cpp | 35 +++++++++++------------ src/storage/v2/vertex_accessor.cpp | 46 +++++++++++++++--------------- src/utils/result.hpp | 8 +++--- 4 files changed, 51 insertions(+), 52 deletions(-) diff --git a/src/storage/v2/edge_accessor.cpp b/src/storage/v2/edge_accessor.cpp index 4c6dc6a49..5a8b7df00 100644 --- a/src/storage/v2/edge_accessor.cpp +++ b/src/storage/v2/edge_accessor.cpp @@ -20,9 +20,9 @@ Result EdgeAccessor::SetProperty(PropertyId property, std::lock_guard guard(edge_->lock); if (!PrepareForWrite(transaction_, edge_)) - return Result{Error::SERIALIZATION_ERROR}; + return Error::SERIALIZATION_ERROR; - if (edge_->deleted) return Result{Error::DELETED_OBJECT}; + if (edge_->deleted) return Error::DELETED_OBJECT; auto it = edge_->properties.find(property); bool existed = it != edge_->properties.end(); @@ -44,7 +44,7 @@ Result EdgeAccessor::SetProperty(PropertyId property, } } - return Result{existed}; + return existed; } Result EdgeAccessor::GetProperty(PropertyId property, @@ -87,8 +87,8 @@ Result EdgeAccessor::GetProperty(PropertyId property, break; } }); - if (deleted) return Result{Error::DELETED_OBJECT}; - return Result{std::move(value)}; + if (deleted) return Error::DELETED_OBJECT; + return std::move(value); } Result> EdgeAccessor::Properties( @@ -138,9 +138,9 @@ Result> EdgeAccessor::Properties( } }); if (deleted) { - return Result>{Error::DELETED_OBJECT}; + return Error::DELETED_OBJECT; } - return Result>{std::move(properties)}; + return std::move(properties); } } // namespace storage diff --git a/src/storage/v2/storage.cpp b/src/storage/v2/storage.cpp index 377ff1453..435a9af6e 100644 --- a/src/storage/v2/storage.cpp +++ b/src/storage/v2/storage.cpp @@ -350,17 +350,17 @@ Result Storage::Accessor::DeleteVertex(VertexAccessor *vertex) { std::lock_guard guard(vertex_ptr->lock); if (!PrepareForWrite(&transaction_, vertex_ptr)) - return Result{Error::SERIALIZATION_ERROR}; + return Error::SERIALIZATION_ERROR; - if (vertex_ptr->deleted) return Result{false}; + if (vertex_ptr->deleted) return false; if (!vertex_ptr->in_edges.empty() || !vertex_ptr->out_edges.empty()) - return Result{Error::VERTEX_HAS_EDGES}; + return Error::VERTEX_HAS_EDGES; CreateAndLinkDelta(&transaction_, vertex_ptr, Delta::RecreateObjectTag()); vertex_ptr->deleted = true; - return Result{true}; + return true; } Result Storage::Accessor::DetachDeleteVertex(VertexAccessor *vertex) { @@ -376,9 +376,9 @@ Result Storage::Accessor::DetachDeleteVertex(VertexAccessor *vertex) { std::lock_guard guard(vertex_ptr->lock); if (!PrepareForWrite(&transaction_, vertex_ptr)) - return Result{Error::SERIALIZATION_ERROR}; + return Error::SERIALIZATION_ERROR; - if (vertex_ptr->deleted) return Result{false}; + if (vertex_ptr->deleted) return false; in_edges = vertex_ptr->in_edges; out_edges = vertex_ptr->out_edges; @@ -414,14 +414,14 @@ Result Storage::Accessor::DetachDeleteVertex(VertexAccessor *vertex) { // meantime if we didn't have any edges to delete. if (!PrepareForWrite(&transaction_, vertex_ptr)) - return Result{Error::SERIALIZATION_ERROR}; + return Error::SERIALIZATION_ERROR; CHECK(!vertex_ptr->deleted) << "Invalid database state!"; CreateAndLinkDelta(&transaction_, vertex_ptr, Delta::RecreateObjectTag()); vertex_ptr->deleted = true; - return Result{true}; + return true; } Result Storage::Accessor::CreateEdge(VertexAccessor *from, @@ -453,12 +453,12 @@ Result Storage::Accessor::CreateEdge(VertexAccessor *from, } if (!PrepareForWrite(&transaction_, from_vertex)) - return Result{Error::SERIALIZATION_ERROR}; + return Error::SERIALIZATION_ERROR; CHECK(!from_vertex->deleted) << "Invalid database state!"; if (to_vertex != from_vertex) { if (!PrepareForWrite(&transaction_, to_vertex)) - return Result{Error::SERIALIZATION_ERROR}; + return Error::SERIALIZATION_ERROR; CHECK(!to_vertex->deleted) << "Invalid database state!"; } @@ -479,9 +479,8 @@ Result Storage::Accessor::CreateEdge(VertexAccessor *from, edge_type, from_vertex, edge); to_vertex->in_edges.emplace_back(edge_type, from_vertex, edge); - return Result{EdgeAccessor{edge, edge_type, from_vertex, - to_vertex, &transaction_, - &storage_->indices_}}; + return EdgeAccessor{edge, edge_type, from_vertex, + to_vertex, &transaction_, &storage_->indices_}; } Result Storage::Accessor::DeleteEdge(EdgeAccessor *edge) { @@ -494,9 +493,9 @@ Result Storage::Accessor::DeleteEdge(EdgeAccessor *edge) { std::lock_guard guard(edge_ptr->lock); if (!PrepareForWrite(&transaction_, edge_ptr)) - return Result{Error::SERIALIZATION_ERROR}; + return Error::SERIALIZATION_ERROR; - if (edge_ptr->deleted) return Result{false}; + if (edge_ptr->deleted) return false; auto from_vertex = edge->from_vertex_; auto to_vertex = edge->to_vertex_; @@ -517,12 +516,12 @@ Result Storage::Accessor::DeleteEdge(EdgeAccessor *edge) { } if (!PrepareForWrite(&transaction_, from_vertex)) - return Result{Error::SERIALIZATION_ERROR}; + return Error::SERIALIZATION_ERROR; CHECK(!from_vertex->deleted) << "Invalid database state!"; if (to_vertex != from_vertex) { if (!PrepareForWrite(&transaction_, to_vertex)) - return Result{Error::SERIALIZATION_ERROR}; + return Error::SERIALIZATION_ERROR; CHECK(!to_vertex->deleted) << "Invalid database state!"; } @@ -553,7 +552,7 @@ Result Storage::Accessor::DeleteEdge(EdgeAccessor *edge) { to_vertex->in_edges.pop_back(); } - return Result{true}; + return true; } const std::string &Storage::Accessor::LabelToName(LabelId label) const { diff --git a/src/storage/v2/vertex_accessor.cpp b/src/storage/v2/vertex_accessor.cpp index c118fe9c9..7cf4d8e7a 100644 --- a/src/storage/v2/vertex_accessor.cpp +++ b/src/storage/v2/vertex_accessor.cpp @@ -48,13 +48,13 @@ Result VertexAccessor::AddLabel(LabelId label) { std::lock_guard guard(vertex_->lock); if (!PrepareForWrite(transaction_, vertex_)) - return Result{Error::SERIALIZATION_ERROR}; + return Error::SERIALIZATION_ERROR; - if (vertex_->deleted) return Result{Error::DELETED_OBJECT}; + if (vertex_->deleted) return Error::DELETED_OBJECT; if (std::find(vertex_->labels.begin(), vertex_->labels.end(), label) != vertex_->labels.end()) - return Result{false}; + return false; CreateAndLinkDelta(transaction_, vertex_, Delta::RemoveLabelTag(), label); @@ -62,25 +62,25 @@ Result VertexAccessor::AddLabel(LabelId label) { UpdateOnAddLabel(indices_, label, vertex_, *transaction_); - return Result{true}; + return true; } Result VertexAccessor::RemoveLabel(LabelId label) { std::lock_guard guard(vertex_->lock); if (!PrepareForWrite(transaction_, vertex_)) - return Result{Error::SERIALIZATION_ERROR}; + return Error::SERIALIZATION_ERROR; - if (vertex_->deleted) return Result{Error::DELETED_OBJECT}; + if (vertex_->deleted) return Error::DELETED_OBJECT; auto it = std::find(vertex_->labels.begin(), vertex_->labels.end(), label); - if (it == vertex_->labels.end()) return Result{false}; + if (it == vertex_->labels.end()) return false; CreateAndLinkDelta(transaction_, vertex_, Delta::AddLabelTag(), label); std::swap(*it, *vertex_->labels.rbegin()); vertex_->labels.pop_back(); - return Result{true}; + return true; } Result VertexAccessor::HasLabel(LabelId label, View view) const { @@ -127,8 +127,8 @@ Result VertexAccessor::HasLabel(LabelId label, View view) const { break; } }); - if (deleted) return Result{Error::DELETED_OBJECT}; - return Result{has_label}; + if (deleted) return Error::DELETED_OBJECT; + return has_label; } Result> VertexAccessor::Labels(View view) const { @@ -175,8 +175,8 @@ Result> VertexAccessor::Labels(View view) const { break; } }); - if (deleted) return Result>{Error::DELETED_OBJECT}; - return Result>{std::move(labels)}; + if (deleted) return Error::DELETED_OBJECT; + return std::move(labels); } Result VertexAccessor::SetProperty(PropertyId property, @@ -184,9 +184,9 @@ Result VertexAccessor::SetProperty(PropertyId property, std::lock_guard guard(vertex_->lock); if (!PrepareForWrite(transaction_, vertex_)) - return Result{Error::SERIALIZATION_ERROR}; + return Error::SERIALIZATION_ERROR; - if (vertex_->deleted) return Result{Error::DELETED_OBJECT}; + if (vertex_->deleted) return Error::DELETED_OBJECT; auto it = vertex_->properties.find(property); bool existed = it != vertex_->properties.end(); @@ -210,7 +210,7 @@ Result VertexAccessor::SetProperty(PropertyId property, UpdateOnSetProperty(indices_, property, value, vertex_, *transaction_); - return Result{existed}; + return existed; } Result VertexAccessor::GetProperty(PropertyId property, @@ -253,8 +253,8 @@ Result VertexAccessor::GetProperty(PropertyId property, break; } }); - if (deleted) return Result{Error::DELETED_OBJECT}; - return Result{std::move(value)}; + if (deleted) return Error::DELETED_OBJECT; + return std::move(value); } Result> VertexAccessor::Properties( @@ -304,9 +304,9 @@ Result> VertexAccessor::Properties( } }); if (deleted) { - return Result>{Error::DELETED_OBJECT}; + return Error::DELETED_OBJECT; } - return Result>{std::move(properties)}; + return std::move(properties); } Result> VertexAccessor::InEdges( @@ -361,7 +361,7 @@ Result> VertexAccessor::InEdges( } }); if (deleted) { - return Result>(Error::DELETED_OBJECT); + return Error::DELETED_OBJECT; } std::vector ret; ret.reserve(in_edges.size()); @@ -373,7 +373,7 @@ Result> VertexAccessor::InEdges( indices_); } } - return Result(std::move(ret)); + return std::move(ret); } Result> VertexAccessor::OutEdges( @@ -428,7 +428,7 @@ Result> VertexAccessor::OutEdges( } }); if (deleted) { - return Result>(Error::DELETED_OBJECT); + return Error::DELETED_OBJECT; } std::vector ret; ret.reserve(out_edges.size()); @@ -440,7 +440,7 @@ Result> VertexAccessor::OutEdges( indices_); } } - return Result(std::move(ret)); + return std::move(ret); } } // namespace storage diff --git a/src/utils/result.hpp b/src/utils/result.hpp index f4c11d33d..375407ece 100644 --- a/src/utils/result.hpp +++ b/src/utils/result.hpp @@ -10,10 +10,10 @@ namespace utils { template class [[nodiscard]] BasicResult final { public: - explicit BasicResult(const TValue &value) : value_(value) {} - explicit BasicResult(TValue &&value) noexcept : value_(std::move(value)) {} - explicit BasicResult(const TError &error) : error_(error) {} - explicit BasicResult(TError &&error) noexcept : error_(std::move(error)) {} + BasicResult(const TValue &value) : value_(value) {} + BasicResult(TValue &&value) noexcept : value_(std::move(value)) {} + BasicResult(const TError &error) : error_(error) {} + BasicResult(TError &&error) noexcept : error_(std::move(error)) {} bool HasValue() const { return value_.has_value(); } bool HasError() const { return error_.has_value(); }