diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2022-03-03 22:17:44 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2022-03-03 23:55:36 +0000 |
commit | 7c7ab8fbb3645a613c13c95ccacbd0600f463465 (patch) | |
tree | 4be65678358a09dd1c8b87656330db0c35bfd1ca /document/src | |
parent | 688816d53e31cb463e20a9507952983dfc9baff6 (diff) |
Reduce use of Identifiable for document::DatatType
Diffstat (limited to 'document/src')
43 files changed, 162 insertions, 129 deletions
diff --git a/document/src/tests/documentselectparsertest.cpp b/document/src/tests/documentselectparsertest.cpp index c89cefeae29..f40aec41e16 100644 --- a/document/src/tests/documentselectparsertest.cpp +++ b/document/src/tests/documentselectparsertest.cpp @@ -4,6 +4,14 @@ #include <vespa/document/repo/documenttyperepo.h> #include <vespa/document/update/assignvalueupdate.h> #include <vespa/document/update/documentupdate.h> +#include <vespa/document/datatype/documenttype.h> +#include <vespa/document/fieldvalue/bytefieldvalue.h> +#include <vespa/document/fieldvalue/intfieldvalue.h> +#include <vespa/document/fieldvalue/longfieldvalue.h> +#include <vespa/document/fieldvalue/stringfieldvalue.h> +#include <vespa/document/fieldvalue/floatfieldvalue.h> +#include <vespa/document/fieldvalue/arrayfieldvalue.h> +#include <vespa/document/fieldvalue/weightedsetfieldvalue.h> #include <vespa/document/base/testdocman.h> #include <vespa/document/select/parser.h> #include <vespa/document/select/visitor.h> diff --git a/document/src/tests/documenttestcase.cpp b/document/src/tests/documenttestcase.cpp index aae4b5c6f40..82c1d62be59 100644 --- a/document/src/tests/documenttestcase.cpp +++ b/document/src/tests/documenttestcase.cpp @@ -1,8 +1,22 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/document/base/testdocman.h> -#include <vespa/document/datatype/annotationreferencedatatype.h> +#include <vespa/document/datatype/documenttype.h> +#include <vespa/document/datatype/mapdatatype.h> +#include <vespa/document/datatype/weightedsetdatatype.h> +#include <vespa/document/datatype/numericdatatype.h> #include <vespa/document/fieldvalue/iteratorhandler.h> +#include <vespa/document/fieldvalue/document.h> +#include <vespa/document/fieldvalue/bytefieldvalue.h> +#include <vespa/document/fieldvalue/intfieldvalue.h> +#include <vespa/document/fieldvalue/longfieldvalue.h> +#include <vespa/document/fieldvalue/floatfieldvalue.h> +#include <vespa/document/fieldvalue/doublefieldvalue.h> +#include <vespa/document/fieldvalue/stringfieldvalue.h> +#include <vespa/document/fieldvalue/rawfieldvalue.h> +#include <vespa/document/fieldvalue/arrayfieldvalue.h> +#include <vespa/document/fieldvalue/mapfieldvalue.h> +#include <vespa/document/fieldvalue/weightedsetfieldvalue.h> #include <vespa/document/repo/configbuilder.h> #include <vespa/document/repo/documenttyperepo.h> #include <vespa/document/serialization/vespadocumentdeserializer.h> @@ -36,6 +50,8 @@ TEST(DocumentTest, testSizeOf) EXPECT_EQ(88ul, sizeof(IdString)); EXPECT_EQ(104ul, sizeof(DocumentId)); EXPECT_EQ(240ul, sizeof(Document)); + EXPECT_EQ(88ul, sizeof(NumericDataType)); + EXPECT_EQ(24ul, sizeof(LongFieldValue)); EXPECT_EQ(96ul, sizeof(StructFieldValue)); EXPECT_EQ(16ul, sizeof(StructuredFieldValue)); EXPECT_EQ(56ul, sizeof(SerializableArray)); diff --git a/document/src/tests/documentupdatetestcase.cpp b/document/src/tests/documentupdatetestcase.cpp index f505c2dd32d..8a9aef0bde4 100644 --- a/document/src/tests/documentupdatetestcase.cpp +++ b/document/src/tests/documentupdatetestcase.cpp @@ -3,7 +3,9 @@ #include <vespa/document/base/testdocman.h> #include <vespa/document/base/exceptions.h> #include <vespa/document/datatype/tensor_data_type.h> +#include <vespa/document/datatype/documenttype.h> #include <vespa/document/fieldvalue/fieldvalues.h> +#include <vespa/document/fieldvalue/tensorfieldvalue.h> #include <vespa/document/repo/configbuilder.h> #include <vespa/document/repo/documenttyperepo.h> #include <vespa/document/serialization/vespadocumentserializer.h> @@ -28,8 +30,6 @@ #include <vespa/vespalib/objects/nbostream.h> #include <vespa/vespalib/util/exception.h> #include <vespa/vespalib/util/exceptions.h> - -#include <fcntl.h> #include <fstream> #include <gtest/gtest.h> #include <unistd.h> diff --git a/document/src/tests/fieldpathupdatetestcase.cpp b/document/src/tests/fieldpathupdatetestcase.cpp index e4516ab6d70..cd4e03bbfe7 100644 --- a/document/src/tests/fieldpathupdatetestcase.cpp +++ b/document/src/tests/fieldpathupdatetestcase.cpp @@ -1,12 +1,20 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/document/base/testdocman.h> #include <vespa/document/fieldvalue/iteratorhandler.h> -#include <vespa/document/select/node.h> +#include <vespa/document/fieldvalue/intfieldvalue.h> +#include <vespa/document/fieldvalue/bytefieldvalue.h> +#include <vespa/document/fieldvalue/floatfieldvalue.h> +#include <vespa/document/fieldvalue/document.h> +#include <vespa/document/fieldvalue/arrayfieldvalue.h> +#include <vespa/document/fieldvalue/stringfieldvalue.h> +#include <vespa/document/fieldvalue/weightedsetfieldvalue.h> + #include <vespa/document/base/exceptions.h> -#include <vespa/vespalib/io/fileutil.h> #include <vespa/document/update/fieldpathupdates.h> #include <vespa/document/update/documentupdate.h> +#include <vespa/document/datatype/documenttype.h> +#include <vespa/document/datatype/mapdatatype.h> #include <vespa/document/repo/configbuilder.h> #include <vespa/document/repo/documenttyperepo.h> diff --git a/document/src/tests/fieldsettest.cpp b/document/src/tests/fieldsettest.cpp index 9f00fdd8c0d..4ce8e53ae3c 100644 --- a/document/src/tests/fieldsettest.cpp +++ b/document/src/tests/fieldsettest.cpp @@ -3,6 +3,9 @@ #include <vespa/document/base/testdocman.h> #include <vespa/document/fieldset/fieldsetrepo.h> #include <vespa/document/repo/documenttyperepo.h> +#include <vespa/document/fieldvalue/document.h> +#include <vespa/document/fieldvalue/intfieldvalue.h> +#include <vespa/document/fieldvalue/stringfieldvalue.h> #include <vespa/vespalib/objects/nbostream.h> #include <algorithm> #include <gtest/gtest.h> diff --git a/document/src/tests/struct_anno/struct_anno_test.cpp b/document/src/tests/struct_anno/struct_anno_test.cpp index 18e5fbc5565..57b643a1d27 100644 --- a/document/src/tests/struct_anno/struct_anno_test.cpp +++ b/document/src/tests/struct_anno/struct_anno_test.cpp @@ -4,7 +4,8 @@ #include <vespa/document/annotation/alternatespanlist.h> #include <vespa/document/annotation/annotation.h> #include <vespa/document/annotation/spantree.h> -#include <vespa/document/document.h> +#include <vespa/document/fieldvalue/document.h> +#include <vespa/document/fieldvalue/stringfieldvalue.h> #include <vespa/document/serialization/annotationdeserializer.h> #include <vespa/document/serialization/annotationserializer.h> #include <vespa/document/serialization/vespadocumentdeserializer.h> diff --git a/document/src/tests/testdocmantest.cpp b/document/src/tests/testdocmantest.cpp index 5aa2b65fb99..6d0a2686a74 100644 --- a/document/src/tests/testdocmantest.cpp +++ b/document/src/tests/testdocmantest.cpp @@ -2,10 +2,10 @@ /* $Id$*/ -#include <iostream> -#include <set> -#include <sstream> #include <vespa/document/base/testdocman.h> +#include <vespa/document/fieldvalue/document.h> +#include <vespa/document/fieldvalue/stringfieldvalue.h> + #include <gtest/gtest.h> namespace document { diff --git a/document/src/vespa/document/base/fieldpath.cpp b/document/src/vespa/document/base/fieldpath.cpp index 2bd8866d9fd..5da64272364 100644 --- a/document/src/vespa/document/base/fieldpath.cpp +++ b/document/src/vespa/document/base/fieldpath.cpp @@ -3,8 +3,6 @@ #include "fieldpath.h" #include <vespa/document/datatype/arraydatatype.h> #include <vespa/document/datatype/mapdatatype.h> -#include <vespa/document/datatype/weightedsetdatatype.h> -#include <vespa/document/datatype/primitivedatatype.h> #include <vespa/vespalib/util/exceptions.h> #include <vespa/document/fieldvalue/fieldvalue.h> #include <vespa/vespalib/objects/visit.hpp> @@ -72,15 +70,19 @@ FieldPathEntry::setFillValue(const DataType & dataType) const DataType * dt = & dataType; while (true) { - if (dt->inherits(CollectionDataType::classId)) { - dt = &static_cast<const CollectionDataType *>(dt)->getNestedType(); - } else if (dt->inherits(MapDataType::classId)) { - dt = &static_cast<const MapDataType *>(dt)->getValueType(); + const CollectionDataType *ct = dt->cast_collection(); + if (ct != nullptr) { + dt = &ct->getNestedType(); } else { - break; + const MapDataType * mt = dt->cast_map(); + if (mt != nullptr) { + dt = &mt->getValueType(); + } else { + break; + } } } - if (dt->inherits(PrimitiveDataType::classId)) { + if (dt->isPrimitive()) { _fillInVal.reset(dt->createFieldValue().release()); } } @@ -130,7 +132,6 @@ FieldPathEntry::visitMembers(vespalib::ObjectVisitor &visitor) const { visit(visitor, "type", _type); visit(visitor, "name", _name); - visit(visitor, "dataType", _dataType); visit(visitor, "lookupIndex", _lookupIndex); visit(visitor, "lookupKey", _lookupKey); visit(visitor, "variableName", _variableName); diff --git a/document/src/vespa/document/base/testdocman.cpp b/document/src/vespa/document/base/testdocman.cpp index 74df8e86f9c..2994de9c9c1 100644 --- a/document/src/vespa/document/base/testdocman.cpp +++ b/document/src/vespa/document/base/testdocman.cpp @@ -1,9 +1,10 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "testdocman.h" -#include "exceptions.h" #include <vespa/document/datatype/datatypes.h> #include <vespa/document/repo/documenttyperepo.h> +#include <vespa/document/fieldvalue/document.h> +#include <vespa/document/fieldvalue/stringfieldvalue.h> #include <boost/random.hpp> #include <sstream> diff --git a/document/src/vespa/document/base/testdocman.h b/document/src/vespa/document/base/testdocman.h index 3926f8b2b11..aca69e6bceb 100644 --- a/document/src/vespa/document/base/testdocman.h +++ b/document/src/vespa/document/base/testdocman.h @@ -19,49 +19,50 @@ #pragma once #include "testdocrepo.h" -#include <vespa/document/datatype/datatypes.h> -#include <vespa/document/fieldvalue/fieldvalues.h> -#include <memory> -#include <vector> +#include <vespa/document/fieldvalue/document.h> +#include <vespa/document/datatype/documenttype.h> namespace document { - class TestDocMan { - static std::vector<char> _buffer; - TestDocRepo _test_repo; - std::shared_ptr<const DocumentTypeRepo> _repo; - const DocumenttypesConfig *_typeCfg; - public: - TestDocMan(); - ~TestDocMan(); +class Document; - void setTypeRepo(const std::shared_ptr<const DocumentTypeRepo> &repo); +class TestDocMan { + static std::vector<char> _buffer; + TestDocRepo _test_repo; + std::shared_ptr<const DocumentTypeRepo> _repo; + const DocumenttypesConfig *_typeCfg; - const DocumentTypeRepo& getTypeRepo() const { return *_repo; } - std::shared_ptr<const DocumentTypeRepo> getTypeRepoSP() const { return _repo; } - const DocumenttypesConfig *getTypeConfig() const { return _typeCfg; } +public: + TestDocMan(); + ~TestDocMan(); - /** Create test document. */ - Document::UP createDocument( - const std::string& content = "This is the contents of " - "the test document.\nIt ain't much.\n", - const std::string& uri = "id:test:testdoctype1::test", - const std::string& type = "testdoctype1") const; + void setTypeRepo(const std::shared_ptr<const DocumentTypeRepo> &repo); - /** Create random document from given seed. */ - Document::UP createRandomDocument( - int seed = 0, int maxContentSize = 0x80) const; - /** Create random document from given seed belonging to given location */ - Document::UP createRandomDocumentAtLocation( - int location, int seed = 0, int maxContentSize = 0x80) const; - Document::UP createRandomDocumentAtLocation( - int location, int seed, int minContentSize, int maxContentSize) const; - /** Create random document of given type from given seed. */ - Document::UP createRandomDocument( - const std::string& type, int seed = 0, - int maxContentSize = 0x80) const; - static std::string generateRandomContent(uint32_t size); - }; + const DocumentTypeRepo& getTypeRepo() const { return *_repo; } + std::shared_ptr<const DocumentTypeRepo> getTypeRepoSP() const { return _repo; } + const DocumenttypesConfig *getTypeConfig() const { return _typeCfg; } + + /** Create test document. */ + std::unique_ptr<Document> createDocument( + const std::string& content = "This is the contents of " + "the test document.\nIt ain't much.\n", + const std::string& uri = "id:test:testdoctype1::test", + const std::string& type = "testdoctype1") const; + + /** Create random document from given seed. */ + std::unique_ptr<Document> createRandomDocument( + int seed = 0, int maxContentSize = 0x80) const; + /** Create random document from given seed belonging to given location */ + std::unique_ptr<Document> createRandomDocumentAtLocation( + int location, int seed = 0, int maxContentSize = 0x80) const; + std::unique_ptr<Document> createRandomDocumentAtLocation( + int location, int seed, int minContentSize, int maxContentSize) const; + /** Create random document of given type from given seed. */ + std::unique_ptr<Document> createRandomDocument( + const std::string& type, int seed = 0, + int maxContentSize = 0x80) const; + static std::string generateRandomContent(uint32_t size); +}; } // document diff --git a/document/src/vespa/document/datatype/arraydatatype.cpp b/document/src/vespa/document/datatype/arraydatatype.cpp index af87e488d19..7aed584ad09 100644 --- a/document/src/vespa/document/datatype/arraydatatype.cpp +++ b/document/src/vespa/document/datatype/arraydatatype.cpp @@ -22,7 +22,7 @@ ArrayDataType::ArrayDataType(const DataType& nestedType) FieldValue::UP ArrayDataType::createFieldValue() const { - return FieldValue::UP(new ArrayFieldValue(*this)); + return std::make_unique<ArrayFieldValue>(*this); } void @@ -39,7 +39,7 @@ ArrayDataType::operator==(const DataType& other) const { if (this == &other) return true; if (!CollectionDataType::operator==(other)) return false; - return other.inherits(ArrayDataType::classId); + return other.isArray(); } void diff --git a/document/src/vespa/document/datatype/arraydatatype.h b/document/src/vespa/document/datatype/arraydatatype.h index b69bdceea02..3c0104eb393 100644 --- a/document/src/vespa/document/datatype/arraydatatype.h +++ b/document/src/vespa/document/datatype/arraydatatype.h @@ -30,6 +30,8 @@ public: ArrayDataType &operator=(const ArrayDataType &rhs) = default; void onBuildFieldPath(FieldPath & path, vespalib::stringref remainFieldName) const override; + bool isArray() const override { return true; } + DECLARE_IDENTIFIABLE(ArrayDataType); }; diff --git a/document/src/vespa/document/datatype/collectiondatatype.cpp b/document/src/vespa/document/datatype/collectiondatatype.cpp index d86be5d35c1..886d44dbb9c 100644 --- a/document/src/vespa/document/datatype/collectiondatatype.cpp +++ b/document/src/vespa/document/datatype/collectiondatatype.cpp @@ -2,7 +2,6 @@ #include "collectiondatatype.h" #include <vespa/document/util/stringutil.h> -#include <vespa/vespalib/util/exceptions.h> namespace document { @@ -37,17 +36,14 @@ CollectionDataType::CollectionDataType(vespalib::stringref name, _nestedType(&nestedType) { } -CollectionDataType::~CollectionDataType() -{ -} +CollectionDataType::~CollectionDataType() = default; bool CollectionDataType::operator==(const DataType& other) const { if (!DataType::operator==(other)) return false; - const CollectionDataType* o( - Identifiable::cast<const CollectionDataType*>(&other)); - return o != 0 && *_nestedType == *o->_nestedType; + const CollectionDataType * o = other.cast_collection(); + return o && *_nestedType == *o->_nestedType; } } // document diff --git a/document/src/vespa/document/datatype/collectiondatatype.h b/document/src/vespa/document/datatype/collectiondatatype.h index f294f8da375..2d1277cc747 100644 --- a/document/src/vespa/document/datatype/collectiondatatype.h +++ b/document/src/vespa/document/datatype/collectiondatatype.h @@ -26,10 +26,11 @@ protected: const DataType &nestedType, int32_t id); public: - ~CollectionDataType(); + ~CollectionDataType() override; bool operator==(const DataType&) const override; const DataType &getNestedType() const { return *_nestedType; } + const CollectionDataType * cast_collection() const override { return this; } DECLARE_IDENTIFIABLE_ABSTRACT(CollectionDataType); }; diff --git a/document/src/vespa/document/datatype/datatype.h b/document/src/vespa/document/datatype/datatype.h index f3538956dfd..c32aec6b9b1 100644 --- a/document/src/vespa/document/datatype/datatype.h +++ b/document/src/vespa/document/datatype/datatype.h @@ -16,11 +16,16 @@ namespace document { class FieldValue; class Field; +class FieldPath; + class NumericDataType; class PrimitiveDataType; class DocumentType; class WeightedSetDataType; -class FieldPath; +class CollectionDataType; +class ArrayDataType; +class MapDataType; +class ReferenceDataType; class DataType : public Printable, public vespalib::Identifiable @@ -98,7 +103,6 @@ public: /** Used by type manager to fetch default types to register. */ static std::vector<const DataType *> getDefaultDataTypes(); - const vespalib::string& getName() const { return _name; } int getId() const { return _dataTypeId; } bool isValueType(const FieldValue & fv) const; @@ -109,6 +113,13 @@ public: virtual std::unique_ptr<FieldValue> createFieldValue() const = 0; virtual DataType* clone() const = 0; + virtual bool isArray() const { return false; } + virtual bool isPrimitive() const { return false; } + virtual bool isNumeric() const { return false; } + virtual const CollectionDataType * cast_collection() const { return nullptr; } + virtual const MapDataType * cast_map() const { return nullptr; } + virtual const ReferenceDataType * cast_reference() const { return nullptr; } + /** * Whether another datatype is a supertype of this one. Document types may * be due to inheritance. For other types, they must be identical for this diff --git a/document/src/vespa/document/datatype/datatypes.h b/document/src/vespa/document/datatype/datatypes.h index 3960b215944..42f445089c8 100644 --- a/document/src/vespa/document/datatype/datatypes.h +++ b/document/src/vespa/document/datatype/datatypes.h @@ -9,4 +9,3 @@ #include <vespa/document/datatype/weightedsetdatatype.h> #include <vespa/document/datatype/structdatatype.h> #include <vespa/document/datatype/documenttype.h> - diff --git a/document/src/vespa/document/datatype/mapdatatype.cpp b/document/src/vespa/document/datatype/mapdatatype.cpp index 891f1b60f49..74cb732fb5c 100644 --- a/document/src/vespa/document/datatype/mapdatatype.cpp +++ b/document/src/vespa/document/datatype/mapdatatype.cpp @@ -1,7 +1,6 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "mapdatatype.h" -#include "primitivedatatype.h" #include <vespa/document/fieldvalue/mapfieldvalue.h> #include <vespa/vespalib/stllike/asciistream.h> #include <ostream> @@ -51,8 +50,8 @@ MapDataType::operator==(const DataType& other) const { if (this == &other) return true; if (!DataType::operator==(other)) return false; - const MapDataType* w(Identifiable::cast<const MapDataType*>(&other)); - return (*_keyType == *w->_keyType) && (*_valueType == *w->_valueType); + const MapDataType * w = other.cast_map(); + return w && (*_keyType == *w->_keyType) && (*_valueType == *w->_valueType); } void diff --git a/document/src/vespa/document/datatype/mapdatatype.h b/document/src/vespa/document/datatype/mapdatatype.h index 457461b32fe..70800d36722 100644 --- a/document/src/vespa/document/datatype/mapdatatype.h +++ b/document/src/vespa/document/datatype/mapdatatype.h @@ -27,6 +27,7 @@ public: void print(std::ostream&, bool verbose, const std::string& indent) const override; bool operator==(const DataType& other) const override; MapDataType* clone() const override { return new MapDataType(*this); } + const MapDataType * cast_map() const override { return this; } void onBuildFieldPath(FieldPath & path, vespalib::stringref remainFieldName) const override; static void buildFieldPathImpl(FieldPath & path, const DataType& dataType, diff --git a/document/src/vespa/document/datatype/numericdatatype.h b/document/src/vespa/document/datatype/numericdatatype.h index 096582568e9..e5f87af584a 100644 --- a/document/src/vespa/document/datatype/numericdatatype.h +++ b/document/src/vespa/document/datatype/numericdatatype.h @@ -15,12 +15,13 @@ namespace document { -class NumericDataType : public PrimitiveDataType { +class NumericDataType final : public PrimitiveDataType { public: NumericDataType(Type type); NumericDataType* clone() const override { return new NumericDataType(*this); } void print(std::ostream&, bool verbose, const std::string& indent) const override; + bool isNumeric() const override { return true; } DECLARE_IDENTIFIABLE_ABSTRACT(NumericDataType); }; diff --git a/document/src/vespa/document/datatype/primitivedatatype.h b/document/src/vespa/document/datatype/primitivedatatype.h index f076e595d00..2f990c1a273 100644 --- a/document/src/vespa/document/datatype/primitivedatatype.h +++ b/document/src/vespa/document/datatype/primitivedatatype.h @@ -28,6 +28,8 @@ public: PrimitiveDataType* clone() const override { return new PrimitiveDataType(*this); } void print(std::ostream&, bool verbose, const std::string& indent) const override; + bool isPrimitive() const override { return true; } + DECLARE_IDENTIFIABLE_ABSTRACT(PrimitiveDataType); }; diff --git a/document/src/vespa/document/datatype/referencedatatype.cpp b/document/src/vespa/document/datatype/referencedatatype.cpp index b36c9fc165a..0f873aa3973 100644 --- a/document/src/vespa/document/datatype/referencedatatype.cpp +++ b/document/src/vespa/document/datatype/referencedatatype.cpp @@ -41,9 +41,9 @@ void ReferenceDataType::onBuildFieldPath(FieldPath &, vespalib::stringref remain } bool ReferenceDataType::operator==(const DataType &rhs) const { - return DataType::operator==(rhs) - && rhs.inherits(classId) - && (_targetDocType == static_cast<const ReferenceDataType &>(rhs)._targetDocType); + const ReferenceDataType *rt = rhs.cast_reference(); + return rt && DataType::operator==(rhs) + && (_targetDocType == rt->_targetDocType); } } // document diff --git a/document/src/vespa/document/datatype/referencedatatype.h b/document/src/vespa/document/datatype/referencedatatype.h index 7a79efaf142..960c6feb435 100644 --- a/document/src/vespa/document/datatype/referencedatatype.h +++ b/document/src/vespa/document/datatype/referencedatatype.h @@ -25,6 +25,7 @@ public: ReferenceDataType* clone() const override; void onBuildFieldPath(FieldPath & path, vespalib::stringref remainingFieldName) const override; + const ReferenceDataType * cast_reference() const override { return this; } bool operator==(const DataType &type) const override; bool operator==(const ReferenceDataType& type) const { return operator==(static_cast<const DataType&>(type)); } }; diff --git a/document/src/vespa/document/document.h b/document/src/vespa/document/document.h deleted file mode 100644 index 9c9bd0473ff..00000000000 --- a/document/src/vespa/document/document.h +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -/** - * - * \file document.h - * - * Include common client parts of document, such that clients can easily - * just include this file to get what they need. - * - * This should pull in all code needed for handling: - * - Datatypes - * - Fieldvalues - * - Updates - * - Selection language - */ - -#pragma once - -#include <vespa/document/datatype/datatypes.h> -#include <vespa/document/fieldvalue/fieldvalues.h> -#include <vespa/document/update/updates.h> -#include <vespa/document/select/parser.h> - diff --git a/document/src/vespa/document/fieldvalue/bytefieldvalue.h b/document/src/vespa/document/fieldvalue/bytefieldvalue.h index b3296adbf1f..7f6bc429b69 100644 --- a/document/src/vespa/document/fieldvalue/bytefieldvalue.h +++ b/document/src/vespa/document/fieldvalue/bytefieldvalue.h @@ -8,7 +8,7 @@ #pragma once #include "numericfieldvalue.h" -#include <vespa/document/datatype/numericdatatype.h> +#include <vespa/document/datatype/datatype.h> namespace document { diff --git a/document/src/vespa/document/fieldvalue/doublefieldvalue.h b/document/src/vespa/document/fieldvalue/doublefieldvalue.h index a8dcca7b40d..feb15e52223 100644 --- a/document/src/vespa/document/fieldvalue/doublefieldvalue.h +++ b/document/src/vespa/document/fieldvalue/doublefieldvalue.h @@ -7,8 +7,8 @@ */ #pragma once -#include <vespa/document/datatype/numericdatatype.h> -#include <vespa/document/fieldvalue/numericfieldvalue.h> +#include "numericfieldvalue.h" +#include <vespa/document/datatype/datatype.h> namespace document { diff --git a/document/src/vespa/document/fieldvalue/floatfieldvalue.h b/document/src/vespa/document/fieldvalue/floatfieldvalue.h index ea3d5971673..f33939d8d67 100644 --- a/document/src/vespa/document/fieldvalue/floatfieldvalue.h +++ b/document/src/vespa/document/fieldvalue/floatfieldvalue.h @@ -7,8 +7,8 @@ */ #pragma once -#include <vespa/document/datatype/numericdatatype.h> -#include <vespa/document/fieldvalue/numericfieldvalue.h> +#include "numericfieldvalue.h" +#include <vespa/document/datatype/datatype.h> namespace document { diff --git a/document/src/vespa/document/fieldvalue/intfieldvalue.h b/document/src/vespa/document/fieldvalue/intfieldvalue.h index e36c271f336..dbe419379a1 100644 --- a/document/src/vespa/document/fieldvalue/intfieldvalue.h +++ b/document/src/vespa/document/fieldvalue/intfieldvalue.h @@ -7,8 +7,8 @@ */ #pragma once -#include <vespa/document/datatype/numericdatatype.h> -#include <vespa/document/fieldvalue/numericfieldvalue.h> +#include "numericfieldvalue.h" +#include <vespa/document/datatype/datatype.h> namespace document { diff --git a/document/src/vespa/document/fieldvalue/longfieldvalue.h b/document/src/vespa/document/fieldvalue/longfieldvalue.h index a4afb1c703c..12a0615e0ad 100644 --- a/document/src/vespa/document/fieldvalue/longfieldvalue.h +++ b/document/src/vespa/document/fieldvalue/longfieldvalue.h @@ -7,8 +7,8 @@ */ #pragma once -#include <vespa/document/datatype/numericdatatype.h> -#include <vespa/document/fieldvalue/numericfieldvalue.h> +#include "numericfieldvalue.h" +#include <vespa/document/datatype/datatype.h> namespace document { diff --git a/document/src/vespa/document/fieldvalue/mapfieldvalue.cpp b/document/src/vespa/document/fieldvalue/mapfieldvalue.cpp index 8db3a15968b..872185e7523 100644 --- a/document/src/vespa/document/fieldvalue/mapfieldvalue.cpp +++ b/document/src/vespa/document/fieldvalue/mapfieldvalue.cpp @@ -29,7 +29,7 @@ IMPLEMENT_IDENTIFIABLE_ABSTRACT(MapFieldValue, FieldValue); namespace { const MapDataType *verifyMapType(const DataType& type) { - const MapDataType *ptr(Identifiable::cast<const MapDataType *>(&type)); + const MapDataType *ptr(dynamic_cast<const MapDataType *>(&type)); if (!ptr) { throw vespalib::IllegalArgumentException("Datatype given is not a map type", VESPA_STRLOC); } diff --git a/document/src/vespa/document/fieldvalue/shortfieldvalue.h b/document/src/vespa/document/fieldvalue/shortfieldvalue.h index f6d485451ad..f2047d1a521 100644 --- a/document/src/vespa/document/fieldvalue/shortfieldvalue.h +++ b/document/src/vespa/document/fieldvalue/shortfieldvalue.h @@ -8,7 +8,7 @@ #pragma once #include "numericfieldvalue.h" -#include <vespa/document/datatype/numericdatatype.h> +#include <vespa/document/datatype/datatype.h> namespace document { diff --git a/document/src/vespa/document/fieldvalue/weightedsetfieldvalue.cpp b/document/src/vespa/document/fieldvalue/weightedsetfieldvalue.cpp index 7893cedb2fe..6b80ceb1f6e 100644 --- a/document/src/vespa/document/fieldvalue/weightedsetfieldvalue.cpp +++ b/document/src/vespa/document/fieldvalue/weightedsetfieldvalue.cpp @@ -22,7 +22,7 @@ IMPLEMENT_IDENTIFIABLE_ABSTRACT(WeightedSetFieldValue, CollectionFieldValue); namespace { const DataType &getKeyType(const DataType &type) { - const WeightedSetDataType *wtype = Identifiable::cast<const WeightedSetDataType *>(&type); + const WeightedSetDataType *wtype = dynamic_cast<const WeightedSetDataType *>(&type); if (!wtype) { throw IllegalArgumentException("Cannot generate a weighted set value with non-weighted set " "type " + type.toString() + ".", VESPA_STRLOC); @@ -33,14 +33,14 @@ const DataType &getKeyType(const DataType &type) { WeightedSetFieldValue::WeightedSetFieldValue(const DataType &type) : CollectionFieldValue(type), - _map_type(new MapDataType(getKeyType(type), *DataType::INT)), + _map_type(std::make_shared<MapDataType>(getKeyType(type), *DataType::INT)), _map(*_map_type), _altered(true) { } WeightedSetFieldValue::WeightedSetFieldValue(const WeightedSetFieldValue &) = default; WeightedSetFieldValue & WeightedSetFieldValue::operator = (const WeightedSetFieldValue &) = default; -WeightedSetFieldValue::~WeightedSetFieldValue() { } +WeightedSetFieldValue::~WeightedSetFieldValue() = default; void WeightedSetFieldValue::verifyKey(const FieldValue & v) { diff --git a/document/src/vespa/document/repo/configbuilder.cpp b/document/src/vespa/document/repo/configbuilder.cpp index 6169ccd5a23..2ff852839f9 100644 --- a/document/src/vespa/document/repo/configbuilder.cpp +++ b/document/src/vespa/document/repo/configbuilder.cpp @@ -1,6 +1,8 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "configbuilder.h" +#include <vespa/document/datatype/structdatatype.h> + namespace document::config_builder { diff --git a/document/src/vespa/document/repo/configbuilder.h b/document/src/vespa/document/repo/configbuilder.h index 4df7a58ebb6..a68a8dda2dc 100644 --- a/document/src/vespa/document/repo/configbuilder.h +++ b/document/src/vespa/document/repo/configbuilder.h @@ -5,8 +5,6 @@ #include <vespa/document/base/field.h> #include <vespa/document/config/config-documenttypes.h> #include <vespa/document/config/documenttypes_config_fwd.h> -#include <vespa/document/datatype/datatype.h> -#include <vespa/document/datatype/structdatatype.h> #include <vespa/vespalib/stllike/string.h> #include <cassert> diff --git a/document/src/vespa/document/repo/documenttyperepo.cpp b/document/src/vespa/document/repo/documenttyperepo.cpp index 3a7769c831e..1738dbd0141 100644 --- a/document/src/vespa/document/repo/documenttyperepo.cpp +++ b/document/src/vespa/document/repo/documenttyperepo.cpp @@ -293,7 +293,7 @@ void addStruct(int32_t id, const Datatype::Sstruct &s, Repo &repo) { const DataType *existing = repo.lookup(name); if (useUglyStructHack && existing) { LOG(spam, "Type %s already existed", name.c_str()); - const StructDataType& cdt = Identifiable::cast<const StructDataType&>(*existing); + const StructDataType& cdt = dynamic_cast<const StructDataType&>(*existing); struct_type = const_cast<StructDataType*>(&cdt); } else { const DataType *existing_retry = repo.lookup(id); diff --git a/document/src/vespa/document/update/addfieldpathupdate.cpp b/document/src/vespa/document/update/addfieldpathupdate.cpp index 86672a08fd2..227ac34d78b 100644 --- a/document/src/vespa/document/update/addfieldpathupdate.cpp +++ b/document/src/vespa/document/update/addfieldpathupdate.cpp @@ -95,7 +95,7 @@ AddFieldPathUpdate::deserialize(const DocumentTypeRepo& repo, const DataType& ty FieldPath path; type.buildFieldPath(path, getOriginalFieldPath()); const DataType& fieldType = getResultingDataType(path); - assert(fieldType.inherits(ArrayDataType::classId)); + assert(fieldType.isArray()); FieldValue::UP val = fieldType.createFieldValue(); _values.reset(static_cast<ArrayFieldValue*>(val.release())); VespaDocumentDeserializer deserializer(repo, stream, Document::getNewestSerializationVersion()); diff --git a/document/src/vespa/document/update/addvalueupdate.cpp b/document/src/vespa/document/update/addvalueupdate.cpp index 22e3582b14d..e12afd8fa63 100644 --- a/document/src/vespa/document/update/addvalueupdate.cpp +++ b/document/src/vespa/document/update/addvalueupdate.cpp @@ -40,9 +40,9 @@ AddValueUpdate::operator==(const ValueUpdate& other) const void AddValueUpdate::checkCompatibility(const Field& field) const { - if (field.getDataType().inherits(CollectionDataType::classId)) { - const CollectionDataType& type(static_cast<const CollectionDataType&>(field.getDataType())); - if (!type.getNestedType().isValueType(*_value)) { + const CollectionDataType *ct = field.getDataType().cast_collection(); + if (ct != nullptr) { + if (!ct->getNestedType().isValueType(*_value)) { throw IllegalArgumentException("Cannot add value of type " + _value->getDataType()->toString() + " to field " + field.getName() + " of container type " + field.getDataType().toString(), VESPA_STRLOC); @@ -88,7 +88,7 @@ AddValueUpdate::printXml(XmlOutputStream& xos) const void AddValueUpdate::deserialize(const DocumentTypeRepo& repo, const DataType& type, nbostream& stream) { - const CollectionDataType* ctype = Identifiable::cast<const CollectionDataType*>(&type); + const CollectionDataType *ctype = type.cast_collection(); if (ctype == nullptr) { throw DeserializeException("Can not perform add operation on non-collection type."); } diff --git a/document/src/vespa/document/update/arithmeticvalueupdate.cpp b/document/src/vespa/document/update/arithmeticvalueupdate.cpp index a30b7acdea1..b33312d8e65 100644 --- a/document/src/vespa/document/update/arithmeticvalueupdate.cpp +++ b/document/src/vespa/document/update/arithmeticvalueupdate.cpp @@ -33,7 +33,7 @@ ArithmeticValueUpdate::operator==(const ValueUpdate& other) const void ArithmeticValueUpdate::checkCompatibility(const Field& field) const { - if ( ! field.getDataType().inherits(NumericDataType::classId)) { + if ( ! field.getDataType().isNumeric()) { throw IllegalArgumentException(vespalib::make_string( "Can not perform arithmetic update on non-numeric field '%s'.", field.getName().data()), VESPA_STRLOC); diff --git a/document/src/vespa/document/update/fieldupdate.h b/document/src/vespa/document/update/fieldupdate.h index a00e5c73821..1e4137b9531 100644 --- a/document/src/vespa/document/update/fieldupdate.h +++ b/document/src/vespa/document/update/fieldupdate.h @@ -19,6 +19,7 @@ namespace document { class Document; +class DocumentType; class FieldUpdate : public vespalib::Identifiable, public Printable, diff --git a/document/src/vespa/document/update/removevalueupdate.cpp b/document/src/vespa/document/update/removevalueupdate.cpp index 979e2e736de..eb5d6547d75 100644 --- a/document/src/vespa/document/update/removevalueupdate.cpp +++ b/document/src/vespa/document/update/removevalueupdate.cpp @@ -39,9 +39,9 @@ RemoveValueUpdate::operator==(const ValueUpdate& other) const void RemoveValueUpdate::checkCompatibility(const Field& field) const { - if (field.getDataType().inherits(CollectionDataType::classId)) { - const CollectionDataType& type = static_cast<const CollectionDataType&>(field.getDataType()); - if (!type.getNestedType().isValueType(*_key)) { + const CollectionDataType *type = field.getDataType().cast_collection(); + if (type != nullptr) { + if (!type->getNestedType().isValueType(*_key)) { throw IllegalArgumentException( "Cannot remove value of type " + _key->getDataType()->toString() + " from field " diff --git a/document/src/vespa/document/update/tensor_modify_update.cpp b/document/src/vespa/document/update/tensor_modify_update.cpp index 6b2fe96c06d..4c114ba477c 100644 --- a/document/src/vespa/document/update/tensor_modify_update.cpp +++ b/document/src/vespa/document/update/tensor_modify_update.cpp @@ -102,7 +102,7 @@ TensorModifyUpdate::TensorModifyUpdate(const TensorModifyUpdate &rhs) TensorModifyUpdate::TensorModifyUpdate(Operation operation, std::unique_ptr<TensorFieldValue> tensor) : _operation(operation), - _tensorType(Identifiable::cast<const TensorDataType &>(*tensor->getDataType()).clone()), + _tensorType(dynamic_cast<const TensorDataType &>(*tensor->getDataType()).clone()), _tensor(Identifiable::cast<TensorFieldValue *>(_tensorType->createFieldValue().release())) { *_tensor = *tensor; @@ -240,7 +240,7 @@ TensorModifyUpdate::deserialize(const DocumentTypeRepo &repo, const DataType &ty throw DeserializeException(msg.str(), VESPA_STRLOC); } _operation = static_cast<Operation>(op); - _tensorType = convertToCompatibleType(Identifiable::cast<const TensorDataType &>(type)); + _tensorType = convertToCompatibleType(dynamic_cast<const TensorDataType &>(type)); auto tensor = _tensorType->createFieldValue(); if (tensor->inherits(TensorFieldValue::classId)) { _tensor.reset(static_cast<TensorFieldValue *>(tensor.release())); diff --git a/document/src/vespa/document/update/tensor_remove_update.cpp b/document/src/vespa/document/update/tensor_remove_update.cpp index 2677f9c8eaa..2afd0869d62 100644 --- a/document/src/vespa/document/update/tensor_remove_update.cpp +++ b/document/src/vespa/document/update/tensor_remove_update.cpp @@ -55,7 +55,7 @@ TensorRemoveUpdate::TensorRemoveUpdate(const TensorRemoveUpdate &rhs) } TensorRemoveUpdate::TensorRemoveUpdate(std::unique_ptr<TensorFieldValue> tensor) - : _tensorType(Identifiable::cast<const TensorDataType &>(*tensor->getDataType()).clone()), + : _tensorType(dynamic_cast<const TensorDataType &>(*tensor->getDataType()).clone()), _tensor(Identifiable::cast<TensorFieldValue *>(_tensorType->createFieldValue().release())) { *_tensor = *tensor; @@ -195,7 +195,7 @@ TensorRemoveUpdate::deserialize(const DocumentTypeRepo &repo, const DataType &ty VespaDocumentDeserializer deserializer(repo, stream, Document::getNewestSerializationVersion()); auto tensor = deserializer.readTensor(); verifyAddressTensorIsSparse(tensor.get()); - auto compatible_type = convertToCompatibleType(Identifiable::cast<const TensorDataType &>(type)); + auto compatible_type = convertToCompatibleType(dynamic_cast<const TensorDataType &>(type)); verify_tensor_type_dimensions_are_subset_of(tensor->type(), compatible_type->getTensorType()); _tensorType = std::make_unique<const TensorDataType>(tensor->type()); _tensor = std::make_unique<TensorFieldValue>(*_tensorType); diff --git a/document/src/vespa/document/update/valueupdate.cpp b/document/src/vespa/document/update/valueupdate.cpp index 2be6a4f2e63..8a023fb9ef2 100644 --- a/document/src/vespa/document/update/valueupdate.cpp +++ b/document/src/vespa/document/update/valueupdate.cpp @@ -2,7 +2,6 @@ #include "valueupdate.h" #include <vespa/vespalib/util/stringfmt.h> -#include <vespa/vespalib/objects/nbostream.h> #include <stdexcept> namespace document { diff --git a/document/src/vespa/document/update/valueupdate.h b/document/src/vespa/document/update/valueupdate.h index b2f4a1da609..9a8ed4e9537 100644 --- a/document/src/vespa/document/update/valueupdate.h +++ b/document/src/vespa/document/update/valueupdate.h @@ -19,14 +19,17 @@ #pragma once #include "updatevisitor.h" -#include <vespa/document/datatype/datatype.h> +#include <vespa/document/util/printable.h> #include <vespa/document/util/xmlserializable.h> +#include <vespa/document/util/identifiableid.h> +#include <vespa/vespalib/objects/nbostream.h> namespace document { class DocumentTypeRepo; class Field; class FieldValue; +class DataType; class ValueUpdate : public vespalib::Identifiable, public Printable, |