diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2022-03-04 05:00:44 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2022-03-04 08:11:53 +0000 |
commit | 19c86cb3ebac5b36630eb2a83281bb0d037a9070 (patch) | |
tree | b2e527d41d7c12a4673a1ba6daa7faff334f9adf /document | |
parent | 50780f816746c84bbb9f6d2c476c5cb3e57740f7 (diff) |
Remove identifiable from document::DataType
Also remove the virtual == operator and the need for default constructor.
Diffstat (limited to 'document')
47 files changed, 294 insertions, 421 deletions
diff --git a/document/src/tests/annotation/annotation_test.cpp b/document/src/tests/annotation/annotation_test.cpp index e940d147588..1e4e216cdc6 100644 --- a/document/src/tests/annotation/annotation_test.cpp +++ b/document/src/tests/annotation/annotation_test.cpp @@ -139,11 +139,11 @@ TEST("requireThatSpanTreeCanHaveMultipleLevels") { TEST("requireThatAnnotationsCanHaveValues") { PrimitiveDataType double_type(DataType::T_DOUBLE); - StructDataType city_data_type; + StructDataType city_data_type("city"); city_data_type.addField(Field("latitude", 0, double_type)); city_data_type.addField(Field("longitude", 1, double_type)); - StructFieldValue::UP position(new StructFieldValue(city_data_type)); + auto position = std::make_unique<StructFieldValue>(city_data_type); position->setValue("latitude", DoubleFieldValue(37.774929)); position->setValue("longitude", DoubleFieldValue(-122.419415)); StructFieldValue original(*position); @@ -164,7 +164,7 @@ TEST("requireThatAnnotationsCanReferenceAnnotations") { StructDataType city_data_type("name", 42); city_data_type.addField(Field("references", 0, array_type)); - StructFieldValue::UP city_data(new StructFieldValue(city_data_type)); + auto city_data = std::make_unique<StructFieldValue>(city_data_type); ArrayFieldValue ref_list(array_type); ref_list.add(AnnotationReferenceFieldValue(annotation_ref_type, san_index)); ref_list.add(AnnotationReferenceFieldValue(annotation_ref_type, fran_index)); diff --git a/document/src/tests/documenttestcase.cpp b/document/src/tests/documenttestcase.cpp index 82c1d62be59..fde702f2080 100644 --- a/document/src/tests/documenttestcase.cpp +++ b/document/src/tests/documenttestcase.cpp @@ -50,7 +50,7 @@ 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(80ul, sizeof(NumericDataType)); EXPECT_EQ(24ul, sizeof(LongFieldValue)); EXPECT_EQ(96ul, sizeof(StructFieldValue)); EXPECT_EQ(16ul, sizeof(StructuredFieldValue)); diff --git a/document/src/tests/fieldpathupdatetestcase.cpp b/document/src/tests/fieldpathupdatetestcase.cpp index cd4e03bbfe7..3ebf3699763 100644 --- a/document/src/tests/fieldpathupdatetestcase.cpp +++ b/document/src/tests/fieldpathupdatetestcase.cpp @@ -37,7 +37,8 @@ using namespace fieldvalue; class FieldPathUpdateTestCase : public ::testing::Test { protected: std::shared_ptr<const DocumentTypeRepo> _repo; - DocumentType _foobar_type; + const DocumentType *_foobar_type; + FieldPathUpdateTestCase(); ~FieldPathUpdateTestCase(); void SetUp() override; @@ -241,6 +242,10 @@ TestFieldPathUpdate::TestFieldPathUpdate(const TestFieldPathUpdate& other) { } +FieldPathUpdateTestCase::FieldPathUpdateTestCase() + : _foobar_type(nullptr) +{} + FieldPathUpdateTestCase::~FieldPathUpdateTestCase() = default; void @@ -263,7 +268,7 @@ FieldPathUpdateTestCase::SetUp() Map(DataType::T_STRING, DataType::T_STRING))); _repo.reset(new DocumentTypeRepo(builder.config())); - _foobar_type = *_repo->getDocumentType("foobar"); + _foobar_type = _repo->getDocumentType("foobar"); } void @@ -302,12 +307,12 @@ TEST_F(FieldPathUpdateTestCase, testNoIterateMapValues) TEST_F(FieldPathUpdateTestCase, testRemoveField) { - Document::UP doc(new Document(_foobar_type, DocumentId("id:ns:foobar::things:thangs"))); + auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::things:thangs")); EXPECT_TRUE(doc->hasValue("strfoo") == false); doc->setValue("strfoo", StringFieldValue("cocacola")); EXPECT_EQ(vespalib::string("cocacola"), doc->getValue("strfoo")->getAsString()); //doc->print(std::cerr, true, ""); - DocumentUpdate docUp(*_repo, _foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); + DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); docUp.addFieldPathUpdate(FieldPathUpdate::CP(new RemoveFieldPathUpdate("strfoo"))); docUp.applyTo(*doc); EXPECT_TRUE(doc->hasValue("strfoo") == false); @@ -315,7 +320,7 @@ TEST_F(FieldPathUpdateTestCase, testRemoveField) TEST_F(FieldPathUpdateTestCase, testApplyRemoveMultiList) { - Document::UP doc(new Document(_foobar_type, DocumentId("id:ns:foobar::things:thangs"))); + auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::things:thangs")); doc->setRepo(*_repo); EXPECT_TRUE(doc->hasValue("strarray") == false); { @@ -327,7 +332,7 @@ TEST_F(FieldPathUpdateTestCase, testApplyRemoveMultiList) } EXPECT_TRUE(doc->hasValue("strarray")); //doc->print(std::cerr, true, ""); - DocumentUpdate docUp(*_repo, _foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); + DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); docUp.addFieldPathUpdate(FieldPathUpdate::CP( new RemoveFieldPathUpdate("strarray[$x]", "foobar.strarray[$x] == \"remove val 1\""))); docUp.applyTo(*doc); @@ -341,7 +346,7 @@ TEST_F(FieldPathUpdateTestCase, testApplyRemoveMultiList) TEST_F(FieldPathUpdateTestCase, testApplyRemoveMultiList2) { - Document::UP doc(new Document(_foobar_type, DocumentId("id:ns:foobar::things:thangs"))); + auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::things:thangs")); doc->setRepo(*_repo); EXPECT_TRUE(doc->hasValue("strarray") == false); { @@ -353,7 +358,7 @@ TEST_F(FieldPathUpdateTestCase, testApplyRemoveMultiList2) } EXPECT_TRUE(doc->hasValue("strarray")); //doc->print(std::cerr, true, ""); - DocumentUpdate docUp(*_repo, _foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); + DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); docUp.addFieldPathUpdate(FieldPathUpdate::CP( new RemoveFieldPathUpdate("strarray[$x]", "foobar.strarray[$x] == \"remove val 1\""))); docUp.applyTo(*doc); @@ -366,7 +371,7 @@ TEST_F(FieldPathUpdateTestCase, testApplyRemoveMultiList2) TEST_F(FieldPathUpdateTestCase, testApplyRemoveEntireListField) { - Document::UP doc(new Document(_foobar_type, DocumentId("id:ns:foobar::things:thangs"))); + auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::things:thangs")); EXPECT_TRUE(doc->hasValue("strarray") == false); { ArrayFieldValue strArray(doc->getType().getField("strarray").getDataType()); @@ -376,7 +381,7 @@ TEST_F(FieldPathUpdateTestCase, testApplyRemoveEntireListField) doc->setValue("strarray", strArray); } //doc->print(std::cerr, true, ""); - DocumentUpdate docUp(*_repo, _foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); + DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); docUp.addFieldPathUpdate(FieldPathUpdate::CP(new RemoveFieldPathUpdate("strarray", ""))); docUp.applyTo(*doc); EXPECT_TRUE(!doc->hasValue("strarray")); @@ -384,7 +389,7 @@ TEST_F(FieldPathUpdateTestCase, testApplyRemoveEntireListField) TEST_F(FieldPathUpdateTestCase, testApplyRemoveMultiWset) { - Document::UP doc(new Document(_foobar_type, DocumentId("id:ns:foobar::helan:halvan"))); + auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::helan:halvan")); EXPECT_TRUE(doc->hasValue("strwset") == false); { WeightedSetFieldValue strWset(doc->getType().getField("strwset").getDataType()); @@ -394,7 +399,7 @@ TEST_F(FieldPathUpdateTestCase, testApplyRemoveMultiWset) } EXPECT_TRUE(doc->hasValue("strwset")); //doc->print(std::cerr, true, ""); - DocumentUpdate docUp(*_repo, _foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); + DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); docUp.addFieldPathUpdate(FieldPathUpdate::CP(new RemoveFieldPathUpdate("strwset{remove val 1}"))); docUp.applyTo(*doc); { @@ -406,17 +411,17 @@ TEST_F(FieldPathUpdateTestCase, testApplyRemoveMultiWset) TEST_F(FieldPathUpdateTestCase, testApplyAssignSingle) { - Document::UP doc(new Document(_foobar_type, DocumentId("id:ns:foobar::drekka:karsk"))); + auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::drekka:karsk")); EXPECT_TRUE(doc->hasValue("strfoo") == false); // Test assignment of non-existing - DocumentUpdate docUp(*_repo, _foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); + DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); docUp.addFieldPathUpdate(FieldPathUpdate::CP( new AssignFieldPathUpdate(*doc->getDataType(), "strfoo", std::string(), StringFieldValue("himert")))); docUp.applyTo(*doc); EXPECT_TRUE(doc->hasValue("strfoo")); EXPECT_EQ(vespalib::string("himert"), doc->getValue("strfoo")->getAsString()); // Test overwriting existing - DocumentUpdate docUp2(*_repo, _foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); + DocumentUpdate docUp2(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); docUp2.addFieldPathUpdate(FieldPathUpdate::CP( new AssignFieldPathUpdate(*doc->getDataType(), "strfoo", std::string(), StringFieldValue("wunderbaum")))); docUp2.applyTo(*doc); @@ -425,10 +430,10 @@ TEST_F(FieldPathUpdateTestCase, testApplyAssignSingle) TEST_F(FieldPathUpdateTestCase, testApplyAssignMath) { - Document::UP doc(new Document(_foobar_type, DocumentId("id:ns:foobar::bat:man"))); + auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::bat:man")); doc->setValue("num", IntFieldValue(34)); - DocumentUpdate docUp(*_repo, _foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); + DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); docUp.addFieldPathUpdate(FieldPathUpdate::CP(new AssignFieldPathUpdate("num", "", "($value * 2) / $value"))); docUp.applyTo(*doc); EXPECT_EQ(static_cast<const FieldValue&>(IntFieldValue(2)), *doc->getValue("num")); @@ -436,10 +441,10 @@ TEST_F(FieldPathUpdateTestCase, testApplyAssignMath) TEST_F(FieldPathUpdateTestCase, testApplyAssignMathByteToZero) { - Document::UP doc(new Document(_foobar_type, DocumentId("id:ns:foobar::bat:man"))); + auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::bat:man")); doc->setValue("byteval", ByteFieldValue(3)); - DocumentUpdate docUp(*_repo, _foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); + DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); docUp.addFieldPathUpdate(FieldPathUpdate::CP(new AssignFieldPathUpdate("byteval", "", "$value - 3"))); docUp.applyTo(*doc); EXPECT_EQ(static_cast<const FieldValue&>(ByteFieldValue(0)), *doc->getValue("byteval")); @@ -448,10 +453,10 @@ TEST_F(FieldPathUpdateTestCase, testApplyAssignMathByteToZero) TEST_F(FieldPathUpdateTestCase, testApplyAssignMathNotModifiedOnUnderflow) { int low_value = -126; - Document::UP doc(new Document(_foobar_type, DocumentId("id:ns:foobar::bat:man"))); + auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::bat:man")); doc->setValue("byteval", ByteFieldValue(low_value)); - DocumentUpdate docUp(*_repo, _foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); + DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); docUp.addFieldPathUpdate(FieldPathUpdate::CP(new AssignFieldPathUpdate("byteval", "", "$value - 4"))); docUp.applyTo(*doc); // Over/underflow will happen. You must have control of your data types. @@ -460,10 +465,10 @@ TEST_F(FieldPathUpdateTestCase, testApplyAssignMathNotModifiedOnUnderflow) TEST_F(FieldPathUpdateTestCase, testApplyAssignMathNotModifiedOnOverflow) { - Document::UP doc(new Document(_foobar_type, DocumentId("id:ns:foobar::bat:man"))); + auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::bat:man")); doc->setValue("byteval", ByteFieldValue(127)); - DocumentUpdate docUp(*_repo, _foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); + DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); docUp.addFieldPathUpdate(FieldPathUpdate::CP(new AssignFieldPathUpdate("byteval", "", "$value + 200"))); docUp.applyTo(*doc); // Over/underflow will happen. You must have control of your data types. @@ -472,11 +477,11 @@ TEST_F(FieldPathUpdateTestCase, testApplyAssignMathNotModifiedOnOverflow) TEST_F(FieldPathUpdateTestCase, testApplyAssignMathDivZero) { - Document::UP doc(new Document(_foobar_type, DocumentId("id:ns:foobar::bat:man"))); + auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::bat:man")); EXPECT_TRUE(doc->hasValue("num") == false); doc->setValue("num", IntFieldValue(10)); - DocumentUpdate docUp(*_repo, _foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); + DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); docUp.addFieldPathUpdate(FieldPathUpdate::CP(new AssignFieldPathUpdate("num", "", "$value / ($value - 10)"))); docUp.applyTo(*doc); EXPECT_EQ(static_cast<const FieldValue&>(IntFieldValue(10)), *doc->getValue("num")); @@ -484,12 +489,12 @@ TEST_F(FieldPathUpdateTestCase, testApplyAssignMathDivZero) TEST_F(FieldPathUpdateTestCase, testApplyAssignFieldNotExistingInExpression) { - Document::UP doc(new Document(_foobar_type, DocumentId("id:ns:foobar::bat:man"))); + auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::bat:man")); doc->setRepo(*_repo); EXPECT_TRUE(doc->hasValue("num") == false); doc->setValue("num", IntFieldValue(10)); - DocumentUpdate docUp(*_repo, _foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); + DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); docUp.addFieldPathUpdate(FieldPathUpdate::CP(new AssignFieldPathUpdate("num", "", "foobar.num2 + $value"))); docUp.applyTo(*doc); EXPECT_EQ(static_cast<const FieldValue&>(IntFieldValue(10)), *doc->getValue("num")); @@ -497,10 +502,10 @@ TEST_F(FieldPathUpdateTestCase, testApplyAssignFieldNotExistingInExpression) TEST_F(FieldPathUpdateTestCase, testApplyAssignFieldNotExistingInPath) { - Document::UP doc(new Document(_foobar_type, DocumentId("id:ns:foobar::bat:man"))); + auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::bat:man")); doc->setRepo(*_repo); - DocumentUpdate docUp(*_repo, _foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); + DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); try { docUp.addFieldPathUpdate(FieldPathUpdate::CP(new AssignFieldPathUpdate("nosuchnum", "", "foobar.num + $value"))); docUp.applyTo(*doc); @@ -511,10 +516,10 @@ TEST_F(FieldPathUpdateTestCase, testApplyAssignFieldNotExistingInPath) TEST_F(FieldPathUpdateTestCase, testApplyAssignTargetNotExisting) { - Document::UP doc(new Document(_foobar_type, DocumentId("id:ns:foobar::bat:man"))); + auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::bat:man")); EXPECT_TRUE(doc->hasValue("num") == false); - DocumentUpdate docUp(*_repo, _foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); + DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); docUp.addFieldPathUpdate(FieldPathUpdate::CP(new AssignFieldPathUpdate("num", "", "$value + 5"))); docUp.applyTo(*doc); EXPECT_EQ(static_cast<const FieldValue&>(IntFieldValue(5)), *doc->getValue("num")); @@ -522,7 +527,7 @@ TEST_F(FieldPathUpdateTestCase, testApplyAssignTargetNotExisting) TEST_F(FieldPathUpdateTestCase, testAssignSimpleMapValueWithVariable) { - Document::UP doc(new Document(_foobar_type, DocumentId("id:ns:foobar::bug:hunter"))); + auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::bug:hunter")); doc->setRepo(*_repo); MapFieldValue mfv(doc->getType().getField("strmap").getDataType()); @@ -530,7 +535,7 @@ TEST_F(FieldPathUpdateTestCase, testAssignSimpleMapValueWithVariable) mfv.put(StringFieldValue("baz"), StringFieldValue("bananas")); doc->setValue("strmap", mfv); - DocumentUpdate docUp(*_repo, _foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); + DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); // Select on value, not key docUp.addFieldPathUpdate(FieldPathUpdate::CP( new AssignFieldPathUpdate(*doc->getDataType(), @@ -550,12 +555,12 @@ TEST_F(FieldPathUpdateTestCase, testAssignSimpleMapValueWithVariable) TEST_F(FieldPathUpdateTestCase, testApplyAssignMathRemoveIfZero) { - Document::UP doc(new Document(_foobar_type, DocumentId("id:ns:foobar::bat:man"))); + auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::bat:man")); EXPECT_TRUE(doc->hasValue("num") == false); doc->setValue("num", IntFieldValue(34)); EXPECT_TRUE(doc->hasValue("num") == true); - DocumentUpdate docUp(*_repo, _foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); + DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); FieldPathUpdate::CP up1(new AssignFieldPathUpdate("num", "", "($value * 2) / $value - 2")); static_cast<AssignFieldPathUpdate&>(*up1).setRemoveIfZero(true); docUp.addFieldPathUpdate(up1); @@ -566,7 +571,7 @@ TEST_F(FieldPathUpdateTestCase, testApplyAssignMathRemoveIfZero) TEST_F(FieldPathUpdateTestCase, testApplyAssignMultiList) { - Document::UP doc(new Document(_foobar_type, DocumentId("id:ns:foobar::fest:skinnvest"))); + auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::fest:skinnvest")); EXPECT_TRUE(doc->hasValue("strarray") == false); { @@ -581,7 +586,7 @@ TEST_F(FieldPathUpdateTestCase, testApplyAssignMultiList) updateArray.add(StringFieldValue("assigned val 0")); updateArray.add(StringFieldValue("assigned val 1")); - DocumentUpdate docUp(*_repo, _foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); + DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); docUp.addFieldPathUpdate(FieldPathUpdate::CP( new AssignFieldPathUpdate(*doc->getDataType(), "strarray", std::string(), updateArray))); docUp.applyTo(*doc); @@ -597,7 +602,7 @@ TEST_F(FieldPathUpdateTestCase, testApplyAssignMultiList) TEST_F(FieldPathUpdateTestCase, testApplyAssignMultiWset) { - Document::UP doc(new Document(_foobar_type, DocumentId("id:ns:foobar::fest:skinnvest"))); + auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::fest:skinnvest")); EXPECT_TRUE(doc->hasValue("strarray") == false); { @@ -612,7 +617,7 @@ TEST_F(FieldPathUpdateTestCase, testApplyAssignMultiWset) assignWset.add(StringFieldValue("assigned val 0"), 5); assignWset.add(StringFieldValue("assigned val 1"), 10); - DocumentUpdate docUp(*_repo, _foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); + DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); docUp.addFieldPathUpdate(FieldPathUpdate::CP( new AssignFieldPathUpdate(*doc->getDataType(), "strwset", std::string(), assignWset))); //doc->print(std::cerr, true, ""); @@ -628,7 +633,7 @@ TEST_F(FieldPathUpdateTestCase, testApplyAssignMultiWset) TEST_F(FieldPathUpdateTestCase, testAssignWsetRemoveIfZero) { - Document::UP doc(new Document(_foobar_type, DocumentId("id:ns:foobar::tronder:bataljon"))); + auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::tronder:bataljon")); EXPECT_TRUE(doc->hasValue("strarray") == false); { @@ -640,7 +645,7 @@ TEST_F(FieldPathUpdateTestCase, testAssignWsetRemoveIfZero) } { - DocumentUpdate docUp(*_repo, _foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); + DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); IntFieldValue zeroWeight(0); FieldPathUpdate::CP assignUpdate( new AssignFieldPathUpdate(*doc->getDataType(), "strwset{you say goodbye}", std::string(), zeroWeight)); @@ -659,7 +664,7 @@ TEST_F(FieldPathUpdateTestCase, testAssignWsetRemoveIfZero) TEST_F(FieldPathUpdateTestCase, testApplyAddMultiList) { - Document::UP doc(new Document(_foobar_type, DocumentId("id:ns:foobar::george:costanza"))); + auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::george:costanza")); EXPECT_TRUE(doc->hasValue("strarray") == false); ArrayFieldValue adds(doc->getType().getField("strarray").getDataType()); @@ -667,7 +672,7 @@ TEST_F(FieldPathUpdateTestCase, testApplyAddMultiList) adds.add(StringFieldValue("a festivus for the rest of us")); adds.add(StringFieldValue("george is getting upset!")); - DocumentUpdate docUp(*_repo, _foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); + DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); docUp.addFieldPathUpdate(FieldPathUpdate::CP( new AddFieldPathUpdate(*doc->getDataType(), "strarray", std::string(), adds))); //doc->print(std::cerr, true, ""); @@ -678,7 +683,7 @@ TEST_F(FieldPathUpdateTestCase, testApplyAddMultiList) TEST_F(FieldPathUpdateTestCase, testAddAndAssignList) { - Document::UP doc(new Document(_foobar_type, DocumentId("id:ns:foobar::fancy:pants"))); + auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::fancy:pants")); EXPECT_TRUE(doc->hasValue("strarray") == false); { @@ -689,7 +694,7 @@ TEST_F(FieldPathUpdateTestCase, testAddAndAssignList) EXPECT_TRUE(doc->hasValue("strarray")); } - DocumentUpdate docUp(*_repo, _foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); + DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); docUp.addFieldPathUpdate(FieldPathUpdate::CP( new AssignFieldPathUpdate(*doc->getDataType(), "strarray[1]", std::string(), StringFieldValue("assigned val 1")))); @@ -768,9 +773,9 @@ Fixture::Fixture(const DocumentType &doc_type, const Keys &k) TEST_F(FieldPathUpdateTestCase, testAssignMap) { Keys k; - Fixture f(_foobar_type, k); + Fixture f(*_foobar_type, k); - DocumentUpdate docUp(*_repo, _foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); + DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); docUp.addFieldPathUpdate(FieldPathUpdate::CP( new AssignFieldPathUpdate(*f.doc->getDataType(), "structmap{" + k.key2 + "}", std::string(), f.fv4))); docUp.applyTo(*f.doc); @@ -788,9 +793,9 @@ TEST_F(FieldPathUpdateTestCase, testAssignMap) TEST_F(FieldPathUpdateTestCase, testAssignMapStruct) { Keys k; - Fixture f(_foobar_type, k); + Fixture f(*_foobar_type, k); - DocumentUpdate docUp(*_repo, _foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); + DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); docUp.addFieldPathUpdate(FieldPathUpdate::CP( new AssignFieldPathUpdate(*f.doc->getDataType(), "structmap{" + k.key2 + "}.rating", std::string(), IntFieldValue(48)))); @@ -809,9 +814,9 @@ TEST_F(FieldPathUpdateTestCase, testAssignMapStruct) TEST_F(FieldPathUpdateTestCase, testAssignMapStructVariable) { Keys k; - Fixture f(_foobar_type, k); + Fixture f(*_foobar_type, k); - DocumentUpdate docUp(*_repo, _foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); + DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); docUp.addFieldPathUpdate(FieldPathUpdate::CP( new AssignFieldPathUpdate(*f.doc->getDataType(), "structmap{$x}.rating", "foobar.structmap{$x}.title == \"farnsworth\"", IntFieldValue(48)))); @@ -830,14 +835,14 @@ TEST_F(FieldPathUpdateTestCase, testAssignMapStructVariable) TEST_F(FieldPathUpdateTestCase, testAssignMapNoExist) { - Document::UP doc(new Document(_foobar_type, DocumentId("id:ns:foobar::planet:express"))); + auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::planet:express")); MapFieldValue mfv(doc->getType().getField("structmap").getDataType()); StructFieldValue fv1(dynamic_cast<const MapDataType&>(*mfv.getDataType()).getValueType()); fv1.setValue("title", StringFieldValue("fry")); fv1.setValue("rating", IntFieldValue(30)); - DocumentUpdate docUp(*_repo, _foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); + DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); docUp.addFieldPathUpdate(FieldPathUpdate::CP( new AssignFieldPathUpdate(*doc->getDataType(), "structmap{foo}", std::string(), fv1))); //doc->print(std::cerr, true, ""); @@ -852,14 +857,14 @@ TEST_F(FieldPathUpdateTestCase, testAssignMapNoExist) TEST_F(FieldPathUpdateTestCase, testAssignMapNoExistNoCreate) { - Document::UP doc(new Document(_foobar_type, DocumentId("id:ns:foobar::planet:express"))); + auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::planet:express")); MapFieldValue mfv(doc->getType().getField("structmap").getDataType()); StructFieldValue fv1(dynamic_cast<const MapDataType&>(*mfv.getDataType()).getValueType()); fv1.setValue("title", StringFieldValue("fry")); fv1.setValue("rating", IntFieldValue(30)); - DocumentUpdate docUp(*_repo, _foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); + DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); FieldPathUpdate::CP assignUpdate( new AssignFieldPathUpdate(*doc->getDataType(), "structmap{foo}", std::string(), fv1)); static_cast<AssignFieldPathUpdate&>(*assignUpdate).setCreateMissingPath(false); @@ -878,9 +883,9 @@ TEST_F(FieldPathUpdateTestCase, testQuotedStringKey) Keys k; k.key2 = "here is a \"fancy\" 'map' :-} key :-{"; const char field_path[] = "structmap{\"here is a \\\"fancy\\\" 'map' :-} key :-{\"}"; - Fixture f(_foobar_type, k); + Fixture f(*_foobar_type, k); - DocumentUpdate docUp(*_repo, _foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); + DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); docUp.addFieldPathUpdate(FieldPathUpdate::CP( new AssignFieldPathUpdate(*f.doc->getDataType(), field_path, std::string(), f.fv4))); docUp.applyTo(*f.doc); @@ -897,7 +902,7 @@ TEST_F(FieldPathUpdateTestCase, testQuotedStringKey) TEST_F(FieldPathUpdateTestCase, testEqualityComparison) { - Document::UP doc(new Document(_foobar_type, DocumentId("id:ns:foobar::foo:zoo"))); + auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::foo:zoo")); MapFieldValue mfv(doc->getType().getField("structmap").getDataType()); StructFieldValue fv4(dynamic_cast<const MapDataType&>(*mfv.getDataType()).getValueType()); @@ -905,8 +910,8 @@ TEST_F(FieldPathUpdateTestCase, testEqualityComparison) fv4.setValue("rating", IntFieldValue(95)); { - DocumentUpdate docUp1(*_repo, _foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); - DocumentUpdate docUp2(*_repo, _foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); + DocumentUpdate docUp1(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); + DocumentUpdate docUp2(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); EXPECT_TRUE(docUp1 == docUp2); FieldPathUpdate::CP assignUp1(new AssignFieldPathUpdate(*doc->getDataType(), @@ -917,8 +922,8 @@ TEST_F(FieldPathUpdateTestCase, testEqualityComparison) EXPECT_TRUE(docUp1 == docUp2); } { - DocumentUpdate docUp1(*_repo, _foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); - DocumentUpdate docUp2(*_repo, _foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); + DocumentUpdate docUp1(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); + DocumentUpdate docUp2(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); // where-clause diff FieldPathUpdate::CP assignUp1(new AssignFieldPathUpdate(*doc->getDataType(), "structmap{here be dragons}", std::string(), fv4)); @@ -929,8 +934,8 @@ TEST_F(FieldPathUpdateTestCase, testEqualityComparison) EXPECT_TRUE(docUp1 != docUp2); } { - DocumentUpdate docUp1(*_repo, _foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); - DocumentUpdate docUp2(*_repo, _foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); + DocumentUpdate docUp1(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); + DocumentUpdate docUp2(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); // fieldpath diff FieldPathUpdate::CP assignUp1(new AssignFieldPathUpdate(*doc->getDataType(), "structmap{here be dragons}", std::string(), fv4)); @@ -945,7 +950,7 @@ TEST_F(FieldPathUpdateTestCase, testEqualityComparison) TEST_F(FieldPathUpdateTestCase, testAffectsDocumentBody) { - Document::UP doc(new Document(_foobar_type, DocumentId("id:ns:foobar::things:stuff"))); + auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::things:stuff")); MapFieldValue mfv(doc->getType().getField("structmap").getDataType()); StructFieldValue fv4(dynamic_cast<const MapDataType&>(*mfv.getDataType()).getValueType()); @@ -954,7 +959,7 @@ TEST_F(FieldPathUpdateTestCase, testAffectsDocumentBody) // structmap is body field { - DocumentUpdate docUp(*_repo, _foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); + DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); FieldPathUpdate::CP update1(new AssignFieldPathUpdate(*doc->getDataType(), "structmap{janitor}", std::string(), fv4)); @@ -964,7 +969,7 @@ TEST_F(FieldPathUpdateTestCase, testAffectsDocumentBody) // strfoo is header field { - DocumentUpdate docUp(*_repo, _foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); + DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); FieldPathUpdate::CP update1(new AssignFieldPathUpdate(*doc->getDataType(), "strfoo", std::string(), StringFieldValue("helloworld"))); static_cast<AssignFieldPathUpdate&>(*update1).setCreateMissingPath(true); @@ -975,10 +980,10 @@ TEST_F(FieldPathUpdateTestCase, testAffectsDocumentBody) TEST_F(FieldPathUpdateTestCase, testIncompatibleDataTypeFails) { - Document::UP doc(new Document(_foobar_type, DocumentId("id:ns:foobar::things:stuff"))); + auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::things:stuff")); MapFieldValue mfv(doc->getType().getField("structmap").getDataType()); - DocumentUpdate docUp(*_repo, _foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); + DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); try { FieldPathUpdate::CP update1(new AssignFieldPathUpdate(*doc->getDataType(), "structmap{foo}", @@ -991,14 +996,14 @@ TEST_F(FieldPathUpdateTestCase, testIncompatibleDataTypeFails) TEST_F(FieldPathUpdateTestCase, testSerializeAssign) { - Document::UP doc(new Document(_foobar_type, DocumentId("id:ns:foobar::weloveto:serializestuff"))); + auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::weloveto:serializestuff")); MapFieldValue mfv(doc->getType().getField("structmap").getDataType()); StructFieldValue val(dynamic_cast<const MapDataType&>(*mfv.getDataType()).getValueType()); val.setValue("title", StringFieldValue("cool frog")); val.setValue("rating", IntFieldValue(100)); - DocumentUpdate docUp(*_repo, _foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); + DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); FieldPathUpdate::CP update1(new AssignFieldPathUpdate(*doc->getDataType(), "structmap{ribbit}", "true", val)); static_cast<AssignFieldPathUpdate&>(*update1).setCreateMissingPath(true); @@ -1009,7 +1014,7 @@ TEST_F(FieldPathUpdateTestCase, testSerializeAssign) TEST_F(FieldPathUpdateTestCase, testSerializeAdd) { - Document::UP doc(new Document(_foobar_type, DocumentId("id:ns:foobar::george:costanza"))); + auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::george:costanza")); EXPECT_TRUE(doc->hasValue("strarray") == false); ArrayFieldValue adds(doc->getType().getField("strarray").getDataType()); @@ -1017,7 +1022,7 @@ TEST_F(FieldPathUpdateTestCase, testSerializeAdd) adds.add(StringFieldValue("a festivus for the rest of us")); adds.add(StringFieldValue("george is getting upset!")); - DocumentUpdate docUp(*_repo, _foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); + DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); FieldPathUpdate::CP update1(new AddFieldPathUpdate(*doc->getDataType(), "strarray", std::string(), adds)); docUp.addFieldPathUpdate(update1); @@ -1027,10 +1032,10 @@ TEST_F(FieldPathUpdateTestCase, testSerializeAdd) TEST_F(FieldPathUpdateTestCase, testSerializeRemove) { - Document::UP doc(new Document(_foobar_type, DocumentId("id:ns:foobar::weloveto:serializestuff"))); + auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::weloveto:serializestuff")); MapFieldValue mfv(doc->getType().getField("structmap").getDataType()); - DocumentUpdate docUp(*_repo, _foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); + DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); FieldPathUpdate::CP update1(new RemoveFieldPathUpdate("structmap{ribbit}", std::string())); docUp.addFieldPathUpdate(update1); @@ -1040,11 +1045,11 @@ TEST_F(FieldPathUpdateTestCase, testSerializeRemove) TEST_F(FieldPathUpdateTestCase, testSerializeAssignMath) { - Document::UP doc(new Document(_foobar_type, DocumentId("id:ns:foobar::bat:man"))); + auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::bat:man")); EXPECT_TRUE(doc->hasValue("num") == false); doc->setValue("num", IntFieldValue(34)); - DocumentUpdate docUp(*_repo, _foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); + DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); docUp.addFieldPathUpdate(FieldPathUpdate::CP(new AssignFieldPathUpdate("num", "", "($value * 2) / $value"))); testSerialize(*_repo, docUp); } @@ -1112,7 +1117,7 @@ TEST_F(FieldPathUpdateTestCase, testGenerateSerializedFile) TEST_F(FieldPathUpdateTestCase, array_element_update_for_invalid_index_is_ignored) { - auto doc = std::make_unique<Document>(_foobar_type, DocumentId("id::foobar::1")); + auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id::foobar::1")); doc->setRepo(*_repo); auto& field = doc->getType().getField("strarray"); @@ -1120,7 +1125,7 @@ TEST_F(FieldPathUpdateTestCase, array_element_update_for_invalid_index_is_ignore str_array.add(StringFieldValue("jerry")); doc->setValue("strarray", str_array); - DocumentUpdate docUp(*_repo, _foobar_type, DocumentId("id::foobar::1")); + DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id::foobar::1")); docUp.addFieldPathUpdate(FieldPathUpdate::CP( new AssignFieldPathUpdate(*doc->getDataType(), "strarray[1]", "", StringFieldValue("george")))); docUp.applyTo(*doc); @@ -1132,7 +1137,7 @@ TEST_F(FieldPathUpdateTestCase, array_element_update_for_invalid_index_is_ignore TEST_F(FieldPathUpdateTestCase, update_can_have_removes_for_both_existent_and_nonexistent_keys) { DocumentId doc_id("id:ns:foobar::george:costanza"); - auto doc = std::make_unique<Document>(_foobar_type, doc_id); + auto doc = std::make_unique<Document>(*_foobar_type, doc_id); auto& map_type = dynamic_cast<const MapDataType&>(doc->getType().getField("structmap").getDataType()); auto& struct_type = map_type.getValueType(); MapFieldValue mfv(map_type); @@ -1143,7 +1148,7 @@ TEST_F(FieldPathUpdateTestCase, update_can_have_removes_for_both_existent_and_no mfv.put(StringFieldValue("coolmovie"), mystruct); doc->setValue("structmap", mfv); - DocumentUpdate update(*_repo, _foobar_type, doc_id); + DocumentUpdate update(*_repo, *_foobar_type, doc_id); auto update1 = std::make_unique<RemoveFieldPathUpdate>("structmap{coolmovie}", ""); auto update2 = std::make_unique<RemoveFieldPathUpdate>("structmap{no such key}", ""); update.addFieldPathUpdate(FieldPathUpdate::CP(std::move(update1))); diff --git a/document/src/tests/positiontypetest.cpp b/document/src/tests/positiontypetest.cpp index 36c35bf46a0..3c308563029 100644 --- a/document/src/tests/positiontypetest.cpp +++ b/document/src/tests/positiontypetest.cpp @@ -22,8 +22,7 @@ TEST(PositionTypeTest, requireThatExpectedFieldsAreThere) TEST(PositionTypeTest, requireThatZCurveFieldMatchesJava) { - EXPECT_EQ(vespalib::string("foo_zcurve"), - PositionDataType::getZCurveFieldName("foo")); + EXPECT_EQ(vespalib::string("foo_zcurve"), PositionDataType::getZCurveFieldName("foo")); EXPECT_TRUE( ! PositionDataType::isZCurveFieldName("foo")); EXPECT_TRUE( ! PositionDataType::isZCurveFieldName("_zcurve")); EXPECT_TRUE( PositionDataType::isZCurveFieldName("x_zcurve")); diff --git a/document/src/tests/repo/documenttyperepo_test.cpp b/document/src/tests/repo/documenttyperepo_test.cpp index 6619d53e609..8180accae00 100644 --- a/document/src/tests/repo/documenttyperepo_test.cpp +++ b/document/src/tests/repo/documenttyperepo_test.cpp @@ -147,8 +147,7 @@ TEST("requireThatAnnotationReferencesCanBeConfigured") { .annotationType(annotation_type_id, "foo", -1); DocumentTypeRepo repo(builder.config()); - const AnnotationReferenceDataType &ar = - getFieldDataType<AnnotationReferenceDataType>(repo); + const AnnotationReferenceDataType &ar = getFieldDataType<AnnotationReferenceDataType>(repo); EXPECT_EQUAL(annotation_type_id, ar.getAnnotationType().getId()); } diff --git a/document/src/tests/serialization/vespadocumentserializer_test.cpp b/document/src/tests/serialization/vespadocumentserializer_test.cpp index 58a5a539feb..d85d5240b64 100644 --- a/document/src/tests/serialization/vespadocumentserializer_test.cpp +++ b/document/src/tests/serialization/vespadocumentserializer_test.cpp @@ -4,7 +4,6 @@ #include <vespa/document/annotation/annotation.h> #include <vespa/document/annotation/span.h> #include <vespa/document/annotation/spantree.h> -#include <vespa/document/config/config-documenttypes.h> #include <vespa/document/config/documenttypes_config_fwd.h> #include <vespa/document/datatype/annotationreferencedatatype.h> #include <vespa/document/datatype/arraydatatype.h> @@ -651,7 +650,7 @@ TEST("requireThatReadDocumentTypeThrowsIfUnknownType") { stream.write(my_type.c_str(), my_type.size() + 1); stream << static_cast<uint16_t>(0); // version (unused) - DocumentType value; + DocumentType value("invalid"); VespaDocumentDeserializer deserializer(repo, stream, serialization_version); EXPECT_EXCEPTION(deserializer.read(value), DocumentTypeNotFoundException, "Document type " + my_type + " not found"); diff --git a/document/src/tests/weightedsetfieldvaluetest.cpp b/document/src/tests/weightedsetfieldvaluetest.cpp index 2c0429f8015..325267e9da6 100644 --- a/document/src/tests/weightedsetfieldvaluetest.cpp +++ b/document/src/tests/weightedsetfieldvaluetest.cpp @@ -1,10 +1,13 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/document/fieldvalue/fieldvalues.h> +#include <vespa/document/fieldvalue/weightedsetfieldvalue.h> +#include <vespa/document/fieldvalue/arrayfieldvalue.h> +#include <vespa/document/fieldvalue/longfieldvalue.h> +#include <vespa/document/fieldvalue/stringfieldvalue.h> +#include <vespa/document/fieldvalue/document.h> #include <vespa/document/datatype/weightedsetdatatype.h> #include <vespa/document/serialization/vespadocumentdeserializer.h> #include <vespa/vespalib/objects/nbostream.h> -#include <vespa/document/util/bytebuffer.h> #include <vespa/document/repo/documenttyperepo.h> #include <gtest/gtest.h> #include <gmock/gmock.h> diff --git a/document/src/vespa/document/base/field.h b/document/src/vespa/document/base/field.h index 6a2dadf8cd6..c80733dd5ff 100644 --- a/document/src/vespa/document/base/field.h +++ b/document/src/vespa/document/base/field.h @@ -98,12 +98,12 @@ public: const DataType &getDataType() const { return *_dataType; } int getId() const noexcept { return _fieldId; } - const vespalib::string & getName() const { return _name; } + const vespalib::string & getName() const noexcept { return _name; } vespalib::string toString(bool verbose=false) const; bool contains(const FieldSet& fields) const override; Type getType() const override { return Type::FIELD; } - bool valid() const { return _fieldId != 0; } + bool valid() const noexcept { return _fieldId != 0; } uint32_t hash() const noexcept { return getId(); } private: int calculateIdV7(); diff --git a/document/src/vespa/document/datatype/annotationreferencedatatype.cpp b/document/src/vespa/document/datatype/annotationreferencedatatype.cpp index 2827f1ef04d..b9060bd8c6c 100644 --- a/document/src/vespa/document/datatype/annotationreferencedatatype.cpp +++ b/document/src/vespa/document/datatype/annotationreferencedatatype.cpp @@ -10,8 +10,6 @@ using std::ostream; namespace document { -IMPLEMENT_IDENTIFIABLE(AnnotationReferenceDataType, DataType); - AnnotationReferenceDataType::AnnotationReferenceDataType( const AnnotationType &type, int id) : DataType("annotationreference<" + type.getName() + ">", id), diff --git a/document/src/vespa/document/datatype/annotationreferencedatatype.h b/document/src/vespa/document/datatype/annotationreferencedatatype.h index c50367a2dcb..271e22183d8 100644 --- a/document/src/vespa/document/datatype/annotationreferencedatatype.h +++ b/document/src/vespa/document/datatype/annotationreferencedatatype.h @@ -7,13 +7,12 @@ namespace document { -class AnnotationReferenceDataType : public DataType { +class AnnotationReferenceDataType final : public DataType { const AnnotationType *_type; public: typedef std::shared_ptr<AnnotationReferenceDataType> SP; - AnnotationReferenceDataType() {} AnnotationReferenceDataType(const AnnotationType &type, int id); const AnnotationType &getAnnotationType() const; @@ -21,8 +20,6 @@ public: AnnotationReferenceDataType *clone() const override; std::unique_ptr<FieldValue> createFieldValue() const override; void onBuildFieldPath(FieldPath & path, vespalib::stringref remainFieldName) const override; - - DECLARE_IDENTIFIABLE(AnnotationReferenceDataType); }; } // namespace document diff --git a/document/src/vespa/document/datatype/arraydatatype.cpp b/document/src/vespa/document/datatype/arraydatatype.cpp index 7aed584ad09..68c4e87ae5e 100644 --- a/document/src/vespa/document/datatype/arraydatatype.cpp +++ b/document/src/vespa/document/datatype/arraydatatype.cpp @@ -1,14 +1,12 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/document/datatype/arraydatatype.h> +#include "arraydatatype.h" #include <vespa/document/fieldvalue/arrayfieldvalue.h> #include <vespa/vespalib/util/exceptions.h> #include <ostream> namespace document { -IMPLEMENT_IDENTIFIABLE(ArrayDataType, CollectionDataType); - ArrayDataType::ArrayDataType(const DataType &nestedType, int32_t id) : CollectionDataType("Array<" + nestedType.getName() + ">", nestedType, id) { @@ -35,11 +33,10 @@ ArrayDataType::print(std::ostream& out, bool verbose, } bool -ArrayDataType::operator==(const DataType& other) const +ArrayDataType::equals(const DataType& other) const noexcept { if (this == &other) return true; - if (!CollectionDataType::operator==(other)) return false; - return other.isArray(); + return CollectionDataType::equals(other) && other.isArray(); } void diff --git a/document/src/vespa/document/datatype/arraydatatype.h b/document/src/vespa/document/datatype/arraydatatype.h index 3c0104eb393..74004885aeb 100644 --- a/document/src/vespa/document/datatype/arraydatatype.h +++ b/document/src/vespa/document/datatype/arraydatatype.h @@ -11,7 +11,7 @@ namespace document { -class ArrayDataType : public CollectionDataType { +class ArrayDataType final : public CollectionDataType { protected: // Protected to help you avoid calling the copy constructor when // you think you're calling the regular constructor with a nested @@ -19,20 +19,17 @@ protected: ArrayDataType(const ArrayDataType &o) : CollectionDataType(o) {} public: - ArrayDataType() {} explicit ArrayDataType(const DataType &nestedType); ArrayDataType(const DataType &nestedType, int32_t id); std::unique_ptr<FieldValue> createFieldValue() const override; void print(std::ostream&, bool verbose, const std::string& indent) const override; - bool operator==(const DataType& other) const override; + bool equals(const DataType& other) const noexcept override; ArrayDataType* clone() const override { return new ArrayDataType(*this); } ArrayDataType &operator=(const ArrayDataType &rhs) = default; void onBuildFieldPath(FieldPath & path, vespalib::stringref remainFieldName) const override; - bool isArray() const override { return true; } - - DECLARE_IDENTIFIABLE(ArrayDataType); + bool isArray() const noexcept override { return true; } }; } // document diff --git a/document/src/vespa/document/datatype/collectiondatatype.cpp b/document/src/vespa/document/datatype/collectiondatatype.cpp index 886d44dbb9c..e7655b953be 100644 --- a/document/src/vespa/document/datatype/collectiondatatype.cpp +++ b/document/src/vespa/document/datatype/collectiondatatype.cpp @@ -1,17 +1,13 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "collectiondatatype.h" -#include <vespa/document/util/stringutil.h> namespace document { -IMPLEMENT_IDENTIFIABLE_ABSTRACT(CollectionDataType, DataType); - -CollectionDataType::CollectionDataType(const CollectionDataType& other) +CollectionDataType::CollectionDataType(const CollectionDataType& other) noexcept : DataType(other), _nestedType(other._nestedType) -{ -} +{ } CollectionDataType& CollectionDataType::operator=(const CollectionDataType& other) @@ -24,26 +20,26 @@ CollectionDataType::operator=(const CollectionDataType& other) } CollectionDataType::CollectionDataType(vespalib::stringref name, - const DataType& nestedType) + const DataType& nestedType) noexcept : DataType(name), - _nestedType(&nestedType) { -} + _nestedType(&nestedType) +{ } CollectionDataType::CollectionDataType(vespalib::stringref name, const DataType& nestedType, - int32_t id) + int32_t id) noexcept : DataType(name, id), - _nestedType(&nestedType) { -} + _nestedType(&nestedType) +{ } CollectionDataType::~CollectionDataType() = default; bool -CollectionDataType::operator==(const DataType& other) const +CollectionDataType::equals(const DataType& other) const noexcept { - if (!DataType::operator==(other)) return false; + if (!DataType::equals(other)) return false; const CollectionDataType * o = other.cast_collection(); - return o && *_nestedType == *o->_nestedType; + return o && _nestedType->equals(*o->_nestedType); } } // document diff --git a/document/src/vespa/document/datatype/collectiondatatype.h b/document/src/vespa/document/datatype/collectiondatatype.h index 2d1277cc747..aa07736bc56 100644 --- a/document/src/vespa/document/datatype/collectiondatatype.h +++ b/document/src/vespa/document/datatype/collectiondatatype.h @@ -17,22 +17,17 @@ class CollectionDataType : public DataType { const DataType *_nestedType; protected: - CollectionDataType() : _nestedType(0) {} - CollectionDataType(const CollectionDataType&); + CollectionDataType(const CollectionDataType&) noexcept; CollectionDataType& operator=(const CollectionDataType&); - CollectionDataType(vespalib::stringref name, - const DataType &nestedType); - CollectionDataType(vespalib::stringref name, - const DataType &nestedType, int32_t id); + CollectionDataType(vespalib::stringref name, const DataType &nestedType) noexcept; + CollectionDataType(vespalib::stringref name, const DataType &nestedType, int32_t id) noexcept; public: ~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); + bool equals(const DataType&) const noexcept override; + const DataType &getNestedType() const noexcept { return *_nestedType; } + const CollectionDataType * cast_collection() const noexcept override { return this; } }; } // document diff --git a/document/src/vespa/document/datatype/datatype.cpp b/document/src/vespa/document/datatype/datatype.cpp index 874306f08ab..87464a197ee 100644 --- a/document/src/vespa/document/datatype/datatype.cpp +++ b/document/src/vespa/document/datatype/datatype.cpp @@ -1,19 +1,16 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/document/datatype/datatype.h> -#include <vespa/document/datatype/numericdatatype.h> -#include <vespa/document/datatype/primitivedatatype.h> -#include <vespa/document/datatype/documenttype.h> -#include <vespa/document/datatype/weightedsetdatatype.h> +#include "datatype.h" +#include "numericdatatype.h" +#include "primitivedatatype.h" +#include "documenttype.h" +#include "weightedsetdatatype.h" #include <vespa/document/fieldvalue/fieldvalues.h> #include <vespa/document/base/exceptions.h> #include <vespa/vespalib/text/lowercase.h> -#include <stdexcept> namespace document { -IMPLEMENT_IDENTIFIABLE_ABSTRACT(DataType, vespalib::Identifiable); - namespace { NumericDataType BYTE_OBJ(DataType::T_BYTE); NumericDataType SHORT_OBJ(DataType::T_SHORT); @@ -122,7 +119,8 @@ namespace { // ASCII characters. Probably screwed up otherwise, but generated ids // should only be used in testing anyways. In production this will be // set from the document manager config. -uint32_t crappyJavaStringHash(vespalib::stringref value) { +uint32_t +crappyJavaStringHash(vespalib::stringref value) { uint32_t h = 0; for (uint32_t i = 0; i < value.size(); ++i) { h = 31 * h + value[i]; @@ -140,39 +138,19 @@ int32_t createId(vespalib::stringref name) } // anon namespace -DataType::DataType() - : _dataTypeId(-1), - _name("invalid") -{ -} - -DataType::DataType(vespalib::stringref name, int dataTypeId) +DataType::DataType(vespalib::stringref name, int dataTypeId) noexcept : _dataTypeId(dataTypeId), _name(name) { } -DataType::DataType(vespalib::stringref name) - : _dataTypeId(createId(name)), - _name(name) +DataType::DataType(vespalib::stringref name) noexcept + : DataType(name, createId(name)) { } DataType::~DataType() = default; -bool -DataType::operator==(const DataType& other) const -{ - return _dataTypeId == other._dataTypeId; -} - -bool -DataType::operator<(const DataType& other) const -{ - if (this == &other) return false; - return (_dataTypeId < other._dataTypeId); -} - void DataType::buildFieldPath(FieldPath & path, vespalib::stringref remainFieldName) const { diff --git a/document/src/vespa/document/datatype/datatype.h b/document/src/vespa/document/datatype/datatype.h index c32aec6b9b1..d1331ef0f7e 100644 --- a/document/src/vespa/document/datatype/datatype.h +++ b/document/src/vespa/document/datatype/datatype.h @@ -7,10 +7,10 @@ */ #pragma once -#include <vespa/vespalib/objects/identifiable.h> - -#include <vespa/document/util/identifiableid.h> #include <vespa/document/util/printable.h> +#include <vespa/vespalib/stllike/string.h> +#include <memory> +#include <vector> namespace document { @@ -27,26 +27,24 @@ class ArrayDataType; class MapDataType; class ReferenceDataType; -class DataType : public Printable, - public vespalib::Identifiable +class DataType : public Printable { int _dataTypeId; vespalib::string _name; protected: - DataType(); /** * Creates a datatype. Note that datatypes must be configured to work with * the entire system, you can't just create them on the fly and expect * everyone to be able to use them. Only tests and the type manager reading * config should need to create datatypes. */ - DataType(vespalib::stringref name, int dataTypeId); + DataType(vespalib::stringref name, int dataTypeId) noexcept; /** * Creates a datatype using the hash of name as the id. */ - explicit DataType(vespalib::stringref name); + explicit DataType(vespalib::stringref name) noexcept; public: ~DataType() override; @@ -103,8 +101,8 @@ 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; } + const vespalib::string& getName() const noexcept { return _name; } + int getId() const noexcept { return _dataTypeId; } bool isValueType(const FieldValue & fv) const; /** @@ -113,23 +111,38 @@ 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; } + virtual bool isWeightedSet() const noexcept { return false; } + virtual bool isArray() const noexcept { return false; } + virtual bool isDocument() const noexcept { return false; } + virtual bool isTensor() const noexcept { return false; } + virtual bool isPrimitive() const noexcept { return false; } + virtual bool isNumeric() const noexcept { return false; } + virtual bool isStructured() const noexcept { return false; } + virtual const CollectionDataType * cast_collection() const noexcept { return nullptr; } + virtual const MapDataType * cast_map() const noexcept { return nullptr; } + virtual const ReferenceDataType * cast_reference() const noexcept { 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 * to match. */ - virtual bool isA(const DataType& other) const { return (*this == other); } - - virtual bool operator==(const DataType&) const; - virtual bool operator<(const DataType&) const; - bool operator != (const DataType & rhs) const { return !(*this == rhs); } + virtual bool isA(const DataType& other) const { return equals(other); } + + virtual bool equals(const DataType & other) const noexcept { + return _dataTypeId == other._dataTypeId; + } + + bool operator == (const DataType & other) const noexcept { + return equals(other); + } + int cmpId(const DataType& b) const { + return (_dataTypeId < b._dataTypeId) + ? -1 + : (b._dataTypeId < _dataTypeId) + ? 1 + : 0; + } /** * This takes a . separated fieldname and gives you back the path of @@ -142,8 +155,6 @@ public: /** @throws FieldNotFoundException if field does not exist. */ virtual const Field& getField(int fieldId) const; - - DECLARE_IDENTIFIABLE_ABSTRACT(DataType); private: virtual void onBuildFieldPath(FieldPath & fieldPath, vespalib::stringref remainFieldName) const = 0; }; diff --git a/document/src/vespa/document/datatype/documenttype.cpp b/document/src/vespa/document/datatype/documenttype.cpp index 1c43e2dfc64..18db872c029 100644 --- a/document/src/vespa/document/datatype/documenttype.cpp +++ b/document/src/vespa/document/datatype/documenttype.cpp @@ -1,12 +1,10 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/document/datatype/documenttype.h> +#include "documenttype.h" #include <vespa/document/fieldvalue/document.h> #include <vespa/vespalib/util/exceptions.h> #include <vespa/vespalib/util/stringfmt.h> -#include <iomanip> #include <vespa/log/log.h> -#include <vespa/document/base/exceptions.h> LOG_SETUP(".document.datatype.document"); @@ -38,10 +36,6 @@ DocumentType::FieldSet::FieldSet(const vespalib::string & name, Fields fields, _field_collection(build_field_collection(fields, doc_type)) {} -IMPLEMENT_IDENTIFIABLE(DocumentType, StructuredDataType); - -DocumentType::DocumentType() = default; - DocumentType::DocumentType(stringref name, int32_t id) : StructuredDataType(name, id), _inheritedTypes(), @@ -137,7 +131,7 @@ DocumentType::inherit(const DocumentType &docType) { if (isA(docType)) { // If we already directly inherits it, complain for (const auto* inherited : _inheritedTypes) { - if (*inherited == docType) { + if (inherited->equals(docType)) { throw IllegalArgumentException( "DocumentType " + getName() + " already inherits " "document type " + docType.getName(), VESPA_STRLOC); @@ -160,7 +154,7 @@ DocumentType::inherit(const DocumentType &docType) { } // If we inherit default document type Document.0, remove that if adding // another parent, as that has to also inherit Document - if ((_inheritedTypes.size() == 1) && (*_inheritedTypes[0] == *DataType::DOCUMENT)) { + if ((_inheritedTypes.size() == 1) && _inheritedTypes[0]->equals(*DataType::DOCUMENT)) { _inheritedTypes.clear(); } _inheritedTypes.push_back(&docType); @@ -172,7 +166,7 @@ DocumentType::isA(const DataType& other) const for (const DocumentType * docType : _inheritedTypes) { if (docType->isA(other)) return true; } - return (*this == other); + return equals(other); } FieldValue::UP @@ -206,18 +200,18 @@ DocumentType::print(std::ostream& out, bool verbose, const std::string& indent) } bool -DocumentType::operator==(const DataType& other) const +DocumentType::equals(const DataType& other) const noexcept { if (&other == this) return true; - if (!DataType::operator==(other)) return false; + if ( ! DataType::equals(other)) return false; const auto* o(dynamic_cast<const DocumentType*>(&other)); if (o == nullptr) return false; - if (*_fields != *o->_fields) return false; + if ( ! _fields->equals(*o->_fields)) return false; if (_inheritedTypes.size() != o->_inheritedTypes.size()) return false; auto it1 = _inheritedTypes.begin(); auto it2 = o->_inheritedTypes.begin(); while (it1 != _inheritedTypes.end()) { - if (**it1 != **it2) return false; + if ( ! (*it1)->equals( **it2)) return false; ++it1; ++it2; } @@ -237,14 +231,6 @@ DocumentType::getField(int fieldId) const return _fields->getField(fieldId); } -bool DocumentType::hasField(stringref name) const { - return _fields->hasField(name); -} - -bool DocumentType::hasField(int fieldId) const { - return _fields->hasField(fieldId); -} - Field::Set DocumentType::getFieldSet() const { diff --git a/document/src/vespa/document/datatype/documenttype.h b/document/src/vespa/document/datatype/documenttype.h index 4b6fe74cc3f..d63a01b6001 100644 --- a/document/src/vespa/document/datatype/documenttype.h +++ b/document/src/vespa/document/datatype/documenttype.h @@ -11,11 +11,9 @@ #pragma once +#include "structdatatype.h" #include <vespa/document/fieldset/fieldsets.h> -#include <vespa/document/datatype/structdatatype.h> #include <vespa/vespalib/stllike/hash_set.h> -#include <vespa/vespalib/stllike/string.h> -#include <vector> #include <map> #include <set> @@ -24,7 +22,7 @@ namespace document { class Field; class DocumentType; -class DocumentType : public StructuredDataType { +class DocumentType final : public StructuredDataType { public: class FieldSet { public: @@ -45,6 +43,7 @@ public: Fields _fields; FieldCollection _field_collection; }; +private: using FieldSetMap = std::map<vespalib::string, FieldSet>; using ImportedFieldNames = vespalib::hash_set<vespalib::string>; @@ -58,7 +57,6 @@ public: using UP = std::unique_ptr<DocumentType>; using SP = std::shared_ptr<DocumentType>; - DocumentType(); DocumentType(vespalib::stringref name, int32_t id); DocumentType(vespalib::stringref name, int32_t id, const StructDataType& fields); @@ -79,21 +77,25 @@ public: void inherit(const DocumentType &docType); bool isA(const DataType& other) const override; + virtual bool isDocument() const noexcept override { return true; } const std::vector<const DocumentType *> & getInheritedTypes() const { return _inheritedTypes; }; // Implementation of StructuredDataType std::unique_ptr<FieldValue> createFieldValue() const override; void print(std::ostream&, bool verbose, const std::string& indent) const override; - bool operator==(const DataType& type) const override; - bool operator==(const DocumentType& type) const { return operator==(static_cast<const DataType&>(type)); } - uint32_t getFieldCount() const override { + bool equals(const DataType& type) const noexcept override; + uint32_t getFieldCount() const noexcept override { return _fields->getFieldCount(); } const Field & getField(vespalib::stringref name) const override; const Field & getField(int fieldId) const override; - bool hasField(vespalib::stringref name) const override; - bool hasField(int fieldId) const override; + bool hasField(vespalib::stringref name) const noexcept override { + return _fields->hasField(name); + } + bool hasField(int fieldId) const noexcept override { + return _fields->hasField(fieldId); + } Field::Set getFieldSet() const override; DocumentType* clone() const override; @@ -107,8 +109,6 @@ public: bool has_imported_field_name(const vespalib::string& name) const noexcept; // Ideally the type would be immutable, but this is how it's built today. void add_imported_field_name(const vespalib::string& name); - - DECLARE_IDENTIFIABLE(DocumentType); }; } // document diff --git a/document/src/vespa/document/datatype/mapdatatype.cpp b/document/src/vespa/document/datatype/mapdatatype.cpp index 74cb732fb5c..616bd91b625 100644 --- a/document/src/vespa/document/datatype/mapdatatype.cpp +++ b/document/src/vespa/document/datatype/mapdatatype.cpp @@ -7,8 +7,6 @@ namespace document { -IMPLEMENT_IDENTIFIABLE(MapDataType, DataType); - namespace { vespalib::string createName(const DataType& keyType, const DataType& valueType) { @@ -18,20 +16,20 @@ vespalib::string createName(const DataType& keyType, const DataType& valueType) } } // namespace -MapDataType::MapDataType(const DataType &key, const DataType &value) +MapDataType::MapDataType(const DataType &key, const DataType &value) noexcept : DataType(createName(key, value)), _keyType(&key), _valueType(&value) { } -MapDataType::MapDataType(const DataType &key, const DataType &value, int id) +MapDataType::MapDataType(const DataType &key, const DataType &value, int id) noexcept : DataType(createName(key, value), id), _keyType(&key), _valueType(&value) { } FieldValue::UP MapDataType::createFieldValue() const { - return FieldValue::UP(new MapFieldValue(*this)); + return std::make_unique<MapFieldValue>(*this); } void @@ -46,12 +44,12 @@ MapDataType::print(std::ostream& out, bool verbose, } bool -MapDataType::operator==(const DataType& other) const +MapDataType::equals(const DataType& other) const noexcept { if (this == &other) return true; - if (!DataType::operator==(other)) return false; + if (!DataType::equals(other)) return false; const MapDataType * w = other.cast_map(); - return w && (*_keyType == *w->_keyType) && (*_valueType == *w->_valueType); + return w && _keyType->equals(*w->_keyType) && _valueType->equals(*w->_valueType); } void diff --git a/document/src/vespa/document/datatype/mapdatatype.h b/document/src/vespa/document/datatype/mapdatatype.h index 70800d36722..bd4b40fa569 100644 --- a/document/src/vespa/document/datatype/mapdatatype.h +++ b/document/src/vespa/document/datatype/mapdatatype.h @@ -11,30 +11,27 @@ namespace document { -class MapDataType : public DataType { +class MapDataType final : public DataType { const DataType *_keyType; const DataType *_valueType; public: - MapDataType() : _keyType(0), _valueType(0) {} - MapDataType(const DataType &keyType, const DataType &valueType); - MapDataType(const DataType &keyType, const DataType &valueType, int id); + MapDataType(const DataType &keyType, const DataType &valueType) noexcept; + MapDataType(const DataType &keyType, const DataType &valueType, int id) noexcept; - const DataType& getKeyType() const { return *_keyType; } - const DataType& getValueType() const { return *_valueType; } + const DataType& getKeyType() const noexcept { return *_keyType; } + const DataType& getValueType() const noexcept { return *_valueType; } std::unique_ptr<FieldValue> createFieldValue() const override; void print(std::ostream&, bool verbose, const std::string& indent) const override; - bool operator==(const DataType& other) const override; + bool equals(const DataType& other) const noexcept override; MapDataType* clone() const override { return new MapDataType(*this); } - const MapDataType * cast_map() const override { return this; } + const MapDataType * cast_map() const noexcept override { return this; } void onBuildFieldPath(FieldPath & path, vespalib::stringref remainFieldName) const override; static void buildFieldPathImpl(FieldPath & path, const DataType& dataType, vespalib::stringref remainFieldName, const DataType &keyType, const DataType &valueType); - - DECLARE_IDENTIFIABLE(MapDataType); }; } // document diff --git a/document/src/vespa/document/datatype/numericdatatype.cpp b/document/src/vespa/document/datatype/numericdatatype.cpp index af1c5b9341f..9c033f239f7 100644 --- a/document/src/vespa/document/datatype/numericdatatype.cpp +++ b/document/src/vespa/document/datatype/numericdatatype.cpp @@ -5,8 +5,6 @@ namespace document { -IMPLEMENT_IDENTIFIABLE_ABSTRACT(NumericDataType, PrimitiveDataType); - NumericDataType::NumericDataType(Type type) : PrimitiveDataType(type) { diff --git a/document/src/vespa/document/datatype/numericdatatype.h b/document/src/vespa/document/datatype/numericdatatype.h index e5f87af584a..e8688398d5f 100644 --- a/document/src/vespa/document/datatype/numericdatatype.h +++ b/document/src/vespa/document/datatype/numericdatatype.h @@ -21,9 +21,7 @@ public: 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); + bool isNumeric() const noexcept override { return true; } }; } diff --git a/document/src/vespa/document/datatype/primitivedatatype.cpp b/document/src/vespa/document/datatype/primitivedatatype.cpp index d45bc4731f1..08e873c7de2 100644 --- a/document/src/vespa/document/datatype/primitivedatatype.cpp +++ b/document/src/vespa/document/datatype/primitivedatatype.cpp @@ -11,8 +11,6 @@ LOG_SETUP(".document.datatype.primitivedatatype"); namespace document { -IMPLEMENT_IDENTIFIABLE_ABSTRACT(PrimitiveDataType, DataType); - namespace { const char *Int = "Int"; const char *Short = "Short"; diff --git a/document/src/vespa/document/datatype/primitivedatatype.h b/document/src/vespa/document/datatype/primitivedatatype.h index 2f990c1a273..2d87a48a585 100644 --- a/document/src/vespa/document/datatype/primitivedatatype.h +++ b/document/src/vespa/document/datatype/primitivedatatype.h @@ -28,9 +28,7 @@ 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); + bool isPrimitive() const noexcept override { return true; } }; } diff --git a/document/src/vespa/document/datatype/referencedatatype.cpp b/document/src/vespa/document/datatype/referencedatatype.cpp index 0f873aa3973..062f07f0ad0 100644 --- a/document/src/vespa/document/datatype/referencedatatype.cpp +++ b/document/src/vespa/document/datatype/referencedatatype.cpp @@ -11,7 +11,7 @@ using vespalib::IllegalArgumentException; namespace document { ReferenceDataType::ReferenceDataType(const DocumentType& targetDocType, int id) - : DataType(vespalib::make_string("Reference<%s>", targetDocType.getName().c_str()), id), + : DataType(make_string("Reference<%s>", targetDocType.getName().c_str()), id), _targetDocType(targetDocType) { } @@ -40,10 +40,9 @@ void ReferenceDataType::onBuildFieldPath(FieldPath &, vespalib::stringref remain } -bool ReferenceDataType::operator==(const DataType &rhs) const { +bool ReferenceDataType::equals(const DataType &rhs) const noexcept { const ReferenceDataType *rt = rhs.cast_reference(); - return rt && DataType::operator==(rhs) - && (_targetDocType == rt->_targetDocType); + return rt && DataType::equals(rhs) && _targetDocType.equals(rt->_targetDocType); } } // document diff --git a/document/src/vespa/document/datatype/referencedatatype.h b/document/src/vespa/document/datatype/referencedatatype.h index 960c6feb435..966f1c7f827 100644 --- a/document/src/vespa/document/datatype/referencedatatype.h +++ b/document/src/vespa/document/datatype/referencedatatype.h @@ -10,7 +10,7 @@ namespace document { * A ReferenceDataType specifies a particular concrete document type that a * ReferenceFieldValue instance binds to. */ -class ReferenceDataType : public DataType { +class ReferenceDataType final : public DataType { const DocumentType& _targetDocType; public: ReferenceDataType(const DocumentType& targetDocType, int id); @@ -25,9 +25,8 @@ 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)); } + const ReferenceDataType * cast_reference() const noexcept override { return this; } + bool equals(const DataType &type) const noexcept override; }; } // document diff --git a/document/src/vespa/document/datatype/structdatatype.cpp b/document/src/vespa/document/datatype/structdatatype.cpp index e4b39099d08..57167fb5d75 100644 --- a/document/src/vespa/document/datatype/structdatatype.cpp +++ b/document/src/vespa/document/datatype/structdatatype.cpp @@ -6,7 +6,6 @@ #include <vespa/document/fieldvalue/document.h> #include <vespa/vespalib/util/stringfmt.h> #include <vespa/vespalib/stllike/hash_map.hpp> -#include <iomanip> #include <cassert> #include <vespa/log/log.h> @@ -17,14 +16,6 @@ namespace document { using vespalib::make_string; using vespalib::IllegalArgumentException; -IMPLEMENT_IDENTIFIABLE(StructDataType, StructuredDataType); - -StructDataType::StructDataType() : - StructuredDataType(), - _nameFieldMap(), - _idFieldMap() -{ } - StructDataType::StructDataType(vespalib::stringref name) : StructuredDataType(name), _nameFieldMap(), @@ -145,11 +136,13 @@ StructDataType::getField(int32_t fieldId) const return *it->second; } -bool StructDataType::hasField(vespalib::stringref name) const { +bool +StructDataType::hasField(vespalib::stringref name) const noexcept { return _nameFieldMap.find(name) != _nameFieldMap.end(); } -bool StructDataType::hasField(int32_t fieldId) const { +bool +StructDataType::hasField(int32_t fieldId) const noexcept { return _idFieldMap.find(fieldId) != _idFieldMap.end(); } diff --git a/document/src/vespa/document/datatype/structdatatype.h b/document/src/vespa/document/datatype/structdatatype.h index ace9edfb0ab..b6f4c842422 100644 --- a/document/src/vespa/document/datatype/structdatatype.h +++ b/document/src/vespa/document/datatype/structdatatype.h @@ -9,9 +9,8 @@ */ #pragma once -#include <vespa/document/datatype/structureddatatype.h> +#include "structureddatatype.h" #include <vespa/vespalib/stllike/hash_map.h> -#include <memory> namespace document { @@ -20,7 +19,6 @@ public: using UP = std::unique_ptr<StructDataType>; using SP = std::shared_ptr<StructDataType>; - StructDataType(); StructDataType(vespalib::stringref name); StructDataType(vespalib::stringref name, int32_t id); ~StructDataType(); @@ -44,7 +42,7 @@ public: // Implementation of StructuredDataType std::unique_ptr<FieldValue> createFieldValue() const override; void print(std::ostream&, bool verbose, const std::string& indent) const override; - uint32_t getFieldCount() const override { return _idFieldMap.size(); } + uint32_t getFieldCount() const noexcept override { return _idFieldMap.size(); } const Field& getField(vespalib::stringref name) const override; @@ -54,17 +52,14 @@ public: */ const Field& getField(int32_t fieldId) const override; - bool hasField(vespalib::stringref name) const override; - bool hasField(int32_t fieldId) const override; - bool hasField(const Field& f) const { + bool hasField(vespalib::stringref name) const noexcept override; + bool hasField(int32_t fieldId) const noexcept override; + bool hasField(const Field& f) const noexcept { return hasField(f.getId()); } Field::Set getFieldSet() const override; StructDataType* clone() const override; - - DECLARE_IDENTIFIABLE(StructDataType); - private: using StringFieldMap = vespalib::hash_map<vespalib::string, Field::SP>; using IntFieldMap = vespalib::hash_map<int32_t, Field::SP>; diff --git a/document/src/vespa/document/datatype/structureddatatype.cpp b/document/src/vespa/document/datatype/structureddatatype.cpp index 4e2ab5bba45..fa5140efc8f 100644 --- a/document/src/vespa/document/datatype/structureddatatype.cpp +++ b/document/src/vespa/document/datatype/structureddatatype.cpp @@ -9,10 +9,6 @@ using vespalib::make_string; namespace document { -IMPLEMENT_IDENTIFIABLE_ABSTRACT(StructuredDataType, DataType); - -StructuredDataType::StructuredDataType() = default; - StructuredDataType::StructuredDataType(vespalib::stringref name) : DataType(name, createId(name)) { @@ -23,10 +19,8 @@ StructuredDataType::StructuredDataType(vespalib::stringref name, int dataTypeId) { } -bool StructuredDataType::operator==(const DataType& type) const -{ - if (!DataType::operator==(type)) return false; - return (dynamic_cast<const StructuredDataType*>(&type) != 0); +bool StructuredDataType::equals(const DataType &other) const noexcept { + return DataType::equals(other) && other.isStructured(); } namespace { diff --git a/document/src/vespa/document/datatype/structureddatatype.h b/document/src/vespa/document/datatype/structureddatatype.h index 2224881b7e6..7f98ed12b4a 100644 --- a/document/src/vespa/document/datatype/structureddatatype.h +++ b/document/src/vespa/document/datatype/structureddatatype.h @@ -19,30 +19,25 @@ class StructuredDataType : public DataType { void onBuildFieldPath(FieldPath & path, vespalib::stringref remainFieldName) const override; protected: - StructuredDataType(); StructuredDataType(vespalib::stringref name); StructuredDataType(vespalib::stringref name, int32_t dataTypeId); - public: - virtual uint32_t getFieldCount() const = 0; + virtual uint32_t getFieldCount() const noexcept = 0; /** @throws FieldNotFoundException if field does not exist. */ virtual const Field& getField(vespalib::stringref name) const = 0; - virtual bool hasField(vespalib::stringref name) const = 0; - virtual bool hasField(int32_t fieldId) const = 0; + virtual bool hasField(vespalib::stringref name) const noexcept = 0; + virtual bool hasField(int32_t fieldId) const noexcept = 0; virtual Field::Set getFieldSet() const = 0; virtual StructuredDataType* clone() const override = 0; - bool operator==(const DataType& type) const override; - bool operator==(const StructuredDataType& type) const { return operator==(static_cast<const DataType&>(type)); } + bool isStructured() const noexcept override { return true; } + bool equals(const DataType& type) const noexcept override; static int32_t createId(vespalib::stringref name); - - DECLARE_IDENTIFIABLE_ABSTRACT(StructuredDataType); - }; } diff --git a/document/src/vespa/document/datatype/tensor_data_type.cpp b/document/src/vespa/document/datatype/tensor_data_type.cpp index 2b640dd90ce..9d5d2bb58b9 100644 --- a/document/src/vespa/document/datatype/tensor_data_type.cpp +++ b/document/src/vespa/document/datatype/tensor_data_type.cpp @@ -9,8 +9,6 @@ using vespalib::eval::ValueType; namespace document { -IMPLEMENT_IDENTIFIABLE_ABSTRACT(TensorDataType, DataType); - TensorDataType::TensorDataType() : TensorDataType(ValueType::error_type()) { diff --git a/document/src/vespa/document/datatype/tensor_data_type.h b/document/src/vespa/document/datatype/tensor_data_type.h index 5fc6aa88b17..aa52af32b54 100644 --- a/document/src/vespa/document/datatype/tensor_data_type.h +++ b/document/src/vespa/document/datatype/tensor_data_type.h @@ -9,20 +9,18 @@ namespace document { /* * This class describes a tensor type. */ -class TensorDataType : public PrimitiveDataType { +class TensorDataType final : public PrimitiveDataType { vespalib::eval::ValueType _tensorType; public: TensorDataType(); TensorDataType(vespalib::eval::ValueType tensorType); ~TensorDataType(); + bool isTensor() const noexcept override { return true; } std::unique_ptr<FieldValue> createFieldValue() const override; TensorDataType* clone() const override; void print(std::ostream&, bool verbose, const std::string& indent) const override; static std::unique_ptr<const TensorDataType> fromSpec(const vespalib::string &spec); - - DECLARE_IDENTIFIABLE_ABSTRACT(TensorDataType); - const vespalib::eval::ValueType &getTensorType() const { return _tensorType; } bool isAssignableType(const vespalib::eval::ValueType &tensorType) const; static bool isAssignableType(const vespalib::eval::ValueType &fieldTensorType, const vespalib::eval::ValueType &tensorType); diff --git a/document/src/vespa/document/datatype/weightedsetdatatype.cpp b/document/src/vespa/document/datatype/weightedsetdatatype.cpp index 82cca2dfac4..67c32f861b7 100644 --- a/document/src/vespa/document/datatype/weightedsetdatatype.cpp +++ b/document/src/vespa/document/datatype/weightedsetdatatype.cpp @@ -8,28 +8,28 @@ namespace document { -IMPLEMENT_IDENTIFIABLE(WeightedSetDataType, CollectionDataType); - namespace { - vespalib::string createName(const DataType& nestedType, bool create, bool remove) - { - if (nestedType.getId() == DataType::T_STRING && create && remove) { - return "Tag"; - } - vespalib::asciistream ost; - ost << "WeightedSet<" << nestedType.getName() << ">"; - if (create) { - ost << ";Add"; - } - if (remove) { - ost << ";Remove"; - } - return ost.str(); + +vespalib::string +createName(const DataType& nestedType, bool create, bool remove) +{ + if (nestedType.getId() == DataType::T_STRING && create && remove) { + return "Tag"; + } + vespalib::asciistream ost; + ost << "WeightedSet<" << nestedType.getName() << ">"; + if (create) { + ost << ";Add"; + } + if (remove) { + ost << ";Remove"; } + return ost.str(); } -WeightedSetDataType::WeightedSetDataType( - const DataType& nested, bool createIfNon, bool remove) +} + +WeightedSetDataType::WeightedSetDataType(const DataType& nested, bool createIfNon, bool remove) : CollectionDataType(createName(nested, createIfNon, remove), nested), _createIfNonExistent(createIfNon), _removeIfZero(remove) @@ -47,15 +47,14 @@ WeightedSetDataType::WeightedSetDataType( FieldValue::UP WeightedSetDataType::createFieldValue() const { - return FieldValue::UP(new WeightedSetFieldValue(*this)); + return std::make_unique<WeightedSetFieldValue>(*this); } void -WeightedSetDataType::print(std::ostream& out, bool verbose, - const std::string& indent) const +WeightedSetDataType::print(std::ostream& out, bool verbose, const std::string& indent) const { - if (getNestedType() == *DataType::STRING && + if (getNestedType().equals(*DataType::STRING) && _createIfNonExistent && _removeIfZero) { out << "Tag()"; @@ -73,13 +72,12 @@ WeightedSetDataType::print(std::ostream& out, bool verbose, } bool -WeightedSetDataType::operator==(const DataType& other) const +WeightedSetDataType::equals(const DataType& other) const noexcept { if (this == &other) return true; - if (!CollectionDataType::operator==(other)) return false; - const WeightedSetDataType* w(dynamic_cast<const WeightedSetDataType*>(&other)); - return (w != 0 && _createIfNonExistent == w->_createIfNonExistent - && _removeIfZero == w->_removeIfZero); + if ( ! CollectionDataType::equals(other) || !other.isWeightedSet()) return false; + const WeightedSetDataType & w(static_cast<const WeightedSetDataType &>(other)); + return (_createIfNonExistent == w._createIfNonExistent) && (_removeIfZero == w._removeIfZero); } void diff --git a/document/src/vespa/document/datatype/weightedsetdatatype.h b/document/src/vespa/document/datatype/weightedsetdatatype.h index 5ac47125eab..53aa526a6a8 100644 --- a/document/src/vespa/document/datatype/weightedsetdatatype.h +++ b/document/src/vespa/document/datatype/weightedsetdatatype.h @@ -15,12 +15,11 @@ namespace document { -class WeightedSetDataType : public CollectionDataType { +class WeightedSetDataType final : public CollectionDataType { bool _createIfNonExistent; bool _removeIfZero; public: - WeightedSetDataType() {} WeightedSetDataType(const DataType& nestedType, bool createIfNonExistent, bool removeIfZero); WeightedSetDataType(const DataType& nestedType, bool createIfNonExistent, bool removeIfZero, int id); @@ -36,13 +35,13 @@ public: */ bool removeIfZero() const { return _removeIfZero; }; + bool isWeightedSet() const noexcept override { return true; } + std::unique_ptr<FieldValue> createFieldValue() const override; void print(std::ostream&, bool verbose, const std::string& indent) const override; - bool operator==(const DataType& other) const override; + bool equals(const DataType& other) const noexcept override; WeightedSetDataType* clone() const override { return new WeightedSetDataType(*this); } void onBuildFieldPath(FieldPath & path, vespalib::stringref remainFieldName) const override; - - DECLARE_IDENTIFIABLE(WeightedSetDataType); }; } // document diff --git a/document/src/vespa/document/fieldvalue/annotationreferencefieldvalue.cpp b/document/src/vespa/document/fieldvalue/annotationreferencefieldvalue.cpp index e35d26d0575..e26f0f15759 100644 --- a/document/src/vespa/document/fieldvalue/annotationreferencefieldvalue.cpp +++ b/document/src/vespa/document/fieldvalue/annotationreferencefieldvalue.cpp @@ -16,9 +16,8 @@ AnnotationReferenceFieldValue::AnnotationReferenceFieldValue( } int AnnotationReferenceFieldValue::compare(const FieldValue &other) const { - if (*getDataType() == *other.getDataType()) { - const AnnotationReferenceFieldValue &val( - static_cast<const AnnotationReferenceFieldValue &>(other)); + if (getDataType()->equals(*other.getDataType())) { + const AnnotationReferenceFieldValue &val(static_cast<const AnnotationReferenceFieldValue &>(other)); return _annotation_index - val._annotation_index; } return (getDataType()->getId() - other.getDataType()->getId()); diff --git a/document/src/vespa/document/fieldvalue/arrayfieldvalue.cpp b/document/src/vespa/document/fieldvalue/arrayfieldvalue.cpp index 0a80ef8c59b..07f731a9ea7 100644 --- a/document/src/vespa/document/fieldvalue/arrayfieldvalue.cpp +++ b/document/src/vespa/document/fieldvalue/arrayfieldvalue.cpp @@ -119,7 +119,7 @@ ArrayFieldValue::removeValue(const FieldValue& value) FieldValue& ArrayFieldValue::assign(const FieldValue& value) { - if (*value.getDataType() == *getDataType()) { + if (value.getDataType()->equals(*getDataType())) { const ArrayFieldValue& val(static_cast<const ArrayFieldValue&>(value)); operator=(val); return *this; diff --git a/document/src/vespa/document/fieldvalue/collectionfieldvalue.cpp b/document/src/vespa/document/fieldvalue/collectionfieldvalue.cpp index a83e8c226b9..4c960502b71 100644 --- a/document/src/vespa/document/fieldvalue/collectionfieldvalue.cpp +++ b/document/src/vespa/document/fieldvalue/collectionfieldvalue.cpp @@ -1,6 +1,6 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/document/fieldvalue/collectionfieldvalue.h> +#include "collectionfieldvalue.h" #include <vespa/vespalib/util/exceptions.h> namespace document { @@ -15,7 +15,7 @@ CollectionFieldValue::CollectionFieldValue(const CollectionFieldValue& other) void CollectionFieldValue::verifyType(const CollectionFieldValue& other) const { - if (*_type != *other._type) { + if ( ! _type->equals(*other._type)) { throw vespalib::IllegalArgumentException( "Cannot assign value of type " + other.getDataType()->toString() + " to value of type " + getDataType()->toString() + ".", diff --git a/document/src/vespa/document/fieldvalue/document.cpp b/document/src/vespa/document/fieldvalue/document.cpp index 36526f09dd6..57787738502 100644 --- a/document/src/vespa/document/fieldvalue/document.cpp +++ b/document/src/vespa/document/fieldvalue/document.cpp @@ -45,7 +45,7 @@ const DataType & Document::verifyDocumentType(const DataType *type) { if (!type) { documentTypeError("null"); - } else if ( ! type->getClass().inherits(DocumentType::classId)) { + } else if ( ! type->isDocument()) { documentTypeError(type->toString()); } return *type; diff --git a/document/src/vespa/document/fieldvalue/fieldvalue.cpp b/document/src/vespa/document/fieldvalue/fieldvalue.cpp index caaf9548ba0..8a678ddf968 100644 --- a/document/src/vespa/document/fieldvalue/fieldvalue.cpp +++ b/document/src/vespa/document/fieldvalue/fieldvalue.cpp @@ -11,7 +11,6 @@ #include "bytefieldvalue.h" #include "predicatefieldvalue.h" #include "iteratorhandler.h" -#include <vespa/document/util/bytebuffer.h> #include <vespa/document/base/exceptions.h> #include <vespa/document/serialization/vespadocumentserializer.h> #include <vespa/vespalib/objects/nbostream.h> @@ -55,13 +54,7 @@ FieldValue::isA(const FieldValue& other) const { } int FieldValue::compare(const FieldValue& other) const { - const DataType & a = *getDataType(); - const DataType & b = *other.getDataType(); - return (a < b) - ? -1 - : (b < a) - ? 1 - : 0; + return getDataType()->cmpId(*other.getDataType()); } int diff --git a/document/src/vespa/document/repo/documenttyperepo.cpp b/document/src/vespa/document/repo/documenttyperepo.cpp index 1738dbd0141..2a994d55ecb 100644 --- a/document/src/vespa/document/repo/documenttyperepo.cpp +++ b/document/src/vespa/document/repo/documenttyperepo.cpp @@ -26,7 +26,6 @@ using std::fstream; using std::make_pair; using std::pair; using std::vector; -using vespalib::Identifiable; using vespalib::IllegalArgumentException; using vespalib::hash_map; using vespalib::make_string; @@ -94,7 +93,7 @@ void Repo::inherit(const Repo &parent) { bool Repo::addDataType(const DataType &type) { const DataType *& data_type = _types[type.getId()]; if (data_type) { - if ((*data_type == type) && (data_type->getName() == type.getName())) { + if (data_type->equals(type) && (data_type->getName() == type.getName())) { return false; // Redefinition of identical type is ok. } throw IllegalArgumentException( @@ -202,7 +201,7 @@ void AnnotationTypeRepo::setAnnotationDataType(int32_t id, const DataType &d) { assert(annotation_type); if (!annotation_type->getDataType()) { annotation_type->setDataType(d); - } else if (*(annotation_type->getDataType()) != d) { + } else if ( ! annotation_type->getDataType()->equals(d)) { throw IllegalArgumentException( make_string("Redefinition of annotation type %d, \"%s\" = '%s'. Previously defined as '%s'.", annotation_type->getId(), annotation_type->getName().c_str(), diff --git a/document/src/vespa/document/update/documentupdate.cpp b/document/src/vespa/document/update/documentupdate.cpp index 758f6fbe03c..fde1ab70e11 100644 --- a/document/src/vespa/document/update/documentupdate.cpp +++ b/document/src/vespa/document/update/documentupdate.cpp @@ -59,7 +59,7 @@ DocumentUpdate::DocumentUpdate(const DocumentTypeRepo & repo, const DataType &ty _createIfNonExistent(false), _needHardReserialize(false) { - if (!type.getClass().inherits(DocumentType::classId)) { + if (!type.isDocument()) { throw IllegalArgumentException("Cannot generate a document with non-document type " + type.toString() + ".", VESPA_STRLOC); } serializeHeader(); diff --git a/document/src/vespa/document/update/mapvalueupdate.cpp b/document/src/vespa/document/update/mapvalueupdate.cpp index 8f9e90b5029..18f2c013b7f 100644 --- a/document/src/vespa/document/update/mapvalueupdate.cpp +++ b/document/src/vespa/document/update/mapvalueupdate.cpp @@ -43,14 +43,14 @@ void MapValueUpdate::checkCompatibility(const Field& field) const { // Check compatibility of nested types. - if (field.getDataType().getClass().id() == ArrayDataType::classId) { + if (field.getDataType().isArray()) { if (_key->getClass().id() != IntFieldValue::classId) { throw IllegalArgumentException(vespalib::make_string( "Key for field '%s' is of wrong type (expected '%s', was '%s').", field.getName().data(), DataType::INT->toString().c_str(), _key->getDataType()->toString().c_str()), VESPA_STRLOC); } - } else if (field.getDataType().getClass().id() == WeightedSetDataType::classId) { + } else if (field.getDataType().isWeightedSet()) { const WeightedSetDataType& type = static_cast<const WeightedSetDataType&>(field.getDataType()); if (!type.getNestedType().isValueType(*_key)) { throw IllegalArgumentException(vespalib::make_string( @@ -68,7 +68,7 @@ MapValueUpdate::checkCompatibility(const Field& field) const bool MapValueUpdate::applyTo(FieldValue& value) const { - if (value.getDataType()->getClass().id() == ArrayDataType::classId) { + if (value.getDataType()->isArray()) { ArrayFieldValue& val(static_cast<ArrayFieldValue&>(value)); int32_t index = _key->getAsInt(); if (index < 0 || static_cast<uint32_t>(index) >= val.size()) { @@ -79,7 +79,7 @@ MapValueUpdate::applyTo(FieldValue& value) const if (!_update->applyTo(val[_key->getAsInt()])) { val.remove(_key->getAsInt()); } - } else if (value.getDataType()->getClass().id() == WeightedSetDataType::classId) { + } else if (value.getDataType()->isWeightedSet()) { const WeightedSetDataType& type(static_cast<const WeightedSetDataType&>(*value.getDataType())); WeightedSetFieldValue& val(static_cast<WeightedSetFieldValue&>(value)); WeightedSetFieldValue::iterator it = val.find(*_key); @@ -131,25 +131,18 @@ void MapValueUpdate::deserialize(const DocumentTypeRepo& repo, const DataType& type, nbostream & stream) { VespaDocumentDeserializer deserializer(repo, stream, Document::getNewestSerializationVersion()); - switch(type.getClass().id()) { - case ArrayDataType::classId: - { - _key.reset(new IntFieldValue); - deserializer.read(*_key); - const ArrayDataType& arrayType = static_cast<const ArrayDataType&>(type); - _update.reset(ValueUpdate::createInstance(repo, arrayType.getNestedType(), stream).release()); - break; - } - case WeightedSetDataType::classId: - { - const WeightedSetDataType& wset(static_cast<const WeightedSetDataType&>(type)); - _key.reset(wset.getNestedType().createFieldValue().release()); - deserializer.read(*_key); - _update.reset(ValueUpdate::createInstance(repo, *DataType::INT, stream).release()); - break; - } - default: - throw DeserializeException("Can not perform map update on type " + type.toString() + ".", VESPA_STRLOC); + if (type.isArray()) { + _key.reset(new IntFieldValue); + deserializer.read(*_key); + const ArrayDataType& arrayType = static_cast<const ArrayDataType&>(type); + _update.reset(ValueUpdate::createInstance(repo, arrayType.getNestedType(), stream).release()); + } else if (type.isWeightedSet()) { + const WeightedSetDataType& wset(static_cast<const WeightedSetDataType&>(type)); + _key.reset(wset.getNestedType().createFieldValue().release()); + deserializer.read(*_key); + _update.reset(ValueUpdate::createInstance(repo, *DataType::INT, stream).release()); + } else { + throw DeserializeException("Can not perform map update on type " + type.toString() + ".", VESPA_STRLOC); } } diff --git a/document/src/vespa/document/update/removevalueupdate.cpp b/document/src/vespa/document/update/removevalueupdate.cpp index eb5d6547d75..d35d8db84a2 100644 --- a/document/src/vespa/document/update/removevalueupdate.cpp +++ b/document/src/vespa/document/update/removevalueupdate.cpp @@ -2,7 +2,6 @@ #include "removevalueupdate.h" #include <vespa/document/base/field.h> #include <vespa/document/datatype/arraydatatype.h> -#include <vespa/document/datatype/weightedsetdatatype.h> #include <vespa/document/fieldvalue/fieldvalues.h> #include <vespa/document/serialization/vespadocumentdeserializer.h> #include <vespa/vespalib/objects/nbostream.h> @@ -87,18 +86,14 @@ RemoveValueUpdate::print(std::ostream& out, bool, const std::string&) const void RemoveValueUpdate::deserialize(const DocumentTypeRepo& repo, const DataType& type, nbostream & stream) { - switch(type.getClass().id()) { - case ArrayDataType::classId: - case WeightedSetDataType::classId: - { - const CollectionDataType& c(static_cast<const CollectionDataType&>(type)); - _key.reset(c.getNestedType().createFieldValue().release()); - VespaDocumentDeserializer deserializer(repo, stream, Document::getNewestSerializationVersion()); - deserializer.read(*_key); - break; - } - default: - throw DeserializeException("Can not perform remove operation on type " + type.toString() + ".", VESPA_STRLOC); + const CollectionDataType * ct = type.cast_collection(); + if (ct != nullptr) { + const CollectionDataType& c(static_cast<const CollectionDataType&>(type)); + _key.reset(c.getNestedType().createFieldValue().release()); + VespaDocumentDeserializer deserializer(repo, stream, Document::getNewestSerializationVersion()); + deserializer.read(*_key); + } else { + throw DeserializeException("Can not perform remove operation on type " + type.toString() + ".", VESPA_STRLOC); } } diff --git a/document/src/vespa/document/update/tensor_add_update.cpp b/document/src/vespa/document/update/tensor_add_update.cpp index 7173fb2982d..3b442b7b1d5 100644 --- a/document/src/vespa/document/update/tensor_add_update.cpp +++ b/document/src/vespa/document/update/tensor_add_update.cpp @@ -74,7 +74,7 @@ TensorAddUpdate::operator==(const ValueUpdate &other) const void TensorAddUpdate::checkCompatibility(const Field& field) const { - if (field.getDataType().getClass().id() != TensorDataType::classId) { + if ( ! field.getDataType().isTensor()) { throw IllegalArgumentException(make_string("Cannot perform tensor add update on non-tensor field '%s'", field.getName().data()), VESPA_STRLOC); } diff --git a/document/src/vespa/document/update/tensor_modify_update.cpp b/document/src/vespa/document/update/tensor_modify_update.cpp index 4c114ba477c..e0da2dc0cc7 100644 --- a/document/src/vespa/document/update/tensor_modify_update.cpp +++ b/document/src/vespa/document/update/tensor_modify_update.cpp @@ -152,7 +152,7 @@ TensorModifyUpdate::operator==(const ValueUpdate &other) const void TensorModifyUpdate::checkCompatibility(const Field& field) const { - if (field.getDataType().getClass().id() != TensorDataType::classId) { + if ( ! field.getDataType().isTensor()) { throw IllegalArgumentException(make_string("Cannot perform tensor modify update on non-tensor field '%s'", field.getName().data()), VESPA_STRLOC); } diff --git a/document/src/vespa/document/update/tensor_remove_update.cpp b/document/src/vespa/document/update/tensor_remove_update.cpp index 2afd0869d62..a47c69d4f30 100644 --- a/document/src/vespa/document/update/tensor_remove_update.cpp +++ b/document/src/vespa/document/update/tensor_remove_update.cpp @@ -99,7 +99,7 @@ TensorRemoveUpdate::operator==(const ValueUpdate &other) const void TensorRemoveUpdate::checkCompatibility(const Field &field) const { - if (field.getDataType().getClass().id() != TensorDataType::classId) { + if ( ! field.getDataType().isTensor()) { throw IllegalArgumentException(make_string("Cannot perform tensor remove update on non-tensor field '%s'", field.getName().data()), VESPA_STRLOC); } diff --git a/document/src/vespa/document/util/identifiableid.h b/document/src/vespa/document/util/identifiableid.h index 1ff4d5301b5..fe5f4892254 100644 --- a/document/src/vespa/document/util/identifiableid.h +++ b/document/src/vespa/document/util/identifiableid.h @@ -18,13 +18,11 @@ #define CID_DoubleFieldValue DOCUMENT_CID(14) #define CID_StringFieldValue DOCUMENT_CID(15) #define CID_RawFieldValue DOCUMENT_CID(16) -//Gone with vespa 6 #define CID_ContentFieldValue DOCUMENT_CID(17) -#define CID_BoolFieldValue DOCUMENT_CID(18) +#define CID_BoolFieldValue DOCUMENT_CID(18) #define CID_ArrayFieldValue DOCUMENT_CID(19) #define CID_WeightedSetFieldValue DOCUMENT_CID(20) #define CID_FieldMapValue DOCUMENT_CID(21) #define CID_ShortFieldValue DOCUMENT_CID(22) -//#define CID_NullObject DOCUMENT_CID(23) #define CID_ValueUpdate DOCUMENT_CID(24) #define CID_AddValueUpdate DOCUMENT_CID(25) #define CID_ArithmeticValueUpdate DOCUMENT_CID(26) @@ -42,25 +40,6 @@ #define CID_TensorFieldValue DOCUMENT_CID(38) #define CID_ReferenceFieldValue DOCUMENT_CID(39) -#define CID_DataType DOCUMENT_CID(50) -#define CID_PrimitiveDataType DOCUMENT_CID(51) -#define CID_NumericDataType DOCUMENT_CID(52) -#define CID_CollectionDataType DOCUMENT_CID(53) -#define CID_ArrayDataType DOCUMENT_CID(54) -#define CID_WeightedSetDataType DOCUMENT_CID(55) -#define CID_StructuredDataType DOCUMENT_CID(56) -#define CID_StructDataType DOCUMENT_CID(57) -#define CID_DocumentType DOCUMENT_CID(58) - -//#define CID_ExactStringFieldValue DOCUMENT_CID(60) -//#define CID_TermBoostFieldValue DOCUMENT_CID(62) -//#define CID_TimestampFieldValue DOCUMENT_CID(63) -//#define CID_UriFieldValue DOCUMENT_CID(64) -#define CID_MapDataType DOCUMENT_CID(65) -#define CID_AnnotationReferenceDataType DOCUMENT_CID(66) -#define CID_TensorDataType DOCUMENT_CID(67) -#define CID_ReferenceDataType DOCUMENT_CID(68) - #define CID_document_FieldPathEntry DOCUMENT_CID(80) #define CID_FieldPathUpdate DOCUMENT_CID(85) |