aboutsummaryrefslogtreecommitdiffstats
path: root/document
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2022-03-29 16:07:07 +0200
committerGitHub <noreply@github.com>2022-03-29 16:07:07 +0200
commit89d248d004cbad6d83f51974238300e2dc2c0de1 (patch)
treeaff26c0e5b184f863093928394de7e11bd3924c9 /document
parentdc45403e426237d940544b4929f5e9f31c259d0e (diff)
parentc533430fd00b801968d58071d022de9f90a02515 (diff)
Merge pull request #21879 from vespa-engine/arnej/use-std-function
use std::function
Diffstat (limited to 'document')
-rw-r--r--document/src/tests/repo/documenttyperepo_test.cpp4
-rw-r--r--document/src/vespa/document/fieldset/fieldsetrepo.cpp4
-rw-r--r--document/src/vespa/document/repo/documenttyperepo.cpp4
-rw-r--r--document/src/vespa/document/repo/documenttyperepo.h27
-rw-r--r--document/src/vespa/document/select/bodyfielddetector.cpp4
5 files changed, 10 insertions, 33 deletions
diff --git a/document/src/tests/repo/documenttyperepo_test.cpp b/document/src/tests/repo/documenttyperepo_test.cpp
index 8180accae00..132485b7975 100644
--- a/document/src/tests/repo/documenttyperepo_test.cpp
+++ b/document/src/tests/repo/documenttyperepo_test.cpp
@@ -376,8 +376,8 @@ TEST("requireThatDocumentTypesCanBeIterated") {
DocumentTypeRepo repo(builder.config());
set<int> ids;
- repo.forEachDocumentType(*DocumentTypeRepo::makeLambda(
- [&ids](const DocumentType &type) { ids.insert(type.getId()); }));
+ repo.forEachDocumentType(
+ [&ids](const DocumentType &type) { ids.insert(type.getId()); });
EXPECT_EQUAL(3u, ids.size());
ASSERT_TRUE(ids.count(DataType::T_DOCUMENT));
diff --git a/document/src/vespa/document/fieldset/fieldsetrepo.cpp b/document/src/vespa/document/fieldset/fieldsetrepo.cpp
index 851eb8f4ecf..5e98705f94e 100644
--- a/document/src/vespa/document/fieldset/fieldsetrepo.cpp
+++ b/document/src/vespa/document/fieldset/fieldsetrepo.cpp
@@ -123,9 +123,9 @@ FieldSetRepo::FieldSetRepo(const DocumentTypeRepo& repo)
: _doumentTyperepo(repo),
_configuredFieldSets()
{
- repo.forEachDocumentType(*DocumentTypeRepo::makeLambda([&](const DocumentType &type) {
+ repo.forEachDocumentType([&](const DocumentType &type) {
configureDocumentType(type);
- }));
+ });
}
FieldSetRepo::~FieldSetRepo() = default;
diff --git a/document/src/vespa/document/repo/documenttyperepo.cpp b/document/src/vespa/document/repo/documenttyperepo.cpp
index 8bcdba9244a..312ce027543 100644
--- a/document/src/vespa/document/repo/documenttyperepo.cpp
+++ b/document/src/vespa/document/repo/documenttyperepo.cpp
@@ -580,9 +580,9 @@ DocumentTypeRepo::getAnnotationType(const DocumentType &doc_type, int32_t id) co
}
void
-DocumentTypeRepo::forEachDocumentType(Handler & handler) const {
+DocumentTypeRepo::forEachDocumentType(std::function<void(const DocumentType &)> handler) const {
for (const auto & entry : *_doc_types) {
- handler.handle(*entry.second->doc_type);
+ handler(*entry.second->doc_type);
}
}
diff --git a/document/src/vespa/document/repo/documenttyperepo.h b/document/src/vespa/document/repo/documenttyperepo.h
index 82f6c2be954..1a3898a1b65 100644
--- a/document/src/vespa/document/repo/documenttyperepo.h
+++ b/document/src/vespa/document/repo/documenttyperepo.h
@@ -2,6 +2,7 @@
#pragma once
+#include <functional>
#include <memory>
#include <vespa/vespalib/stllike/string.h>
#include <vespa/document/config/documenttypes_config_fwd.h>
@@ -19,20 +20,6 @@ class DocumentType;
class DocumentTypeRepo {
public:
- struct Handler {
- virtual ~Handler() = default;
- virtual void handle(const DocumentType & type) = 0;
- };
-
-
- template <class FunctionType>
- static std::unique_ptr<Handler>
- makeLambda(FunctionType &&function)
- {
- return std::make_unique<LambdaHandler<std::decay_t<FunctionType>>>
- (std::forward<FunctionType>(function));
- }
-
// This one should only be used for testing. If you do not have any config.
explicit DocumentTypeRepo(const DocumentType & docType);
@@ -47,19 +34,9 @@ public:
const DataType *getDataType(const DocumentType &doc_type, int32_t id) const;
const DataType *getDataType(const DocumentType &doc_type, vespalib::stringref name) const;
const AnnotationType *getAnnotationType(const DocumentType &doc_type, int32_t id) const;
- void forEachDocumentType(Handler & handler) const;
+ void forEachDocumentType(std::function<void(const DocumentType &)> handler) const;
const DocumentType *getDefaultDocType() const { return _default; }
private:
- template <class FunctionType>
- class LambdaHandler : public Handler {
- FunctionType _func;
- public:
- LambdaHandler(FunctionType &&func) : _func(std::move(func)) {}
- LambdaHandler(const LambdaHandler &) = delete;
- LambdaHandler & operator = (const LambdaHandler &) = delete;
- ~LambdaHandler() override = default;
- void handle(const DocumentType & type) override { _func(type); }
- };
std::unique_ptr<internal::DocumentTypeMap> _doc_types;
const DocumentType * _default;
diff --git a/document/src/vespa/document/select/bodyfielddetector.cpp b/document/src/vespa/document/select/bodyfielddetector.cpp
index 62daa1b3a84..569efa89394 100644
--- a/document/src/vespa/document/select/bodyfielddetector.cpp
+++ b/document/src/vespa/document/select/bodyfielddetector.cpp
@@ -28,9 +28,9 @@ BodyFieldDetector::detectFieldType(const FieldValueNode *expr, const DocumentTyp
void
BodyFieldDetector::visitFieldValueNode(const FieldValueNode& expr)
{
- _repo.forEachDocumentType(*DocumentTypeRepo::makeLambda([&](const DocumentType &type) {
+ _repo.forEachDocumentType([&](const DocumentType &type) {
detectFieldType(&expr, type);
- }));
+ });
}