You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by wi...@apache.org on 2016/05/02 11:49:53 UTC
[16/50] [abbrv] marmotta git commit: backport implementation of
std::make_unique from C++14 and use it
backport implementation of std::make_unique from C++14 and use it
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/4eb074dc
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/4eb074dc
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/4eb074dc
Branch: refs/heads/MARMOTTA-584
Commit: 4eb074dcb9936259ce111f991760ada8fd741d75
Parents: 767ef4a
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Sun Dec 20 11:33:32 2015 +0100
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Sun Dec 20 11:33:32 2015 +0100
----------------------------------------------------------------------
.../backend/persistence/leveldb_persistence.cc | 25 +++++++++-----------
.../backend/persistence/leveldb_service.cc | 5 ++--
libraries/ostrich/backend/util/CMakeLists.txt | 2 +-
libraries/ostrich/backend/util/iterator.h | 2 +-
libraries/ostrich/backend/util/unique.h | 23 ++++++++++++++++++
5 files changed, 38 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/4eb074dc/libraries/ostrich/backend/persistence/leveldb_persistence.cc
----------------------------------------------------------------------
diff --git a/libraries/ostrich/backend/persistence/leveldb_persistence.cc b/libraries/ostrich/backend/persistence/leveldb_persistence.cc
index 852f152..365397e 100644
--- a/libraries/ostrich/backend/persistence/leveldb_persistence.cc
+++ b/libraries/ostrich/backend/persistence/leveldb_persistence.cc
@@ -28,6 +28,7 @@
#include "leveldb_persistence.h"
#include "model/rdf_operators.h"
#include "util/murmur3.h"
+#include "util/unique.h"
#define CHECK_STATUS(s) CHECK(s.ok()) << "Writing to database failed: " << s.ToString()
@@ -387,16 +388,14 @@ std::unique_ptr<LevelDBPersistence::NamespaceIterator> LevelDBPersistence::GetNa
leveldb::Status s = db->Get(leveldb::ReadOptions(), key, &value);
if (s.ok()) {
ns.ParseFromString(value);
- return std::unique_ptr<NamespaceIterator>(
- new util::SingletonIterator<Namespace>(ns));
+ return util::make_unique<util::SingletonIterator<Namespace>>(std::move(ns));
} else {
- return std::unique_ptr<NamespaceIterator>(
- new util::EmptyIterator<Namespace>());
+ return util::make_unique<util::EmptyIterator<Namespace>>();
}
} else {
// Pattern was empty, iterate over all namespaces and report them.
- return std::unique_ptr<NamespaceIterator>(
- new LevelDBIterator<Namespace>(db_ns_prefix->NewIterator(leveldb::ReadOptions())));
+ return util::make_unique<LevelDBIterator<Namespace>>(
+ db_ns_prefix->NewIterator(leveldb::ReadOptions()));
}
}
@@ -481,16 +480,14 @@ std::unique_ptr<LevelDBPersistence::StatementIterator> LevelDBPersistence::GetSt
if (query.NeedsFilter()) {
DLOG(INFO) << "Retrieving statements with filter.";
- return std::unique_ptr<StatementIterator>(
- new util::FilteringIterator<Statement>(
- new StatementRangeIterator(
- db->NewIterator(leveldb::ReadOptions()), query.MinKey(), query.MaxKey()),
- [&pattern](const Statement& stmt) -> bool { return Matches(pattern, stmt); }));
+ return util::make_unique<util::FilteringIterator<Statement>>(
+ new StatementRangeIterator(
+ db->NewIterator(leveldb::ReadOptions()), query.MinKey(), query.MaxKey()),
+ [&pattern](const Statement& stmt) -> bool { return Matches(pattern, stmt); });
} else {
DLOG(INFO) << "Retrieving statements without filter.";
- return std::unique_ptr<StatementIterator>(
- new StatementRangeIterator(
- db->NewIterator(leveldb::ReadOptions()), query.MinKey(), query.MaxKey()));
+ return util::make_unique<StatementRangeIterator>(
+ db->NewIterator(leveldb::ReadOptions()), query.MinKey(), query.MaxKey());
}
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/4eb074dc/libraries/ostrich/backend/persistence/leveldb_service.cc
----------------------------------------------------------------------
diff --git a/libraries/ostrich/backend/persistence/leveldb_service.cc b/libraries/ostrich/backend/persistence/leveldb_service.cc
index 9ab9fd8..c11b002 100644
--- a/libraries/ostrich/backend/persistence/leveldb_service.cc
+++ b/libraries/ostrich/backend/persistence/leveldb_service.cc
@@ -21,6 +21,7 @@
#include <unordered_set>
#include <model/rdf_operators.h>
#include <util/iterator.h>
+#include <util/unique.h>
using grpc::Status;
using grpc::StatusCode;
@@ -230,9 +231,7 @@ grpc::Status LevelDBSparqlService::TupleQuery(
grpc::ServerContext* context, const spq::SparqlRequest* query,
grpc::ServerWriter<spq::SparqlResponse>* result) {
- SparqlService svc(
- std::unique_ptr<TripleSource>(
- new LevelDBTripleSource(persistence)));
+ SparqlService svc(util::make_unique<LevelDBTripleSource>(persistence));
svc.TupleQuery(query->query(), [&result](const SparqlService::RowType& row) {
spq::SparqlResponse response;
http://git-wip-us.apache.org/repos/asf/marmotta/blob/4eb074dc/libraries/ostrich/backend/util/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/libraries/ostrich/backend/util/CMakeLists.txt b/libraries/ostrich/backend/util/CMakeLists.txt
index f573c3c..ac87cd8 100644
--- a/libraries/ostrich/backend/util/CMakeLists.txt
+++ b/libraries/ostrich/backend/util/CMakeLists.txt
@@ -1,3 +1,3 @@
include_directories(.. ${CMAKE_CURRENT_BINARY_DIR}/..)
-add_library(marmotta_util murmur3.cc murmur3.h split.cc split.h iterator.h)
\ No newline at end of file
+add_library(marmotta_util murmur3.cc murmur3.h split.cc split.h iterator.h unique.h)
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/marmotta/blob/4eb074dc/libraries/ostrich/backend/util/iterator.h
----------------------------------------------------------------------
diff --git a/libraries/ostrich/backend/util/iterator.h b/libraries/ostrich/backend/util/iterator.h
index fd29cc4..0f08531 100644
--- a/libraries/ostrich/backend/util/iterator.h
+++ b/libraries/ostrich/backend/util/iterator.h
@@ -88,7 +88,7 @@ class EmptyIterator : public CloseableIterator<T> {
template<typename T>
class SingletonIterator : public CloseableIterator<T> {
public:
- SingletonIterator(T& value) : value(value), incremented(false) { }
+ SingletonIterator(T&& value) : value(value), incremented(false) { }
const T &next() override {
if (!incremented) {
http://git-wip-us.apache.org/repos/asf/marmotta/blob/4eb074dc/libraries/ostrich/backend/util/unique.h
----------------------------------------------------------------------
diff --git a/libraries/ostrich/backend/util/unique.h b/libraries/ostrich/backend/util/unique.h
new file mode 100644
index 0000000..d212af2
--- /dev/null
+++ b/libraries/ostrich/backend/util/unique.h
@@ -0,0 +1,23 @@
+//
+// Created by wastl on 20.12.15.
+//
+
+#include <memory>
+
+#ifndef MARMOTTA_UNIQUE_H
+#define MARMOTTA_UNIQUE_H
+namespace marmotta {
+namespace util {
+
+/**
+ * Backport of C++14 make_unique implementation.
+ */
+template<typename T, typename ...Args>
+std::unique_ptr<T> make_unique( Args&& ...args )
+{
+ return std::unique_ptr<T>( new T( std::forward<Args>(args)... ) );
+}
+
+} // namespace util
+} // namespace marmotta
+#endif //MARMOTTA_UNIQUE_H