Make Result constructors implicit
Reviewers: mferencevic, mtomic, msantl Reviewed By: mferencevic Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D2293
This commit is contained in:
parent
5bae9c6457
commit
e18cb7b4c7
@ -20,9 +20,9 @@ Result<bool> EdgeAccessor::SetProperty(PropertyId property,
|
||||
std::lock_guard<utils::SpinLock> guard(edge_->lock);
|
||||
|
||||
if (!PrepareForWrite(transaction_, edge_))
|
||||
return Result<bool>{Error::SERIALIZATION_ERROR};
|
||||
return Error::SERIALIZATION_ERROR;
|
||||
|
||||
if (edge_->deleted) return Result<bool>{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<bool> EdgeAccessor::SetProperty(PropertyId property,
|
||||
}
|
||||
}
|
||||
|
||||
return Result<bool>{existed};
|
||||
return existed;
|
||||
}
|
||||
|
||||
Result<PropertyValue> EdgeAccessor::GetProperty(PropertyId property,
|
||||
@ -87,8 +87,8 @@ Result<PropertyValue> EdgeAccessor::GetProperty(PropertyId property,
|
||||
break;
|
||||
}
|
||||
});
|
||||
if (deleted) return Result<PropertyValue>{Error::DELETED_OBJECT};
|
||||
return Result<PropertyValue>{std::move(value)};
|
||||
if (deleted) return Error::DELETED_OBJECT;
|
||||
return std::move(value);
|
||||
}
|
||||
|
||||
Result<std::map<PropertyId, PropertyValue>> EdgeAccessor::Properties(
|
||||
@ -138,9 +138,9 @@ Result<std::map<PropertyId, PropertyValue>> EdgeAccessor::Properties(
|
||||
}
|
||||
});
|
||||
if (deleted) {
|
||||
return Result<std::map<PropertyId, PropertyValue>>{Error::DELETED_OBJECT};
|
||||
return Error::DELETED_OBJECT;
|
||||
}
|
||||
return Result<std::map<PropertyId, PropertyValue>>{std::move(properties)};
|
||||
return std::move(properties);
|
||||
}
|
||||
|
||||
} // namespace storage
|
||||
|
@ -350,17 +350,17 @@ Result<bool> Storage::Accessor::DeleteVertex(VertexAccessor *vertex) {
|
||||
std::lock_guard<utils::SpinLock> guard(vertex_ptr->lock);
|
||||
|
||||
if (!PrepareForWrite(&transaction_, vertex_ptr))
|
||||
return Result<bool>{Error::SERIALIZATION_ERROR};
|
||||
return Error::SERIALIZATION_ERROR;
|
||||
|
||||
if (vertex_ptr->deleted) return Result<bool>{false};
|
||||
if (vertex_ptr->deleted) return false;
|
||||
|
||||
if (!vertex_ptr->in_edges.empty() || !vertex_ptr->out_edges.empty())
|
||||
return Result<bool>{Error::VERTEX_HAS_EDGES};
|
||||
return Error::VERTEX_HAS_EDGES;
|
||||
|
||||
CreateAndLinkDelta(&transaction_, vertex_ptr, Delta::RecreateObjectTag());
|
||||
vertex_ptr->deleted = true;
|
||||
|
||||
return Result<bool>{true};
|
||||
return true;
|
||||
}
|
||||
|
||||
Result<bool> Storage::Accessor::DetachDeleteVertex(VertexAccessor *vertex) {
|
||||
@ -376,9 +376,9 @@ Result<bool> Storage::Accessor::DetachDeleteVertex(VertexAccessor *vertex) {
|
||||
std::lock_guard<utils::SpinLock> guard(vertex_ptr->lock);
|
||||
|
||||
if (!PrepareForWrite(&transaction_, vertex_ptr))
|
||||
return Result<bool>{Error::SERIALIZATION_ERROR};
|
||||
return Error::SERIALIZATION_ERROR;
|
||||
|
||||
if (vertex_ptr->deleted) return Result<bool>{false};
|
||||
if (vertex_ptr->deleted) return false;
|
||||
|
||||
in_edges = vertex_ptr->in_edges;
|
||||
out_edges = vertex_ptr->out_edges;
|
||||
@ -414,14 +414,14 @@ Result<bool> Storage::Accessor::DetachDeleteVertex(VertexAccessor *vertex) {
|
||||
// meantime if we didn't have any edges to delete.
|
||||
|
||||
if (!PrepareForWrite(&transaction_, vertex_ptr))
|
||||
return Result<bool>{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<bool>{true};
|
||||
return true;
|
||||
}
|
||||
|
||||
Result<EdgeAccessor> Storage::Accessor::CreateEdge(VertexAccessor *from,
|
||||
@ -453,12 +453,12 @@ Result<EdgeAccessor> Storage::Accessor::CreateEdge(VertexAccessor *from,
|
||||
}
|
||||
|
||||
if (!PrepareForWrite(&transaction_, from_vertex))
|
||||
return Result<EdgeAccessor>{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<EdgeAccessor>{Error::SERIALIZATION_ERROR};
|
||||
return Error::SERIALIZATION_ERROR;
|
||||
CHECK(!to_vertex->deleted) << "Invalid database state!";
|
||||
}
|
||||
|
||||
@ -479,9 +479,8 @@ Result<EdgeAccessor> Storage::Accessor::CreateEdge(VertexAccessor *from,
|
||||
edge_type, from_vertex, edge);
|
||||
to_vertex->in_edges.emplace_back(edge_type, from_vertex, edge);
|
||||
|
||||
return Result<EdgeAccessor>{EdgeAccessor{edge, edge_type, from_vertex,
|
||||
to_vertex, &transaction_,
|
||||
&storage_->indices_}};
|
||||
return EdgeAccessor{edge, edge_type, from_vertex,
|
||||
to_vertex, &transaction_, &storage_->indices_};
|
||||
}
|
||||
|
||||
Result<bool> Storage::Accessor::DeleteEdge(EdgeAccessor *edge) {
|
||||
@ -494,9 +493,9 @@ Result<bool> Storage::Accessor::DeleteEdge(EdgeAccessor *edge) {
|
||||
std::lock_guard<utils::SpinLock> guard(edge_ptr->lock);
|
||||
|
||||
if (!PrepareForWrite(&transaction_, edge_ptr))
|
||||
return Result<bool>{Error::SERIALIZATION_ERROR};
|
||||
return Error::SERIALIZATION_ERROR;
|
||||
|
||||
if (edge_ptr->deleted) return Result<bool>{false};
|
||||
if (edge_ptr->deleted) return false;
|
||||
|
||||
auto from_vertex = edge->from_vertex_;
|
||||
auto to_vertex = edge->to_vertex_;
|
||||
@ -517,12 +516,12 @@ Result<bool> Storage::Accessor::DeleteEdge(EdgeAccessor *edge) {
|
||||
}
|
||||
|
||||
if (!PrepareForWrite(&transaction_, from_vertex))
|
||||
return Result<bool>{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<bool>{Error::SERIALIZATION_ERROR};
|
||||
return Error::SERIALIZATION_ERROR;
|
||||
CHECK(!to_vertex->deleted) << "Invalid database state!";
|
||||
}
|
||||
|
||||
@ -553,7 +552,7 @@ Result<bool> Storage::Accessor::DeleteEdge(EdgeAccessor *edge) {
|
||||
to_vertex->in_edges.pop_back();
|
||||
}
|
||||
|
||||
return Result<bool>{true};
|
||||
return true;
|
||||
}
|
||||
|
||||
const std::string &Storage::Accessor::LabelToName(LabelId label) const {
|
||||
|
@ -48,13 +48,13 @@ Result<bool> VertexAccessor::AddLabel(LabelId label) {
|
||||
std::lock_guard<utils::SpinLock> guard(vertex_->lock);
|
||||
|
||||
if (!PrepareForWrite(transaction_, vertex_))
|
||||
return Result<bool>{Error::SERIALIZATION_ERROR};
|
||||
return Error::SERIALIZATION_ERROR;
|
||||
|
||||
if (vertex_->deleted) return Result<bool>{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<bool>{false};
|
||||
return false;
|
||||
|
||||
CreateAndLinkDelta(transaction_, vertex_, Delta::RemoveLabelTag(), label);
|
||||
|
||||
@ -62,25 +62,25 @@ Result<bool> VertexAccessor::AddLabel(LabelId label) {
|
||||
|
||||
UpdateOnAddLabel(indices_, label, vertex_, *transaction_);
|
||||
|
||||
return Result<bool>{true};
|
||||
return true;
|
||||
}
|
||||
|
||||
Result<bool> VertexAccessor::RemoveLabel(LabelId label) {
|
||||
std::lock_guard<utils::SpinLock> guard(vertex_->lock);
|
||||
|
||||
if (!PrepareForWrite(transaction_, vertex_))
|
||||
return Result<bool>{Error::SERIALIZATION_ERROR};
|
||||
return Error::SERIALIZATION_ERROR;
|
||||
|
||||
if (vertex_->deleted) return Result<bool>{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<bool>{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<bool>{true};
|
||||
return true;
|
||||
}
|
||||
|
||||
Result<bool> VertexAccessor::HasLabel(LabelId label, View view) const {
|
||||
@ -127,8 +127,8 @@ Result<bool> VertexAccessor::HasLabel(LabelId label, View view) const {
|
||||
break;
|
||||
}
|
||||
});
|
||||
if (deleted) return Result<bool>{Error::DELETED_OBJECT};
|
||||
return Result<bool>{has_label};
|
||||
if (deleted) return Error::DELETED_OBJECT;
|
||||
return has_label;
|
||||
}
|
||||
|
||||
Result<std::vector<LabelId>> VertexAccessor::Labels(View view) const {
|
||||
@ -175,8 +175,8 @@ Result<std::vector<LabelId>> VertexAccessor::Labels(View view) const {
|
||||
break;
|
||||
}
|
||||
});
|
||||
if (deleted) return Result<std::vector<LabelId>>{Error::DELETED_OBJECT};
|
||||
return Result<std::vector<LabelId>>{std::move(labels)};
|
||||
if (deleted) return Error::DELETED_OBJECT;
|
||||
return std::move(labels);
|
||||
}
|
||||
|
||||
Result<bool> VertexAccessor::SetProperty(PropertyId property,
|
||||
@ -184,9 +184,9 @@ Result<bool> VertexAccessor::SetProperty(PropertyId property,
|
||||
std::lock_guard<utils::SpinLock> guard(vertex_->lock);
|
||||
|
||||
if (!PrepareForWrite(transaction_, vertex_))
|
||||
return Result<bool>{Error::SERIALIZATION_ERROR};
|
||||
return Error::SERIALIZATION_ERROR;
|
||||
|
||||
if (vertex_->deleted) return Result<bool>{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<bool> VertexAccessor::SetProperty(PropertyId property,
|
||||
|
||||
UpdateOnSetProperty(indices_, property, value, vertex_, *transaction_);
|
||||
|
||||
return Result<bool>{existed};
|
||||
return existed;
|
||||
}
|
||||
|
||||
Result<PropertyValue> VertexAccessor::GetProperty(PropertyId property,
|
||||
@ -253,8 +253,8 @@ Result<PropertyValue> VertexAccessor::GetProperty(PropertyId property,
|
||||
break;
|
||||
}
|
||||
});
|
||||
if (deleted) return Result<PropertyValue>{Error::DELETED_OBJECT};
|
||||
return Result<PropertyValue>{std::move(value)};
|
||||
if (deleted) return Error::DELETED_OBJECT;
|
||||
return std::move(value);
|
||||
}
|
||||
|
||||
Result<std::map<PropertyId, PropertyValue>> VertexAccessor::Properties(
|
||||
@ -304,9 +304,9 @@ Result<std::map<PropertyId, PropertyValue>> VertexAccessor::Properties(
|
||||
}
|
||||
});
|
||||
if (deleted) {
|
||||
return Result<std::map<PropertyId, PropertyValue>>{Error::DELETED_OBJECT};
|
||||
return Error::DELETED_OBJECT;
|
||||
}
|
||||
return Result<std::map<PropertyId, PropertyValue>>{std::move(properties)};
|
||||
return std::move(properties);
|
||||
}
|
||||
|
||||
Result<std::vector<EdgeAccessor>> VertexAccessor::InEdges(
|
||||
@ -361,7 +361,7 @@ Result<std::vector<EdgeAccessor>> VertexAccessor::InEdges(
|
||||
}
|
||||
});
|
||||
if (deleted) {
|
||||
return Result<std::vector<EdgeAccessor>>(Error::DELETED_OBJECT);
|
||||
return Error::DELETED_OBJECT;
|
||||
}
|
||||
std::vector<EdgeAccessor> ret;
|
||||
ret.reserve(in_edges.size());
|
||||
@ -373,7 +373,7 @@ Result<std::vector<EdgeAccessor>> VertexAccessor::InEdges(
|
||||
indices_);
|
||||
}
|
||||
}
|
||||
return Result<decltype(ret)>(std::move(ret));
|
||||
return std::move(ret);
|
||||
}
|
||||
|
||||
Result<std::vector<EdgeAccessor>> VertexAccessor::OutEdges(
|
||||
@ -428,7 +428,7 @@ Result<std::vector<EdgeAccessor>> VertexAccessor::OutEdges(
|
||||
}
|
||||
});
|
||||
if (deleted) {
|
||||
return Result<std::vector<EdgeAccessor>>(Error::DELETED_OBJECT);
|
||||
return Error::DELETED_OBJECT;
|
||||
}
|
||||
std::vector<EdgeAccessor> ret;
|
||||
ret.reserve(out_edges.size());
|
||||
@ -440,7 +440,7 @@ Result<std::vector<EdgeAccessor>> VertexAccessor::OutEdges(
|
||||
indices_);
|
||||
}
|
||||
}
|
||||
return Result<decltype(ret)>(std::move(ret));
|
||||
return std::move(ret);
|
||||
}
|
||||
|
||||
} // namespace storage
|
||||
|
@ -10,10 +10,10 @@ namespace utils {
|
||||
template <class TError, class TValue>
|
||||
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(); }
|
||||
|
Loading…
Reference in New Issue
Block a user