diff options
Diffstat (limited to 'document')
5 files changed, 23 insertions, 45 deletions
diff --git a/document/src/vespa/document/fieldvalue/stringfieldvalue.h b/document/src/vespa/document/fieldvalue/stringfieldvalue.h index be32f007db4..14b67838787 100644 --- a/document/src/vespa/document/fieldvalue/stringfieldvalue.h +++ b/document/src/vespa/document/fieldvalue/stringfieldvalue.h @@ -7,15 +7,16 @@ */ #pragma once -#include <vespa/document/fieldvalue/literalfieldvalue.h> +#include "literalfieldvalue.h" #include <vespa/document/annotation/spantree.h> #include <vespa/vespalib/stllike/hash_map.h> -#include <vespa/document/repo/fixedtyperepo.h> #include <vespa/vespalib/util/buffer.h> #include <vespa/fastos/dynamiclibrary.h> namespace document { + class FixedTypeRepo; +class DocumentTypeRepo; class StringFieldValue : public LiteralFieldValue<StringFieldValue, DataType::T_STRING, true> { public: diff --git a/document/src/vespa/document/repo/documenttyperepo.cpp b/document/src/vespa/document/repo/documenttyperepo.cpp index 3a630ea2bea..a2f5aeb8f0b 100644 --- a/document/src/vespa/document/repo/documenttyperepo.cpp +++ b/document/src/vespa/document/repo/documenttyperepo.cpp @@ -349,7 +349,8 @@ void addDocumentTypes(const DocumentTypeMap &type_map, Repo &repo) { } } -void addDefaultDocument(DocumentTypeMap &type_map) { +const DocumentType * +addDefaultDocument(DocumentTypeMap &type_map) { DataTypeRepo::UP data_types(new DataTypeRepo); vector<const DataType *> default_types = DataType::getDefaultDataTypes(); for (size_t i = 0; i < default_types.size(); ++i) { @@ -365,7 +366,9 @@ void addDefaultDocument(DocumentTypeMap &type_map) { } uint32_t typeId = data_types->doc_type->getId(); + const DocumentType * docType = data_types->doc_type; type_map[typeId] = data_types.release(); + return docType; } const DataTypeRepo &lookupRepo(int32_t id, const DocumentTypeMap &type_map) { @@ -478,15 +481,15 @@ void configureAllRepos(const DocumenttypesConfig::DocumenttypeVector &t, Documen } // namespace DocumentTypeRepo::DocumentTypeRepo() : - _doc_types(std::make_unique<internal::DocumentTypeMap>()) + _doc_types(std::make_unique<internal::DocumentTypeMap>()), + _default(addDefaultDocument(*_doc_types)) { - addDefaultDocument(*_doc_types); } DocumentTypeRepo::DocumentTypeRepo(const DocumentType & type) : - _doc_types(std::make_unique<internal::DocumentTypeMap>()) + _doc_types(std::make_unique<internal::DocumentTypeMap>()), + _default(addDefaultDocument(*_doc_types)) { - addDefaultDocument(*_doc_types); try { addDataTypeRepo(makeDataTypeRepo(type, *_doc_types), *_doc_types); } catch (...) { @@ -496,9 +499,9 @@ DocumentTypeRepo::DocumentTypeRepo(const DocumentType & type) : } DocumentTypeRepo::DocumentTypeRepo(const DocumenttypesConfig &config) : - _doc_types(std::make_unique<internal::DocumentTypeMap>()) + _doc_types(std::make_unique<internal::DocumentTypeMap>()), + _default(addDefaultDocument(*_doc_types)) { - addDefaultDocument(*_doc_types); try { createAllDocumentTypes(config.documenttype, *_doc_types); addAllDocumentTypesToRepos(*_doc_types); diff --git a/document/src/vespa/document/repo/documenttyperepo.h b/document/src/vespa/document/repo/documenttyperepo.h index 71410197405..c1c25204b3f 100644 --- a/document/src/vespa/document/repo/documenttyperepo.h +++ b/document/src/vespa/document/repo/documenttyperepo.h @@ -20,6 +20,7 @@ class DocumentType; class DocumentTypeRepo { std::unique_ptr<internal::DocumentTypeMap> _doc_types; + const DocumentType * _default; public: using DocumenttypesConfig = const internal::InternalDocumenttypesType; @@ -39,7 +40,7 @@ public: const DataType *getDataType(const DocumentType &doc_type, const vespalib::stringref &name) const; const AnnotationType *getAnnotationType(const DocumentType &doc_type, int32_t id) const; void forEachDocumentType(vespalib::Closure1<const DocumentType &> &c) const; - + const DocumentType *getDefaultDocType() const { return _default; } }; } // namespace document diff --git a/document/src/vespa/document/repo/fixedtyperepo.cpp b/document/src/vespa/document/repo/fixedtyperepo.cpp index 7644dddb64d..81a26265830 100644 --- a/document/src/vespa/document/repo/fixedtyperepo.cpp +++ b/document/src/vespa/document/repo/fixedtyperepo.cpp @@ -1,38 +1,14 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "fixedtyperepo.h" -#include "documenttyperepo.h" #include <cassert> namespace document { -FixedTypeRepo::FixedTypeRepo(const DocumentTypeRepo &repo) - : _repo(&repo), _doc_type(repo.getDocumentType(DataType::T_DOCUMENT)) +FixedTypeRepo::FixedTypeRepo(const DocumentTypeRepo &repo, const vespalib::string &type) + : _repo(&repo), _doc_type(repo.getDocumentType(type)) { -} - -FixedTypeRepo::FixedTypeRepo(const DocumentTypeRepo &repo, - const vespalib::string &type) - : _repo(&repo), _doc_type(repo.getDocumentType(type)) { assert(_doc_type); } -const DataType * -FixedTypeRepo::getDataType(int32_t id) const -{ - return _repo->getDataType(*_doc_type, id); -} - -const DataType * -FixedTypeRepo::getDataType(const vespalib::string &name) const -{ - return _repo->getDataType(*_doc_type, name); -} - -const AnnotationType * -FixedTypeRepo::getAnnotationType(int32_t id) const -{ - return _repo->getAnnotationType(*_doc_type, id); -} - } // namespace document diff --git a/document/src/vespa/document/repo/fixedtyperepo.h b/document/src/vespa/document/repo/fixedtyperepo.h index eb8a5a328dd..67e7571e31d 100644 --- a/document/src/vespa/document/repo/fixedtyperepo.h +++ b/document/src/vespa/document/repo/fixedtyperepo.h @@ -2,13 +2,10 @@ #pragma once -#include <vespa/document/datatype/datatype.h> +#include "documenttyperepo.h" namespace document { -class DocumentTypeRepo; -class AnnotationType; - // Combines a DocumentTypeRepo and a DocumentType to allow easy access // to the types contained in the DocumentType's namespace. class FixedTypeRepo { @@ -16,15 +13,15 @@ class FixedTypeRepo { const DocumentType *_doc_type; public: - explicit FixedTypeRepo(const DocumentTypeRepo &repo); + explicit FixedTypeRepo(const DocumentTypeRepo &repo) + : _repo(&repo), _doc_type(repo.getDefaultDocType()) {} FixedTypeRepo(const DocumentTypeRepo &repo, const DocumentType &doc_type) : _repo(&repo), _doc_type(&doc_type) {} FixedTypeRepo(const DocumentTypeRepo &repo, const vespalib::string &type); - const DataType *getDataType(int32_t id) const; - const DataType *getDataType(const vespalib::string &name) const; - const AnnotationType *getAnnotationType(int32_t id) const; - + const DataType *getDataType(int32_t id) const { return _repo->getDataType(*_doc_type, id); } + const DataType *getDataType(const vespalib::string &name) const { return _repo->getDataType(*_doc_type, name); } + const AnnotationType *getAnnotationType(int32_t id) const { return _repo->getAnnotationType(*_doc_type, id); } const DocumentTypeRepo &getDocumentTypeRepo() const { return *_repo; } const DocumentType &getDocumentType() const { return *_doc_type; } }; |