diff options
author | Arne H Juul <arnej@yahooinc.com> | 2022-03-29 12:53:37 +0000 |
---|---|---|
committer | Arne H Juul <arnej@yahooinc.com> | 2022-03-29 12:53:37 +0000 |
commit | c533430fd00b801968d58071d022de9f90a02515 (patch) | |
tree | a9e88e57475c30346f34a9aff0c91af12e3fba00 /document/src | |
parent | 9bced6805fe2d89f9ba316399474a831c85985ff (diff) |
use std::function
* no need to implement our own (restricted) version of it
Diffstat (limited to 'document/src')
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); - })); + }); } |