diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2022-03-28 06:42:13 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2022-03-28 10:08:43 +0000 |
commit | 02b5efaa3bbc043e50e2c64b968241f842c3cffc (patch) | |
tree | b9f9ea83f0dd49656791439322d5ba3d3b6be0b9 | |
parent | bb59611ce9611986ee97f19d2bb725dc1d160074 (diff) |
Avoid the need for clone by using unique_ptr.
34 files changed, 194 insertions, 228 deletions
diff --git a/document/src/tests/documentselectparsertest.cpp b/document/src/tests/documentselectparsertest.cpp index 443686dde19..14aec13ab60 100644 --- a/document/src/tests/documentselectparsertest.cpp +++ b/document/src/tests/documentselectparsertest.cpp @@ -139,9 +139,9 @@ DocumentUpdate::SP DocumentSelectParserTest::createUpdate( const DocumentType* type = _repo->getDocumentType(doctype); auto doc = std::make_shared<DocumentUpdate>(*_repo, *type, DocumentId(id)); doc->addUpdate(std::move(FieldUpdate(doc->getType().getField("headerval")) - .addUpdate(AssignValueUpdate(IntFieldValue(hint))))); + .addUpdate(std::make_unique<AssignValueUpdate>(IntFieldValue(hint))))); doc->addUpdate(std::move(FieldUpdate(doc->getType().getField("hstringval")) - .addUpdate(AssignValueUpdate(StringFieldValue(hstr))))); + .addUpdate(std::make_unique<AssignValueUpdate>(StringFieldValue(hstr))))); return doc; } diff --git a/document/src/tests/documentupdatetestcase.cpp b/document/src/tests/documentupdatetestcase.cpp index a1b5bb17df9..a6be72e53d4 100644 --- a/document/src/tests/documentupdatetestcase.cpp +++ b/document/src/tests/documentupdatetestcase.cpp @@ -126,7 +126,7 @@ TEST(DocumentUpdateTest, testSimpleUsage) testRoundtripSerialize(RemoveValueUpdate(IntFieldValue(1)), *arrayType); FieldUpdate fieldUpdate(docType->getField("intf")); - fieldUpdate.addUpdate(AssignValueUpdate(IntFieldValue(1))); + fieldUpdate.addUpdate(std::make_unique<AssignValueUpdate>(IntFieldValue(1))); nbostream stream = serialize(fieldUpdate); FieldUpdate fieldUpdateCopy(repo, *docType, stream); EXPECT_EQ(fieldUpdate, fieldUpdateCopy); @@ -150,7 +150,7 @@ TEST(DocumentUpdateTest, testSimpleUsage) { Document updated(doc); DocumentUpdate upd(repo, *docType, DocumentId("id:ns:test::1")); - upd.addUpdate(std::move(FieldUpdate(docType->getField("intf")).addUpdate(ClearValueUpdate()))); + upd.addUpdate(std::move(FieldUpdate(docType->getField("intf")).addUpdate(std::make_unique<ClearValueUpdate>()))); upd.applyTo(updated); EXPECT_NE(doc, updated); EXPECT_FALSE(updated.getValue("intf")); @@ -158,7 +158,7 @@ TEST(DocumentUpdateTest, testSimpleUsage) { Document updated(doc); DocumentUpdate upd(repo, *docType, DocumentId("id:ns:test::1")); - upd.addUpdate(std::move(FieldUpdate(docType->getField("intf")).addUpdate(AssignValueUpdate(IntFieldValue(15))))); + upd.addUpdate(std::move(FieldUpdate(docType->getField("intf")).addUpdate(std::make_unique<AssignValueUpdate>(IntFieldValue(15))))); upd.applyTo(updated); EXPECT_NE(doc, updated); EXPECT_EQ(15, updated.getValue("intf")->getAsInt()); @@ -166,7 +166,7 @@ TEST(DocumentUpdateTest, testSimpleUsage) { Document updated(doc); DocumentUpdate upd(repo, *docType, DocumentId("id:ns:test::1")); - upd.addUpdate(std::move(FieldUpdate(docType->getField("intf")).addUpdate(ArithmeticValueUpdate(ArithmeticValueUpdate::Add, 15)))); + upd.addUpdate(std::move(FieldUpdate(docType->getField("intf")).addUpdate(std::make_unique<ArithmeticValueUpdate>(ArithmeticValueUpdate::Add, 15)))); upd.applyTo(updated); EXPECT_NE(doc, updated); EXPECT_EQ(20, updated.getValue("intf")->getAsInt()); @@ -174,7 +174,7 @@ TEST(DocumentUpdateTest, testSimpleUsage) { Document updated(doc); DocumentUpdate upd(repo, *docType, DocumentId("id:ns:test::1")); - upd.addUpdate(std::move(FieldUpdate(docType->getField("intarr")).addUpdate(AddValueUpdate(IntFieldValue(4))))); + upd.addUpdate(std::move(FieldUpdate(docType->getField("intarr")).addUpdate(std::make_unique<AddValueUpdate>(IntFieldValue(4))))); upd.applyTo(updated); EXPECT_NE(doc, updated); std::unique_ptr<ArrayFieldValue> val(dynamic_cast<ArrayFieldValue*>(updated.getValue("intarr").release())); @@ -184,7 +184,7 @@ TEST(DocumentUpdateTest, testSimpleUsage) { Document updated(doc); DocumentUpdate upd(repo, *docType, DocumentId("id:ns:test::1")); - upd.addUpdate(std::move(FieldUpdate(docType->getField("intarr")).addUpdate(RemoveValueUpdate(IntFieldValue(3))))); + upd.addUpdate(std::move(FieldUpdate(docType->getField("intarr")).addUpdate(std::make_unique<RemoveValueUpdate>(IntFieldValue(3))))); upd.applyTo(updated); EXPECT_NE(doc, updated); std::unique_ptr<ArrayFieldValue> val(dynamic_cast<ArrayFieldValue*>(updated.getValue("intarr").release())); @@ -195,7 +195,7 @@ TEST(DocumentUpdateTest, testSimpleUsage) Document updated(doc); DocumentUpdate upd(repo, *docType, DocumentId("id:ns:test::1")); upd.addUpdate(std::move(FieldUpdate(docType->getField("bytef")) - .addUpdate(ArithmeticValueUpdate(ArithmeticValueUpdate::Add, 15)))); + .addUpdate(std::make_unique<ArithmeticValueUpdate>(ArithmeticValueUpdate::Add, 15)))); upd.applyTo(updated); EXPECT_NE(doc, updated); EXPECT_EQ(15, (int) updated.getValue("bytef")->getAsByte()); @@ -212,7 +212,7 @@ TEST(DocumentUpdateTest, testClearField) // Apply an update. DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()) - .addUpdate(std::move(FieldUpdate(doc->getField("headerval")).addUpdate(AssignValueUpdate()))) + .addUpdate(std::move(FieldUpdate(doc->getField("headerval")).addUpdate(std::make_unique<AssignValueUpdate>()))) .applyTo(*doc); EXPECT_FALSE(doc->getValue("headerval")); } @@ -227,7 +227,7 @@ TEST(DocumentUpdateTest, testUpdateApplySingleValue) // Apply an update. DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()) - .addUpdate(std::move(FieldUpdate(doc->getField("headerval")).addUpdate(AssignValueUpdate(IntFieldValue(9))))) + .addUpdate(std::move(FieldUpdate(doc->getField("headerval")).addUpdate(std::make_unique<AssignValueUpdate>(IntFieldValue(9))))) .applyTo(*doc); EXPECT_EQ(9, doc->getValue("headerval")->getAsInt()); } @@ -245,7 +245,7 @@ TEST(DocumentUpdateTest, testUpdateArray) myarray.add(StringFieldValue("bar")); DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()) - .addUpdate(std::move(FieldUpdate(doc->getField("tags")).addUpdate(AssignValueUpdate(myarray)))) + .addUpdate(std::move(FieldUpdate(doc->getField("tags")).addUpdate(std::make_unique<AssignValueUpdate>(myarray)))) .applyTo(*doc); auto fval1(doc->getAs<ArrayFieldValue>(doc->getField("tags"))); ASSERT_EQ((size_t) 2, fval1->size()); @@ -255,8 +255,8 @@ TEST(DocumentUpdateTest, testUpdateArray) // Append array field DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()) .addUpdate(std::move(FieldUpdate(doc->getField("tags")) - .addUpdate(AddValueUpdate(StringFieldValue("another"))) - .addUpdate(AddValueUpdate(StringFieldValue("tag"))))) + .addUpdate(std::make_unique<AddValueUpdate>(StringFieldValue("another"))) + .addUpdate(std::make_unique<AddValueUpdate>(StringFieldValue("tag"))))) .applyTo(*doc); std::unique_ptr<ArrayFieldValue> fval2(doc->getAs<ArrayFieldValue>(doc->getField("tags"))); @@ -270,15 +270,15 @@ TEST(DocumentUpdateTest, testUpdateArray) ASSERT_THROW( DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()) .addUpdate(std::move(FieldUpdate(doc->getField("tags")) - .addUpdate(AssignValueUpdate(StringFieldValue("THROW MEH!"))))) + .addUpdate(std::make_unique<AssignValueUpdate>(StringFieldValue("THROW MEH!"))))) .applyTo(*doc), std::exception) << "Expected exception when assigning a string value to an array field."; // Remove array field. DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()) .addUpdate(std::move(FieldUpdate(doc->getField("tags")) - .addUpdate(RemoveValueUpdate(StringFieldValue("foo"))) - .addUpdate(RemoveValueUpdate(StringFieldValue("tag"))))) + .addUpdate(std::make_unique<RemoveValueUpdate>(StringFieldValue("foo"))) + .addUpdate(std::make_unique<RemoveValueUpdate>(StringFieldValue("tag"))))) .applyTo(*doc); auto fval3(doc->getAs<ArrayFieldValue>(doc->getField("tags"))); ASSERT_EQ((size_t) 2, fval3->size()); @@ -292,11 +292,25 @@ TEST(DocumentUpdateTest, testUpdateArray) ASSERT_THROW( DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()) .addUpdate(std::move(FieldUpdate(doc->getField("tags")) - .addUpdate(RemoveValueUpdate(myarray2)))) + .addUpdate(std::make_unique<RemoveValueUpdate>(myarray2)))) .applyTo(*doc), std::exception) << "Expected exception when removing an array from a string array."; } +std::unique_ptr<ValueUpdate> +createAddUpdate(vespalib::stringref key, int weight) { + auto upd = std::make_unique<AddValueUpdate>(StringFieldValue(key)); + upd->setWeight(weight); + return upd; +} + +std::unique_ptr<ValueUpdate> +createAddUpdate(int key, int weight) { + auto upd = std::make_unique<AddValueUpdate>(IntFieldValue(key)); + upd->setWeight(weight); + return upd; +} + TEST(DocumentUpdateTest, testUpdateWeightedSet) { // Create a test document @@ -310,7 +324,7 @@ TEST(DocumentUpdateTest, testUpdateWeightedSet) wset.add(StringFieldValue("foo"), 3); wset.add(StringFieldValue("bar"), 14); DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()) - .addUpdate(std::move(FieldUpdate(field).addUpdate(AssignValueUpdate(wset)))) + .addUpdate(std::move(FieldUpdate(field).addUpdate(std::make_unique<AssignValueUpdate>(wset)))) .applyTo(*doc); auto fval1(doc->getAs<WeightedSetFieldValue>(field)); ASSERT_EQ((size_t) 2, fval1->size()); @@ -327,7 +341,7 @@ TEST(DocumentUpdateTest, testUpdateWeightedSet) wset2.add(StringFieldValue("bar"), 24); DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()) .addUpdate(std::move(FieldUpdate(field) - .addUpdate(AssignValueUpdate(wset2)))) + .addUpdate(std::make_unique<AssignValueUpdate>(wset2)))) .applyTo(*doc); auto fval2(doc->getAs<WeightedSetFieldValue>(field)); ASSERT_EQ((size_t) 2, fval2->size()); @@ -341,8 +355,8 @@ TEST(DocumentUpdateTest, testUpdateWeightedSet) // Append weighted field DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()) .addUpdate(std::move(FieldUpdate(field) - .addUpdate(AddValueUpdate(StringFieldValue("foo")).setWeight(3)) - .addUpdate(AddValueUpdate(StringFieldValue("too")).setWeight(14)))) + .addUpdate(createAddUpdate("foo", 3)) + .addUpdate(createAddUpdate("too", 14)))) .applyTo(*doc); std::unique_ptr<WeightedSetFieldValue> fval3(doc->getAs<WeightedSetFieldValue>(field)); @@ -357,8 +371,8 @@ TEST(DocumentUpdateTest, testUpdateWeightedSet) // Remove weighted field DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()) .addUpdate(std::move(FieldUpdate(field) - .addUpdate(RemoveValueUpdate(StringFieldValue("foo"))) - .addUpdate(RemoveValueUpdate(StringFieldValue("too"))))) + .addUpdate(std::make_unique<RemoveValueUpdate>(StringFieldValue("foo"))) + .addUpdate(std::make_unique<RemoveValueUpdate>(StringFieldValue("too"))))) .applyTo(*doc); auto fval4(doc->getAs<WeightedSetFieldValue>(field)); ASSERT_EQ((size_t) 1, fval4->size()); @@ -405,8 +419,8 @@ WeightedSetAutoCreateFixture::WeightedSetAutoCreateFixture() update(repo, *docType, DocumentId("id:ns:test::1")) { update.addUpdate(std::move(FieldUpdate(field) - .addUpdate(MapValueUpdate(StringFieldValue("foo"), - ArithmeticValueUpdate(ArithmeticValueUpdate::Add, 1))))); + .addUpdate(std::make_unique<MapValueUpdate>(StringFieldValue("foo"), + std::make_unique<ArithmeticValueUpdate>(ArithmeticValueUpdate::Add, 1))))); } } // anon ns @@ -443,8 +457,8 @@ TEST(DocumentUpdateTest, testIncrementWithZeroResultWeightIsRemoved) { WeightedSetAutoCreateFixture fixture; fixture.update.addUpdate(std::move(FieldUpdate(fixture.field) - .addUpdate(MapValueUpdate(StringFieldValue("baz"), - ArithmeticValueUpdate(ArithmeticValueUpdate::Add, 0))))); + .addUpdate(std::make_unique<MapValueUpdate>(StringFieldValue("baz"), + std::make_unique<ArithmeticValueUpdate>(ArithmeticValueUpdate::Add, 0))))); fixture.applyUpdateToDocument(); @@ -525,20 +539,20 @@ TEST(DocumentUpdateTest, testGenerateSerializedFile) const DocumentType *type(repo.getDocumentType("serializetest")); DocumentUpdate upd(repo, *type, DocumentId("id:ns:serializetest::update")); upd.addUpdate(std::move(FieldUpdate(type->getField("intfield")) - .addUpdate(AssignValueUpdate(IntFieldValue(4))))); + .addUpdate(std::make_unique<AssignValueUpdate>(IntFieldValue(4))))); upd.addUpdate(std::move(FieldUpdate(type->getField("floatfield")) - .addUpdate(AssignValueUpdate(FloatFieldValue(1.00f))))); + .addUpdate(std::make_unique<AssignValueUpdate>(FloatFieldValue(1.00f))))); upd.addUpdate(std::move(FieldUpdate(type->getField("arrayoffloatfield")) - .addUpdate(AddValueUpdate(FloatFieldValue(5.00f))) - .addUpdate(AddValueUpdate(FloatFieldValue(4.23f))) - .addUpdate(AddValueUpdate(FloatFieldValue(-1.00f))))); + .addUpdate(std::make_unique<AddValueUpdate>(FloatFieldValue(5.00f))) + .addUpdate(std::make_unique<AddValueUpdate>(FloatFieldValue(4.23f))) + .addUpdate(std::make_unique<AddValueUpdate>(FloatFieldValue(-1.00f))))); upd.addUpdate(std::move(FieldUpdate(type->getField("intfield")) - .addUpdate(ArithmeticValueUpdate(ArithmeticValueUpdate::Add, 3)))); + .addUpdate(std::make_unique<ArithmeticValueUpdate>(ArithmeticValueUpdate::Add, 3)))); upd.addUpdate(std::move(FieldUpdate(type->getField("wsfield")) - .addUpdate(MapValueUpdate(StringFieldValue("foo"), - ArithmeticValueUpdate(ArithmeticValueUpdate::Add, 2))) - .addUpdate(MapValueUpdate(StringFieldValue("foo"), - ArithmeticValueUpdate(ArithmeticValueUpdate::Mul, 2))))); + .addUpdate(std::make_unique<MapValueUpdate>(StringFieldValue("foo"), + std::make_unique<ArithmeticValueUpdate>(ArithmeticValueUpdate::Add, 2))) + .addUpdate(std::make_unique<MapValueUpdate>(StringFieldValue("foo"), + std::make_unique<ArithmeticValueUpdate>(ArithmeticValueUpdate::Mul, 2))))); nbostream buf(serializeHEAD(upd)); writeBufferToFile(buf, "data/serializeupdatecpp.dat"); } @@ -555,7 +569,7 @@ TEST(DocumentUpdateTest, testSetBadFieldTypes) DocumentUpdate update(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()); ASSERT_THROW( update.addUpdate(std::move(FieldUpdate(doc->getField("headerval")) - .addUpdate(AssignValueUpdate(FloatFieldValue(4.00f))))), + .addUpdate(std::make_unique<AssignValueUpdate>(FloatFieldValue(4.00f))))), std::exception) << "Expected exception when adding a float to an int field."; update.applyTo(*doc); @@ -572,7 +586,7 @@ TEST(DocumentUpdateTest, testUpdateApplyNoParams) EXPECT_EQ((document::FieldValue*)nullptr, doc->getValue(doc->getField("tags")).get()); DocumentUpdate update(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()); - update.addUpdate(std::move(FieldUpdate(doc->getField("tags")).addUpdate(AssignValueUpdate()))); + update.addUpdate(std::move(FieldUpdate(doc->getField("tags")).addUpdate(std::make_unique<AssignValueUpdate>()))); update.applyTo(*doc); @@ -590,7 +604,7 @@ TEST(DocumentUpdateTest, testUpdateApplyNoArrayValues) // Assign array field with no array values = empty array DocumentUpdate update(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()); update.addUpdate(std::move(FieldUpdate(field) - .addUpdate(AssignValueUpdate(ArrayFieldValue(field.getDataType()))))); + .addUpdate(std::make_unique<AssignValueUpdate>(ArrayFieldValue(field.getDataType()))))); update.applyTo(*doc); @@ -610,7 +624,7 @@ TEST(DocumentUpdateTest, testUpdateArrayEmptyParamValue) // Assign array field with no array values = empty array. DocumentUpdate update(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()); - update.addUpdate(std::move(FieldUpdate(field).addUpdate(AssignValueUpdate(ArrayFieldValue(field.getDataType()))))); + update.addUpdate(std::move(FieldUpdate(field).addUpdate(std::make_unique<AssignValueUpdate>(ArrayFieldValue(field.getDataType()))))); update.applyTo(*doc); // Verify that the field was set in the document. @@ -620,7 +634,7 @@ TEST(DocumentUpdateTest, testUpdateArrayEmptyParamValue) // Remove array field. DocumentUpdate update2(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()); - update2.addUpdate(std::move(FieldUpdate(field).addUpdate(ClearValueUpdate()))); + update2.addUpdate(std::move(FieldUpdate(field).addUpdate(std::make_unique<ClearValueUpdate>()))); update2.applyTo(*doc); // Verify that the field was cleared in the document. @@ -638,7 +652,7 @@ TEST(DocumentUpdateTest, testUpdateWeightedSetEmptyParamValue) // Assign weighted set with no items = empty set. DocumentUpdate update(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()); - update.addUpdate(std::move(FieldUpdate(field).addUpdate(AssignValueUpdate(WeightedSetFieldValue(field.getDataType()))))); + update.addUpdate(std::move(FieldUpdate(field).addUpdate(std::make_unique<AssignValueUpdate>(WeightedSetFieldValue(field.getDataType()))))); update.applyTo(*doc); // Verify that the field was set in the document. @@ -648,7 +662,7 @@ TEST(DocumentUpdateTest, testUpdateWeightedSetEmptyParamValue) // Remove weighted set field. DocumentUpdate update2(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()); - update2.addUpdate(std::move(FieldUpdate(field).addUpdate(ClearValueUpdate()))); + update2.addUpdate(std::move(FieldUpdate(field).addUpdate(std::make_unique<ClearValueUpdate>()))); update2.applyTo(*doc); // Verify that the field was cleared in the document. @@ -668,8 +682,8 @@ TEST(DocumentUpdateTest, testUpdateArrayWrongSubtype) DocumentUpdate update(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()); ASSERT_THROW( update.addUpdate(std::move(FieldUpdate(field) - .addUpdate(AddValueUpdate(IntFieldValue(123))) - .addUpdate(AddValueUpdate(IntFieldValue(456))))), + .addUpdate(std::make_unique<AddValueUpdate>(IntFieldValue(123))) + .addUpdate(std::make_unique<AddValueUpdate>(IntFieldValue(456))))), std::exception) << "Expected exception when adding wrong type."; // Apply update @@ -692,8 +706,8 @@ TEST(DocumentUpdateTest, testUpdateWeightedSetWrongSubtype) DocumentUpdate update(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()); ASSERT_THROW( update.addUpdate(std::move(FieldUpdate(field) - .addUpdate(AddValueUpdate(IntFieldValue(123)).setWeight(1000)) - .addUpdate(AddValueUpdate(IntFieldValue(456)).setWeight(2000)))), + .addUpdate(createAddUpdate(123, 1000)) + .addUpdate(createAddUpdate(456, 2000)))), std::exception) << "Expected exception when adding wrong type."; // Apply update @@ -718,8 +732,8 @@ TEST(DocumentUpdateTest, testMapValueUpdate) DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()) .addUpdate(std::move(FieldUpdate(field1) - .addUpdate(MapValueUpdate(StringFieldValue("banana"), - ArithmeticValueUpdate(ArithmeticValueUpdate::Add, 1.0))))) + .addUpdate(std::make_unique<MapValueUpdate>(StringFieldValue("banana"), + std::make_unique<ArithmeticValueUpdate>(ArithmeticValueUpdate::Add, 1.0))))) .applyTo(*doc); std::unique_ptr<WeightedSetFieldValue> fv1 = doc->getAs<WeightedSetFieldValue>(field1); @@ -727,19 +741,19 @@ TEST(DocumentUpdateTest, testMapValueUpdate) DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()) .addUpdate(std::move(FieldUpdate(field2) - .addUpdate(MapValueUpdate(StringFieldValue("banana"), - ArithmeticValueUpdate(ArithmeticValueUpdate::Add, 1.0))))) + .addUpdate(std::make_unique<MapValueUpdate>(StringFieldValue("banana"), + std::make_unique<ArithmeticValueUpdate>(ArithmeticValueUpdate::Add, 1.0))))) .applyTo(*doc); auto fv2 = doc->getAs<WeightedSetFieldValue>(field2); EXPECT_EQ(1, fv2->size()); EXPECT_EQ(fv1->find(StringFieldValue("apple")), fv1->end()); DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()) - .addUpdate(std::move(FieldUpdate(field1).addUpdate(ClearValueUpdate()))) + .addUpdate(std::move(FieldUpdate(field1).addUpdate(std::make_unique<ClearValueUpdate>()))) .applyTo(*doc); DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()) - .addUpdate(std::move(FieldUpdate(field1).addUpdate(AddValueUpdate(StringFieldValue("apple")).setWeight(1)))) + .addUpdate(std::move(FieldUpdate(field1).addUpdate(createAddUpdate("apple", 1)))) .applyTo(*doc); auto fval3(doc->getAs<WeightedSetFieldValue>(field1)); @@ -747,7 +761,7 @@ TEST(DocumentUpdateTest, testMapValueUpdate) EXPECT_EQ(1, fval3->get(StringFieldValue("apple"))); DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()) - .addUpdate(std::move(FieldUpdate(field2).addUpdate(AddValueUpdate(StringFieldValue("apple")).setWeight(1)))) + .addUpdate(std::move(FieldUpdate(field2).addUpdate(createAddUpdate("apple", 1)))) .applyTo(*doc); auto fval3b(doc->getAs<WeightedSetFieldValue>(field2)); @@ -756,8 +770,8 @@ TEST(DocumentUpdateTest, testMapValueUpdate) DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()) .addUpdate(std::move(FieldUpdate(field1) - .addUpdate(MapValueUpdate(StringFieldValue("apple"), - ArithmeticValueUpdate(ArithmeticValueUpdate::Sub, 1.0))))) + .addUpdate(std::make_unique<MapValueUpdate>(StringFieldValue("apple"), + std::make_unique<ArithmeticValueUpdate>(ArithmeticValueUpdate::Sub, 1.0))))) .applyTo(*doc); auto fv3 = doc->getAs<WeightedSetFieldValue>(field1); @@ -766,8 +780,8 @@ TEST(DocumentUpdateTest, testMapValueUpdate) DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId()) .addUpdate(std::move(FieldUpdate(field2) - .addUpdate(MapValueUpdate(StringFieldValue("apple"), - ArithmeticValueUpdate(ArithmeticValueUpdate::Sub, 1.0))))) + .addUpdate(std::make_unique<MapValueUpdate>(StringFieldValue("apple"), + std::make_unique<ArithmeticValueUpdate>(ArithmeticValueUpdate::Sub, 1.0))))) .applyTo(*doc); auto fv4 = doc->getAs<WeightedSetFieldValue>(field2); @@ -851,9 +865,9 @@ struct TensorUpdateFixture { .add({{"x", "b"}}, 3)); } - void applyUpdate(const ValueUpdate &update) { + void applyUpdate(std::unique_ptr<ValueUpdate> update) { DocumentUpdate docUpdate(docMan.getTypeRepo(), *emptyDoc->getDataType(), emptyDoc->getId()); - docUpdate.addUpdate(std::move(FieldUpdate(docUpdate.getType().getField(fieldName)).addUpdate(update))); + docUpdate.addUpdate(std::move(FieldUpdate(docUpdate.getType().getField(fieldName)).addUpdate(std::move(update)))); docUpdate.applyTo(updatedDoc); } @@ -887,23 +901,23 @@ struct TensorUpdateFixture { } void assertApplyUpdate(const TensorSpec &initialTensor, - const ValueUpdate &update, + std::unique_ptr<ValueUpdate> update, const TensorSpec &expTensor) { setTensor(initialTensor); - applyUpdate(update); + applyUpdate(std::move(update)); assertDocumentUpdated(); assertTensor(expTensor); } - void assertApplyUpdateNonExisting(const ValueUpdate &update, + void assertApplyUpdateNonExisting(std::unique_ptr<ValueUpdate> update, const TensorSpec &expTensor) { - applyUpdate(update); + applyUpdate(std::move(update)); assertDocumentUpdated(); assertTensor(expTensor); } - void assertApplyUpdateNonExisting(const ValueUpdate &update) { - applyUpdate(update); + void assertApplyUpdateNonExisting(std::unique_ptr<ValueUpdate> update) { + applyUpdate(std::move(update)); assertDocumentUpdated(); assertTensorNull(); } @@ -927,7 +941,7 @@ TEST(DocumentUpdateTest, tensor_assign_update_can_be_applied) { TensorUpdateFixture f; auto newTensor = f.makeBaselineTensor(); - f.applyUpdate(AssignValueUpdate(*newTensor)); + f.applyUpdate(std::make_unique<AssignValueUpdate>(*newTensor)); f.assertDocumentUpdated(); f.assertTensor(*newTensor); } @@ -936,7 +950,7 @@ TEST(DocumentUpdateTest, tensor_clear_update_can_be_applied) { TensorUpdateFixture f; f.setTensor(*f.makeBaselineTensor()); - f.applyUpdate(ClearValueUpdate()); + f.applyUpdate(std::make_unique<ClearValueUpdate>()); f.assertDocumentNotUpdated(); EXPECT_FALSE(f.getTensor()); } @@ -947,7 +961,7 @@ TEST(DocumentUpdateTest, tensor_add_update_can_be_applied) f.assertApplyUpdate(f.spec().add({{"x", "a"}}, 2) .add({{"x", "b"}}, 3), - TensorAddUpdate(f.makeTensor(f.spec().add({{"x", "b"}}, 5) + std::make_unique<TensorAddUpdate>(f.makeTensor(f.spec().add({{"x", "b"}}, 5) .add({{"x", "c"}}, 7))), f.spec().add({{"x", "a"}}, 2) @@ -958,7 +972,7 @@ TEST(DocumentUpdateTest, tensor_add_update_can_be_applied) TEST(DocumentUpdateTest, tensor_add_update_can_be_applied_to_nonexisting_tensor) { TensorUpdateFixture f; - f.assertApplyUpdateNonExisting(TensorAddUpdate(f.makeTensor(f.spec().add({{"x", "b"}}, 5) + f.assertApplyUpdateNonExisting(std::make_unique<TensorAddUpdate>(f.makeTensor(f.spec().add({{"x", "b"}}, 5) .add({{"x", "c"}}, 7))), f.spec().add({{"x", "b"}}, 5) @@ -971,7 +985,7 @@ TEST(DocumentUpdateTest, tensor_remove_update_can_be_applied) f.assertApplyUpdate(f.spec().add({{"x", "a"}}, 2) .add({{"x", "b"}}, 3), - TensorRemoveUpdate(f.makeTensor(f.spec().add({{"x", "b"}}, 1))), + std::make_unique<TensorRemoveUpdate>(f.makeTensor(f.spec().add({{"x", "b"}}, 1))), f.spec().add({{"x", "a"}}, 2)); } @@ -979,7 +993,7 @@ TEST(DocumentUpdateTest, tensor_remove_update_can_be_applied) TEST(DocumentUpdateTest, tensor_remove_update_can_be_applied_to_nonexisting_tensor) { TensorUpdateFixture f; - f.assertApplyUpdateNonExisting(TensorRemoveUpdate(f.makeTensor(f.spec().add({{"x", "b"}}, 1)))); + f.assertApplyUpdateNonExisting(std::make_unique<TensorRemoveUpdate>(f.makeTensor(f.spec().add({{"x", "b"}}, 1)))); } TEST(DocumentUpdateTest, tensor_modify_update_can_be_applied) @@ -989,20 +1003,20 @@ TEST(DocumentUpdateTest, tensor_modify_update_can_be_applied) .add({{"x", "b"}}, 3); f.assertApplyUpdate(baseLine, - TensorModifyUpdate(TensorModifyUpdate::Operation::REPLACE, + std::make_unique<TensorModifyUpdate>(TensorModifyUpdate::Operation::REPLACE, f.makeTensor(f.spec().add({{"x", "b"}}, 5) .add({{"x", "c"}}, 7))), f.spec().add({{"x", "a"}}, 2) .add({{"x", "b"}}, 5)); f.assertApplyUpdate(baseLine, - TensorModifyUpdate(TensorModifyUpdate::Operation::ADD, + std::make_unique<TensorModifyUpdate>(TensorModifyUpdate::Operation::ADD, f.makeTensor(f.spec().add({{"x", "b"}}, 5))), f.spec().add({{"x", "a"}}, 2) .add({{"x", "b"}}, 8)); f.assertApplyUpdate(baseLine, - TensorModifyUpdate(TensorModifyUpdate::Operation::MULTIPLY, + std::make_unique<TensorModifyUpdate>(TensorModifyUpdate::Operation::MULTIPLY, f.makeTensor(f.spec().add({{"x", "b"}}, 5))), f.spec().add({{"x", "a"}}, 2) .add({{"x", "b"}}, 15)); @@ -1011,7 +1025,7 @@ TEST(DocumentUpdateTest, tensor_modify_update_can_be_applied) TEST(DocumentUpdateTest, tensor_modify_update_can_be_applied_to_nonexisting_tensor) { TensorUpdateFixture f; - f.assertApplyUpdateNonExisting(TensorModifyUpdate(TensorModifyUpdate::Operation::ADD, + f.assertApplyUpdateNonExisting(std::make_unique<TensorModifyUpdate>(TensorModifyUpdate::Operation::ADD, f.makeTensor(f.spec().add({{"x", "b"}}, 5)))); } @@ -1148,13 +1162,13 @@ struct TensorUpdateSerializeFixture { (*repo, docType, DocumentId("id:test:test::0")); result->addUpdate(std::move(FieldUpdate(getField("sparse_tensor")) - .addUpdate(AssignValueUpdate(*makeTensor())) - .addUpdate(TensorAddUpdate(makeTensor())) - .addUpdate(TensorRemoveUpdate(makeTensor())))); + .addUpdate(std::make_unique<AssignValueUpdate>(*makeTensor())) + .addUpdate(std::make_unique<TensorAddUpdate>(makeTensor())) + .addUpdate(std::make_unique<TensorRemoveUpdate>(makeTensor())))); result->addUpdate(std::move(FieldUpdate(getField("dense_tensor")) - .addUpdate(TensorModifyUpdate(TensorModifyUpdate::Operation::REPLACE, makeTensor())) - .addUpdate(TensorModifyUpdate(TensorModifyUpdate::Operation::ADD, makeTensor())) - .addUpdate(TensorModifyUpdate(TensorModifyUpdate::Operation::MULTIPLY, makeTensor())))); + .addUpdate(std::make_unique<TensorModifyUpdate>(TensorModifyUpdate::Operation::REPLACE, makeTensor())) + .addUpdate(std::make_unique<TensorModifyUpdate>(TensorModifyUpdate::Operation::ADD, makeTensor())) + .addUpdate(std::make_unique<TensorModifyUpdate>(TensorModifyUpdate::Operation::MULTIPLY, makeTensor())))); return result; } @@ -1236,7 +1250,7 @@ CreateIfNonExistentFixture::CreateIfNonExistentFixture() update(std::make_unique<DocumentUpdate>(docMan.getTypeRepo(), *document->getDataType(), document->getId())) { update->addUpdate(std::move(FieldUpdate(document->getField("headerval")) - .addUpdate(AssignValueUpdate(IntFieldValue(1))))); + .addUpdate(std::make_unique<AssignValueUpdate>(IntFieldValue(1))))); update->setCreateIfNonExistent(true); } @@ -1268,8 +1282,8 @@ ArrayUpdateFixture::ArrayUpdateFixture() { update = std::make_unique<DocumentUpdate>(doc_man.getTypeRepo(), *doc->getDataType(), doc->getId()); update->addUpdate(std::move(FieldUpdate(array_field) - .addUpdate(MapValueUpdate(IntFieldValue(1), - AssignValueUpdate(StringFieldValue("bar")))))); + .addUpdate(std::make_unique<MapValueUpdate>(IntFieldValue(1), + std::make_unique<AssignValueUpdate>(StringFieldValue("bar")))))); } ArrayUpdateFixture::~ArrayUpdateFixture() = default; diff --git a/document/src/tests/feed_reject_helper_test.cpp b/document/src/tests/feed_reject_helper_test.cpp index bb7faade164..6649c9c0208 100644 --- a/document/src/tests/feed_reject_helper_test.cpp +++ b/document/src/tests/feed_reject_helper_test.cpp @@ -60,7 +60,7 @@ TEST(DocumentRejectTest, requireThatClearRemoveTensorRemoveAndArtithmeticUpdates TEST(DocumentRejectTest, requireThatAddMapTensorModifyAndTensorAddUpdatesWillBeRejected) { EXPECT_TRUE(FeedRejectHelper::mustReject(AddValueUpdate(IntFieldValue()))); - EXPECT_TRUE(FeedRejectHelper::mustReject(MapValueUpdate(IntFieldValue(), ClearValueUpdate()))); + EXPECT_TRUE(FeedRejectHelper::mustReject(MapValueUpdate(IntFieldValue(), std::make_unique<ClearValueUpdate>()))); EXPECT_TRUE(FeedRejectHelper::mustReject(TensorModifyUpdate(TensorModifyUpdate::Operation::REPLACE, std::make_unique<TensorFieldValue>()))); EXPECT_TRUE(FeedRejectHelper::mustReject(TensorAddUpdate(std::make_unique<TensorFieldValue>()))); diff --git a/document/src/tests/testxml.cpp b/document/src/tests/testxml.cpp index e2da806e834..71f7d0e3c38 100644 --- a/document/src/tests/testxml.cpp +++ b/document/src/tests/testxml.cpp @@ -60,16 +60,16 @@ createTestDocumentUpdate(const DocumentTypeRepo& repo) auto up = std::make_unique<DocumentUpdate>(repo, *type, id); up->addUpdate(std::move(FieldUpdate(type->getField("intattr")) - .addUpdate(AssignValueUpdate(IntFieldValue(7))))); + .addUpdate(std::make_unique<AssignValueUpdate>(IntFieldValue(7))))); up->addUpdate(std::move(FieldUpdate(type->getField("stringattr")) - .addUpdate(AssignValueUpdate(StringFieldValue("New value"))))); + .addUpdate(std::make_unique<AssignValueUpdate>(StringFieldValue("New value"))))); up->addUpdate(std::move(FieldUpdate(type->getField("arrayattr")) - .addUpdate(AddValueUpdate(IntFieldValue(123))) - .addUpdate(AddValueUpdate(IntFieldValue(456))))); + .addUpdate(std::make_unique<AddValueUpdate>(IntFieldValue(123))) + .addUpdate(std::make_unique<AddValueUpdate>(IntFieldValue(456))))); up->addUpdate(std::move(FieldUpdate(type->getField("arrayattr")) - .addUpdate(RemoveValueUpdate(IntFieldValue(123))) - .addUpdate(RemoveValueUpdate(IntFieldValue(456))) - .addUpdate(RemoveValueUpdate(IntFieldValue(789))))); + .addUpdate(std::make_unique<RemoveValueUpdate>(IntFieldValue(123))) + .addUpdate(std::make_unique<RemoveValueUpdate>(IntFieldValue(456))) + .addUpdate(std::make_unique<RemoveValueUpdate>(IntFieldValue(789))))); return up; } diff --git a/document/src/vespa/document/base/forcelink.cpp b/document/src/vespa/document/base/forcelink.cpp index 0462f22784c..500b5cf7fa5 100644 --- a/document/src/vespa/document/base/forcelink.cpp +++ b/document/src/vespa/document/base/forcelink.cpp @@ -14,7 +14,7 @@ ForceLink::ForceLink(void) DocumentType type("foo", 1); Document document(type, DocumentId("doc:ns:bar")); DocumentUpdate documentUpdate; - MapValueUpdate mapValueUpdate(IntFieldValue(3), ClearValueUpdate()); + MapValueUpdate mapValueUpdate(IntFieldValue(3), std::make_unique<ClearValueUpdate>()); AddValueUpdate addValueUpdate(IntFieldValue(3)); RemoveValueUpdate removeValueUpdate(IntFieldValue(3)); AssignValueUpdate assignValueUpdate(IntFieldValue(3)); diff --git a/document/src/vespa/document/update/addvalueupdate.h b/document/src/vespa/document/update/addvalueupdate.h index 0707e575e50..ee7f6fbcdf2 100644 --- a/document/src/vespa/document/update/addvalueupdate.h +++ b/document/src/vespa/document/update/addvalueupdate.h @@ -67,7 +67,6 @@ public: void printXml(XmlOutputStream& xos) const override; void print(std::ostream& out, bool verbose, const std::string& indent) const override; void deserialize(const DocumentTypeRepo& repo, const DataType& type, nbostream & buffer) override; - AddValueUpdate* clone() const override { return new AddValueUpdate(*this); } DECLARE_IDENTIFIABLE(AddValueUpdate); }; diff --git a/document/src/vespa/document/update/arithmeticvalueupdate.h b/document/src/vespa/document/update/arithmeticvalueupdate.h index f7673adf9c4..cb86528fce5 100644 --- a/document/src/vespa/document/update/arithmeticvalueupdate.h +++ b/document/src/vespa/document/update/arithmeticvalueupdate.h @@ -91,7 +91,6 @@ public: void printXml(XmlOutputStream& xos) const override; void print(std::ostream& out, bool verbose, const std::string& indent) const override; void deserialize(const DocumentTypeRepo& repo, const DataType& type, nbostream & buffer) override; - ArithmeticValueUpdate* clone() const override { return new ArithmeticValueUpdate(*this); } DECLARE_IDENTIFIABLE(ArithmeticValueUpdate); }; diff --git a/document/src/vespa/document/update/assignvalueupdate.h b/document/src/vespa/document/update/assignvalueupdate.h index c877236199c..e829e80da45 100644 --- a/document/src/vespa/document/update/assignvalueupdate.h +++ b/document/src/vespa/document/update/assignvalueupdate.h @@ -43,7 +43,6 @@ public: void printXml(XmlOutputStream& xos) const override; void print(std::ostream& out, bool verbose, const std::string& indent) const override; void deserialize(const DocumentTypeRepo& repo, const DataType& type, nbostream & buffer) override; - AssignValueUpdate* clone() const override { return new AssignValueUpdate(*this); } DECLARE_IDENTIFIABLE(AssignValueUpdate); }; diff --git a/document/src/vespa/document/update/clearvalueupdate.h b/document/src/vespa/document/update/clearvalueupdate.h index 49aa958c103..6e0d800dd73 100644 --- a/document/src/vespa/document/update/clearvalueupdate.h +++ b/document/src/vespa/document/update/clearvalueupdate.h @@ -25,7 +25,6 @@ public: void printXml(XmlOutputStream& xos) const override; void print(std::ostream& out, bool verbose, const std::string& indent) const override; void deserialize(const DocumentTypeRepo& repo, const DataType& type, nbostream& buffer) override; - ClearValueUpdate* clone() const override { return new ClearValueUpdate(*this); } DECLARE_IDENTIFIABLE(ClearValueUpdate); }; diff --git a/document/src/vespa/document/update/fieldupdate.cpp b/document/src/vespa/document/update/fieldupdate.cpp index d0941acbfee..54d0a572bc4 100644 --- a/document/src/vespa/document/update/fieldupdate.cpp +++ b/document/src/vespa/document/update/fieldupdate.cpp @@ -54,9 +54,9 @@ FieldUpdate::operator==(const FieldUpdate& other) const FieldUpdate& -FieldUpdate::addUpdate(const ValueUpdate& update) { - update.checkCompatibility(_field); // May throw exception. - _updates.push_back(std::unique_ptr<ValueUpdate>(update.clone())); +FieldUpdate::addUpdate(std::unique_ptr<ValueUpdate> update) { + update->checkCompatibility(_field); // May throw exception. + _updates.push_back(std::move(update)); return *this; } diff --git a/document/src/vespa/document/update/fieldupdate.h b/document/src/vespa/document/update/fieldupdate.h index 686c3a32d19..f5902c39216 100644 --- a/document/src/vespa/document/update/fieldupdate.h +++ b/document/src/vespa/document/update/fieldupdate.h @@ -53,7 +53,7 @@ public: * @param update A pointer to the value update to add to this. * @return A pointer to this. */ - FieldUpdate& addUpdate(const ValueUpdate& update); + FieldUpdate& addUpdate(std::unique_ptr<ValueUpdate> update); const ValueUpdate& operator[](int index) const { return *_updates[index]; } ValueUpdate& operator[](int index) { return *_updates[index]; } diff --git a/document/src/vespa/document/update/mapvalueupdate.cpp b/document/src/vespa/document/update/mapvalueupdate.cpp index 7418d35793b..c3d9cff571b 100644 --- a/document/src/vespa/document/update/mapvalueupdate.cpp +++ b/document/src/vespa/document/update/mapvalueupdate.cpp @@ -18,14 +18,24 @@ namespace document { IMPLEMENT_IDENTIFIABLE(MapValueUpdate, ValueUpdate); -MapValueUpdate::MapValueUpdate(const FieldValue& key, const ValueUpdate& update) +MapValueUpdate::MapValueUpdate(const FieldValue& key, std::unique_ptr<ValueUpdate> update) : ValueUpdate(), _key(key.clone()), - _update(update.clone()) + _update(std::move(update)) {} -MapValueUpdate::MapValueUpdate(const MapValueUpdate &) = default; -MapValueUpdate & MapValueUpdate::operator = (const MapValueUpdate &) = default; +MapValueUpdate::MapValueUpdate(const MapValueUpdate &) + : ValueUpdate(), + _key(), + _update() +{ + abort(); // TODO Will never be called, remove +} +MapValueUpdate & +MapValueUpdate::operator = (const MapValueUpdate &) { + abort(); // TODO Will never be called, remove + return *this; +} MapValueUpdate::~MapValueUpdate() = default; bool diff --git a/document/src/vespa/document/update/mapvalueupdate.h b/document/src/vespa/document/update/mapvalueupdate.h index 8ec57473aa5..722255dd8d6 100644 --- a/document/src/vespa/document/update/mapvalueupdate.h +++ b/document/src/vespa/document/update/mapvalueupdate.h @@ -17,15 +17,6 @@ namespace document { class MapValueUpdate : public ValueUpdate { - FieldValue::CP _key; // The field value this update is mapping to. - ValueUpdate::CP _update; //The update to apply to the value member of this. - - // Used by ValueUpdate's static factory function - // Private because it generates an invalid object. - friend class ValueUpdate; - MapValueUpdate() : ValueUpdate(), _key(), _update() {} - - ACCEPT_UPDATE_VISITOR; public: /** @@ -35,13 +26,13 @@ public: * @param key The identifier of the field value to be updated. * @param update The update to map to apply to the field value of this. */ - MapValueUpdate(const FieldValue& key, const ValueUpdate& update); + MapValueUpdate(const FieldValue& key, std::unique_ptr<ValueUpdate> update); MapValueUpdate(const MapValueUpdate &); MapValueUpdate & operator = (const MapValueUpdate &); MapValueUpdate(MapValueUpdate &&) = default; MapValueUpdate & operator = (MapValueUpdate &&) = default; - ~MapValueUpdate(); + ~MapValueUpdate() override; bool operator==(const ValueUpdate& other) const override; @@ -52,24 +43,13 @@ public: ValueUpdate& getUpdate() { return *_update; } /** - * Sets the identifier of the field value to update. - * - * @param key The field value identifier. - * @return A pointer to this. - */ - MapValueUpdate& setKey(const FieldValue& key) { - _key.reset(key.clone()); - return *this; - } - - /** * Sets the update to apply to the value update of this. * * @param update The value update. * @return A pointer to this. */ - MapValueUpdate& setUpdate(const ValueUpdate& update) { - _update.reset(update.clone()); + MapValueUpdate& setUpdate(std::unique_ptr<ValueUpdate> update) { + _update = std::move(update); return *this; } @@ -78,10 +58,18 @@ public: void printXml(XmlOutputStream& xos) const override; void print(std::ostream& out, bool verbose, const std::string& indent) const override; void deserialize(const DocumentTypeRepo& repo, const DataType& type, nbostream& buffer) override; - MapValueUpdate* clone() const override { return new MapValueUpdate(*this); } DECLARE_IDENTIFIABLE(MapValueUpdate); +private: + std::unique_ptr<FieldValue> _key; // The field value this update is mapping to. + std::unique_ptr<ValueUpdate> _update; //The update to apply to the value member of this. + + // Used by ValueUpdate's static factory function + // Private because it generates an invalid object. + friend class ValueUpdate; + MapValueUpdate() : ValueUpdate(), _key(), _update() {} + ACCEPT_UPDATE_VISITOR; }; } diff --git a/document/src/vespa/document/update/removevalueupdate.h b/document/src/vespa/document/update/removevalueupdate.h index 7fc1ee4a4e1..0eea8f69da7 100644 --- a/document/src/vespa/document/update/removevalueupdate.h +++ b/document/src/vespa/document/update/removevalueupdate.h @@ -35,23 +35,11 @@ public: */ const FieldValue& getKey() const { return *_key; } - /** - * Sets the field value to remove during this update. - * - * @param The new field value. - * @return A pointer to this. - */ - RemoveValueUpdate& setKey(const FieldValue& key) { - _key.reset(key.clone()); - return *this; - } - void checkCompatibility(const Field& field) const override; bool applyTo(FieldValue& value) const override; void printXml(XmlOutputStream& xos) const override; void print(std::ostream& out, bool verbose, const std::string& indent) const override; void deserialize(const DocumentTypeRepo& repo, const DataType& type, nbostream& buffer) override; - RemoveValueUpdate* clone() const override { return new RemoveValueUpdate(*this); } DECLARE_IDENTIFIABLE(RemoveValueUpdate); diff --git a/document/src/vespa/document/update/tensor_add_update.cpp b/document/src/vespa/document/update/tensor_add_update.cpp index 1f8aed2d8b4..2d6b6e1d658 100644 --- a/document/src/vespa/document/update/tensor_add_update.cpp +++ b/document/src/vespa/document/update/tensor_add_update.cpp @@ -145,10 +145,4 @@ TensorAddUpdate::deserialize(const DocumentTypeRepo &repo, const DataType &type, deserializer.read(*_tensor); } -TensorAddUpdate* -TensorAddUpdate::clone() const -{ - return new TensorAddUpdate(*this); -} - } diff --git a/document/src/vespa/document/update/tensor_add_update.h b/document/src/vespa/document/update/tensor_add_update.h index 259226b380c..7f2228bff41 100644 --- a/document/src/vespa/document/update/tensor_add_update.h +++ b/document/src/vespa/document/update/tensor_add_update.h @@ -35,7 +35,6 @@ public: void printXml(XmlOutputStream &xos) const override; void print(std::ostream &out, bool verbose, const std::string &indent) const override; void deserialize(const DocumentTypeRepo &repo, const DataType &type, nbostream &stream) override; - TensorAddUpdate* clone() const override; DECLARE_IDENTIFIABLE(TensorAddUpdate); }; diff --git a/document/src/vespa/document/update/tensor_modify_update.cpp b/document/src/vespa/document/update/tensor_modify_update.cpp index 49ea57f28c1..77fd5059b0c 100644 --- a/document/src/vespa/document/update/tensor_modify_update.cpp +++ b/document/src/vespa/document/update/tensor_modify_update.cpp @@ -253,10 +253,4 @@ TensorModifyUpdate::deserialize(const DocumentTypeRepo &repo, const DataType &ty verifyCellsTensorIsSparse(_tensor->getAsTensorPtr()); } -TensorModifyUpdate* -TensorModifyUpdate::clone() const -{ - return new TensorModifyUpdate(*this); -} - } diff --git a/document/src/vespa/document/update/tensor_modify_update.h b/document/src/vespa/document/update/tensor_modify_update.h index b721ec70a0b..b6d339a36cf 100644 --- a/document/src/vespa/document/update/tensor_modify_update.h +++ b/document/src/vespa/document/update/tensor_modify_update.h @@ -49,7 +49,6 @@ public: void printXml(XmlOutputStream &xos) const override; void print(std::ostream &out, bool verbose, const std::string &indent) const override; void deserialize(const DocumentTypeRepo &repo, const DataType &type, nbostream &stream) override; - TensorModifyUpdate* clone() const override; DECLARE_IDENTIFIABLE(TensorModifyUpdate); }; diff --git a/document/src/vespa/document/update/tensor_remove_update.cpp b/document/src/vespa/document/update/tensor_remove_update.cpp index f2d11ef8234..69b8b898ec5 100644 --- a/document/src/vespa/document/update/tensor_remove_update.cpp +++ b/document/src/vespa/document/update/tensor_remove_update.cpp @@ -200,10 +200,4 @@ TensorRemoveUpdate::deserialize(const DocumentTypeRepo &repo, const DataType &ty _tensor->assignDeserialized(std::move(tensor)); } -TensorRemoveUpdate * -TensorRemoveUpdate::clone() const -{ - return new TensorRemoveUpdate(*this); -} - } diff --git a/document/src/vespa/document/update/tensor_remove_update.h b/document/src/vespa/document/update/tensor_remove_update.h index bd2817899f5..9b4ea17c4d9 100644 --- a/document/src/vespa/document/update/tensor_remove_update.h +++ b/document/src/vespa/document/update/tensor_remove_update.h @@ -40,7 +40,6 @@ public: void printXml(XmlOutputStream &xos) const override; void print(std::ostream &out, bool verbose, const std::string &indent) const override; void deserialize(const DocumentTypeRepo &repo, const DataType &type, nbostream &stream) override; - TensorRemoveUpdate* clone() const override; DECLARE_IDENTIFIABLE(TensorRemoveUpdate); }; diff --git a/document/src/vespa/document/update/valueupdate.h b/document/src/vespa/document/update/valueupdate.h index 872f883744a..0b52fe46ac9 100644 --- a/document/src/vespa/document/update/valueupdate.h +++ b/document/src/vespa/document/update/valueupdate.h @@ -35,7 +35,6 @@ class ValueUpdate : public vespalib::Identifiable protected: using nbostream = vespalib::nbostream; public: - using CP = vespalib::CloneablePtr<ValueUpdate>; using XmlOutputStream = vespalib::xml::XmlOutputStream; /** @@ -77,8 +76,6 @@ public: */ virtual bool applyTo(FieldValue& value) const = 0; - virtual ValueUpdate* clone() const = 0; - /** * Deserializes the given stream into an instance of an update object. * diff --git a/persistence/src/vespa/persistence/conformancetest/conformancetest.cpp b/persistence/src/vespa/persistence/conformancetest/conformancetest.cpp index 339c72864fa..f46bdaf19f0 100644 --- a/persistence/src/vespa/persistence/conformancetest/conformancetest.cpp +++ b/persistence/src/vespa/persistence/conformancetest/conformancetest.cpp @@ -910,9 +910,8 @@ TEST_F(ConformanceTest, testUpdate) const document::DocumentType *docType( testDocMan.getTypeRepo().getDocumentType("testdoctype1")); document::DocumentUpdate::SP update(new DocumentUpdate(testDocMan.getTypeRepo(), *docType, doc1->getId())); - std::shared_ptr<document::AssignValueUpdate> assignUpdate(new document::AssignValueUpdate(document::IntFieldValue(42))); document::FieldUpdate fieldUpdate(docType->getField("headerval")); - fieldUpdate.addUpdate(*assignUpdate); + fieldUpdate.addUpdate(std::make_unique<document::AssignValueUpdate>(document::IntFieldValue(42))); update->addUpdate(std::move(fieldUpdate)); { diff --git a/searchcore/src/tests/proton/attribute/attribute_test.cpp b/searchcore/src/tests/proton/attribute/attribute_test.cpp index a95d3f7ccca..e64045853d4 100644 --- a/searchcore/src/tests/proton/attribute/attribute_test.cpp +++ b/searchcore/src/tests/proton/attribute/attribute_test.cpp @@ -483,9 +483,9 @@ TEST_F(AttributeWriterTest, handles_update) const document::DocumentType &dt(idb.getDocumentType()); DocumentUpdate upd(*idb.getDocumentTypeRepo(), dt, DocumentId("id:ns:searchdocument::1")); upd.addUpdate(std::move(FieldUpdate(upd.getType().getField("a1")) - .addUpdate(ArithmeticValueUpdate(ArithmeticValueUpdate::Add, 5)))); + .addUpdate(std::make_unique<ArithmeticValueUpdate>(ArithmeticValueUpdate::Add, 5)))); upd.addUpdate(std::move(FieldUpdate(upd.getType().getField("a2")) - .addUpdate(ArithmeticValueUpdate(ArithmeticValueUpdate::Add, 10)))); + .addUpdate(std::make_unique<ArithmeticValueUpdate>(ArithmeticValueUpdate::Add, 10)))); DummyFieldUpdateCallback onUpdate; update(2, upd, 1, onUpdate); @@ -528,7 +528,7 @@ TEST_F(AttributeWriterTest, handles_predicate_update) DocumentUpdate upd(*idb.getDocumentTypeRepo(), dt, DocumentId("id:ns:searchdocument::1")); PredicateFieldValue new_value(builder.feature("foo").value("bar").build()); upd.addUpdate(std::move(FieldUpdate(upd.getType().getField("a1")) - .addUpdate(AssignValueUpdate(new_value)))); + .addUpdate(std::make_unique<AssignValueUpdate>(new_value)))); PredicateIndex &index = static_cast<PredicateAttribute &>(*a1).getIndex(); EXPECT_EQ(1u, index.getZeroConstraintDocs().size()); @@ -729,7 +729,7 @@ TEST_F(AttributeWriterTest, handles_tensor_assign_update) TensorFieldValue new_value(xySparseTensorDataType); new_value = SimpleValue::from_value(*new_tensor); upd.addUpdate(std::move(FieldUpdate(upd.getType().getField("a1")) - .addUpdate(AssignValueUpdate(new_value)))); + .addUpdate(std::make_unique<AssignValueUpdate>(new_value)))); DummyFieldUpdateCallback onUpdate; update(2, upd, 1, onUpdate); EXPECT_EQ(2u, a1->getNumDocs()); @@ -938,7 +938,7 @@ public: TensorDataType tensor_type(vespalib::eval::ValueType::from_spec(dense_tensor)); TensorFieldValue tensor_value(tensor_type); tensor_value= SimpleValue::from_value(*tensor); - upd->addUpdate(std::move(FieldUpdate(upd->getType().getField("a1")).addUpdate(AssignValueUpdate(tensor_value)))); + upd->addUpdate(std::move(FieldUpdate(upd->getType().getField("a1")).addUpdate(std::make_unique<AssignValueUpdate>(tensor_value)))); return upd; } void expect_shared_executor_tasks(size_t exp_accepted_tasks) { diff --git a/searchcore/src/tests/proton/common/attribute_updater/attribute_updater_test.cpp b/searchcore/src/tests/proton/common/attribute_updater/attribute_updater_test.cpp index 924abc81711..20584a2a1fb 100644 --- a/searchcore/src/tests/proton/common/attribute_updater/attribute_updater_test.cpp +++ b/searchcore/src/tests/proton/common/attribute_updater/attribute_updater_test.cpp @@ -97,29 +97,28 @@ struct Fixture { { } - void applyValueUpdate(AttributeVector & vec, uint32_t docId, const ValueUpdate & upd) { + void applyValueUpdate(AttributeVector & vec, uint32_t docId, std::unique_ptr<ValueUpdate> upd) { FieldUpdate fupd(docType->getField(vec.getName())); - fupd.addUpdate(upd); + fupd.addUpdate(std::move(upd)); search::AttributeUpdater::handleUpdate(vec, docId, fupd); vec.commit(); } void applyArrayUpdates(AttributeVector & vec, const FieldValue & assign, const FieldValue & first, const FieldValue & second) { - applyValueUpdate(vec, 0, AssignValueUpdate(assign)); - applyValueUpdate(vec, 1, AddValueUpdate(second)); - applyValueUpdate(vec, 2, RemoveValueUpdate(first)); - applyValueUpdate(vec, 3, ClearValueUpdate()); + applyValueUpdate(vec, 0, std::make_unique<AssignValueUpdate>(assign)); + applyValueUpdate(vec, 1, std::make_unique<AddValueUpdate>(second)); + applyValueUpdate(vec, 2, std::make_unique<RemoveValueUpdate>(first)); + applyValueUpdate(vec, 3, std::make_unique<ClearValueUpdate>()); } void applyWeightedSetUpdates(AttributeVector & vec, const FieldValue & assign, const FieldValue & first, const FieldValue & second) { - applyValueUpdate(vec, 0, AssignValueUpdate(assign)); - applyValueUpdate(vec, 1, AddValueUpdate(second, 20)); - applyValueUpdate(vec, 2, RemoveValueUpdate(first)); - applyValueUpdate(vec, 3, ClearValueUpdate()); - ArithmeticValueUpdate arithmetic(ArithmeticValueUpdate::Add, 10); - applyValueUpdate(vec, 4, MapValueUpdate(first, arithmetic)); + applyValueUpdate(vec, 0, std::make_unique<AssignValueUpdate>(assign)); + applyValueUpdate(vec, 1, std::make_unique<AddValueUpdate>(second, 20)); + applyValueUpdate(vec, 2, std::make_unique<RemoveValueUpdate>(first)); + applyValueUpdate(vec, 3, std::make_unique<ClearValueUpdate>()); + applyValueUpdate(vec, 4, std::make_unique<MapValueUpdate>(first, std::make_unique<ArithmeticValueUpdate>(ArithmeticValueUpdate::Add, 10))); } }; @@ -207,9 +206,9 @@ TEST_F("require that single attributes are updated", Fixture) AttributePtr vec = create<int32_t, IntegerAttribute>(3, 32, 0, "in1/int", Config(bt, ct)); - f.applyValueUpdate(*vec, 0, AssignValueUpdate(IntFieldValue(64))); - f.applyValueUpdate(*vec, 1, ArithmeticValueUpdate(ArithmeticValueUpdate::Add, 10)); - f.applyValueUpdate(*vec, 2, ClearValueUpdate()); + f.applyValueUpdate(*vec, 0, std::make_unique<AssignValueUpdate>(IntFieldValue(64))); + f.applyValueUpdate(*vec, 1, std::make_unique<ArithmeticValueUpdate>(ArithmeticValueUpdate::Add, 10)); + f.applyValueUpdate(*vec, 2, std::make_unique<ClearValueUpdate>()); EXPECT_EQUAL(3u, vec->getNumDocs()); EXPECT_TRUE(check(vec, 0, std::vector<WeightedInt>{WeightedInt(64)})); EXPECT_TRUE(check(vec, 1, std::vector<WeightedInt>{WeightedInt(42)})); @@ -221,9 +220,9 @@ TEST_F("require that single attributes are updated", Fixture) "in1/float", Config(bt, ct)); - f.applyValueUpdate(*vec, 0, AssignValueUpdate(FloatFieldValue(77.7f))); - f.applyValueUpdate(*vec, 1, ArithmeticValueUpdate(ArithmeticValueUpdate::Add, 10)); - f.applyValueUpdate(*vec, 2, ClearValueUpdate()); + f.applyValueUpdate(*vec, 0, std::make_unique<AssignValueUpdate>(FloatFieldValue(77.7f))); + f.applyValueUpdate(*vec, 1, std::make_unique<ArithmeticValueUpdate>(ArithmeticValueUpdate::Add, 10)); + f.applyValueUpdate(*vec, 2, std::make_unique<ClearValueUpdate>()); EXPECT_EQUAL(3u, vec->getNumDocs()); EXPECT_TRUE(check(vec, 0, std::vector<WeightedFloat>{WeightedFloat(77.7f)})); EXPECT_TRUE(check(vec, 1, std::vector<WeightedFloat>{WeightedFloat(65.5f)})); @@ -235,8 +234,8 @@ TEST_F("require that single attributes are updated", Fixture) "in1/string", Config(bt, ct)); - f.applyValueUpdate(*vec, 0, AssignValueUpdate(StringFieldValue("second"))); - f.applyValueUpdate(*vec, 2, ClearValueUpdate()); + f.applyValueUpdate(*vec, 0, std::make_unique<AssignValueUpdate>(StringFieldValue("second"))); + f.applyValueUpdate(*vec, 2, std::make_unique<ClearValueUpdate>()); EXPECT_EQUAL(3u, vec->getNumDocs()); EXPECT_TRUE(check(vec, 0, std::vector<WeightedString>{WeightedString("second")})); EXPECT_TRUE(check(vec, 1, std::vector<WeightedString>{WeightedString("first")})); @@ -255,8 +254,8 @@ TEST_F("require that single attributes are updated", Fixture) asReferenceAttribute(*vec).update(docId, toGid(doc1)); } vec->commit(); - f.applyValueUpdate(*vec, 0, AssignValueUpdate(ReferenceFieldValue(dynamic_cast<const ReferenceDataType &>(f.docType->getField("ref").getDataType()), DocumentId(doc2)))); - f.applyValueUpdate(*vec, 2, ClearValueUpdate()); + f.applyValueUpdate(*vec, 0, std::make_unique<AssignValueUpdate>(ReferenceFieldValue(dynamic_cast<const ReferenceDataType &>(f.docType->getField("ref").getDataType()), DocumentId(doc2)))); + f.applyValueUpdate(*vec, 2, std::make_unique<ClearValueUpdate>()); EXPECT_EQUAL(3u, vec->getNumDocs()); TEST_DO(assertRef(*vec, doc2, 0)); TEST_DO(assertRef(*vec, doc1, 1)); @@ -453,7 +452,7 @@ TEST_F("require that tensor modify update is applied", { f.setTensor(TensorSpec(f.type).add({{"x", 0}}, 3).add({{"x", 1}}, 5)); f.applyValueUpdate(*f.attribute, 1, - TensorModifyUpdate(TensorModifyUpdate::Operation::REPLACE, + std::make_unique<TensorModifyUpdate>(TensorModifyUpdate::Operation::REPLACE, makeTensorFieldValue(TensorSpec("tensor(x{})").add({{"x", "0"}}, 7)))); f.assertTensor(TensorSpec(f.type).add({{"x", 0}}, 7).add({{"x", 1}}, 5)); } @@ -463,7 +462,7 @@ TEST_F("require that tensor add update is applied", { f.setTensor(TensorSpec(f.type).add({{"x", "a"}}, 2)); f.applyValueUpdate(*f.attribute, 1, - TensorAddUpdate(makeTensorFieldValue(TensorSpec(f.type).add({{"x", "a"}}, 3)))); + std::make_unique<TensorAddUpdate>(makeTensorFieldValue(TensorSpec(f.type).add({{"x", "a"}}, 3)))); f.assertTensor(TensorSpec(f.type).add({{"x", "a"}}, 3)); } @@ -471,7 +470,7 @@ TEST_F("require that tensor add update to non-existing tensor creates empty tens TensorFixture<SerializedFastValueAttribute>("tensor(x{})", "sparse_tensor")) { f.applyValueUpdate(*f.attribute, 1, - TensorAddUpdate(makeTensorFieldValue(TensorSpec(f.type).add({{"x", "a"}}, 3)))); + std::make_unique<TensorAddUpdate>(makeTensorFieldValue(TensorSpec(f.type).add({{"x", "a"}}, 3)))); f.assertTensor(TensorSpec(f.type).add({{"x", "a"}}, 3)); } @@ -480,7 +479,7 @@ TEST_F("require that tensor remove update is applied", { f.setTensor(TensorSpec(f.type).add({{"x", "a"}}, 2).add({{"x", "b"}}, 3)); f.applyValueUpdate(*f.attribute, 1, - TensorRemoveUpdate(makeTensorFieldValue(TensorSpec(f.type).add({{"x", "b"}}, 1)))); + std::make_unique<TensorRemoveUpdate>(makeTensorFieldValue(TensorSpec(f.type).add({{"x", "b"}}, 1)))); f.assertTensor(TensorSpec(f.type).add({{"x", "a"}}, 2)); } diff --git a/searchcore/src/tests/proton/documentdb/feedhandler/feedhandler_test.cpp b/searchcore/src/tests/proton/documentdb/feedhandler/feedhandler_test.cpp index c3275d51a1e..8affdde8562 100644 --- a/searchcore/src/tests/proton/documentdb/feedhandler/feedhandler_test.cpp +++ b/searchcore/src/tests/proton/documentdb/feedhandler/feedhandler_test.cpp @@ -345,8 +345,7 @@ struct UpdateContext { } else { fieldValue->assign(document::StringFieldValue("new value")); } - document::AssignValueUpdate assignValueUpdate(*fieldValue); - update->addUpdate(std::move(document::FieldUpdate(field).addUpdate(assignValueUpdate))); + update->addUpdate(std::move(document::FieldUpdate(field).addUpdate(std::make_unique<document::AssignValueUpdate>(*fieldValue)))); } }; @@ -771,11 +770,11 @@ TEST_F("require that update with a fieldpath update will be rejected", SchemaCon TEST_F("require that all value updates will be inspected before rejected", SchemaContext) { const DocumentType *docType = f.getRepo()->getDocumentType(f.getDocType().getName()); auto docUpdate = std::make_unique<DocumentUpdate>(*f.getRepo(), *docType, DocumentId("id:ns:" + docType->getName() + "::1")); - docUpdate->addUpdate(std::move(FieldUpdate(docType->getField("i1")).addUpdate(ClearValueUpdate()))); + docUpdate->addUpdate(std::move(FieldUpdate(docType->getField("i1")).addUpdate(std::make_unique<ClearValueUpdate>()))); EXPECT_FALSE(FeedRejectHelper::mustReject(*docUpdate)); - docUpdate->addUpdate(std::move(FieldUpdate(docType->getField("i1")).addUpdate(ClearValueUpdate()))); + docUpdate->addUpdate(std::move(FieldUpdate(docType->getField("i1")).addUpdate(std::make_unique<ClearValueUpdate>()))); EXPECT_FALSE(FeedRejectHelper::mustReject(*docUpdate)); - docUpdate->addUpdate(std::move(FieldUpdate(docType->getField("i1")).addUpdate(AssignValueUpdate(StringFieldValue())))); + docUpdate->addUpdate(std::move(FieldUpdate(docType->getField("i1")).addUpdate(std::make_unique<AssignValueUpdate>(StringFieldValue())))); EXPECT_TRUE(FeedRejectHelper::mustReject(*docUpdate)); } diff --git a/searchcore/src/tests/proton/feedoperation/feedoperation_test.cpp b/searchcore/src/tests/proton/feedoperation/feedoperation_test.cpp index 2490fac783a..36920f52254 100644 --- a/searchcore/src/tests/proton/feedoperation/feedoperation_test.cpp +++ b/searchcore/src/tests/proton/feedoperation/feedoperation_test.cpp @@ -122,7 +122,7 @@ public: auto makeUpdate() { auto upd(std::make_shared<DocumentUpdate>(*_repo, _docType, docId)); upd->addUpdate(std::move(FieldUpdate(upd->getType().getField("string")). - addUpdate(AssignValueUpdate(StringFieldValue("newval"))))); + addUpdate(std::make_unique<AssignValueUpdate>(StringFieldValue("newval"))))); return upd; } auto makeDoc() { diff --git a/searchcore/src/tests/proton/persistenceengine/persistenceengine_test.cpp b/searchcore/src/tests/proton/persistenceengine/persistenceengine_test.cpp index 2c72b37bc8d..7f35e05dfb6 100644 --- a/searchcore/src/tests/proton/persistenceengine/persistenceengine_test.cpp +++ b/searchcore/src/tests/proton/persistenceengine/persistenceengine_test.cpp @@ -521,7 +521,7 @@ TEST_F("require that update is rejected if resource limit is reached", SimpleFix document::Field field("string", 1, *document::DataType::STRING); type.addField(field); DocumentUpdate::SP upd = createUpd(type, docId1); - upd->addUpdate(std::move(document::FieldUpdate(field).addUpdate(document::AssignValueUpdate(document::StringFieldValue("new value"))))); + upd->addUpdate(std::move(document::FieldUpdate(field).addUpdate(std::make_unique<document::AssignValueUpdate>(document::StringFieldValue("new value"))))); EXPECT_EQUAL( Result(Result::ErrorType::RESOURCE_EXHAUSTED, diff --git a/searchcore/src/vespa/searchcore/bmcluster/bm_feed.cpp b/searchcore/src/vespa/searchcore/bmcluster/bm_feed.cpp index ae1b9ec7fe3..c8a7f3336e0 100644 --- a/searchcore/src/vespa/searchcore/bmcluster/bm_feed.cpp +++ b/searchcore/src/vespa/searchcore/bmcluster/bm_feed.cpp @@ -71,7 +71,7 @@ BmFeed::make_document_update(uint32_t n, uint32_t i) const { auto id = make_document_id(n, i); auto document_update = std::make_unique<DocumentUpdate>(*_repo, *_document_type, id); - document_update->addUpdate(std::move(FieldUpdate(_field).addUpdate(AssignValueUpdate(IntFieldValue(15))))); + document_update->addUpdate(std::move(FieldUpdate(_field).addUpdate(std::make_unique<AssignValueUpdate>(IntFieldValue(15))))); return document_update; } diff --git a/searchlib/src/tests/attribute/attribute_test.cpp b/searchlib/src/tests/attribute/attribute_test.cpp index 73dd7d2f776..ea8a1649789 100644 --- a/searchlib/src/tests/attribute/attribute_test.cpp +++ b/searchlib/src/tests/attribute/attribute_test.cpp @@ -1514,11 +1514,11 @@ AttributeTest::testMapValueUpdate(const AttributePtr & ptr, BufferType initValue EXPECT_EQUAL(ptr->getStatus().getUpdateCount(), 7u); EXPECT_EQUAL(ptr->getStatus().getNonIdempotentUpdateCount(), 0u); - EXPECT_TRUE(ptr->apply(0, MapVU(initFieldValue, ArithVU(ArithVU::Add, 10)))); - EXPECT_TRUE(ptr->apply(1, MapVU(initFieldValue, ArithVU(ArithVU::Sub, 10)))); - EXPECT_TRUE(ptr->apply(2, MapVU(initFieldValue, ArithVU(ArithVU::Mul, 10)))); - EXPECT_TRUE(ptr->apply(3, MapVU(initFieldValue, ArithVU(ArithVU::Div, 10)))); - EXPECT_TRUE(ptr->apply(6, MapVU(initFieldValue, AssignValueUpdate(IntFieldValue(70))))); + EXPECT_TRUE(ptr->apply(0, MapVU(initFieldValue, std::make_unique<ArithVU>(ArithVU::Add, 10)))); + EXPECT_TRUE(ptr->apply(1, MapVU(initFieldValue, std::make_unique<ArithVU>(ArithVU::Sub, 10)))); + EXPECT_TRUE(ptr->apply(2, MapVU(initFieldValue, std::make_unique<ArithVU>(ArithVU::Mul, 10)))); + EXPECT_TRUE(ptr->apply(3, MapVU(initFieldValue, std::make_unique<ArithVU>(ArithVU::Div, 10)))); + EXPECT_TRUE(ptr->apply(6, MapVU(initFieldValue, std::make_unique<AssignValueUpdate>(IntFieldValue(70))))); ptr->commit(); EXPECT_EQUAL(ptr->getStatus().getUpdateCount(), 12u); EXPECT_EQUAL(ptr->getStatus().getNonIdempotentUpdateCount(), 5u); @@ -1536,7 +1536,7 @@ AttributeTest::testMapValueUpdate(const AttributePtr & ptr, BufferType initValue EXPECT_EQUAL(buf[0].getWeight(), 70); // removeifzero - EXPECT_TRUE(ptr->apply(4, MapVU(initFieldValue, ArithVU(ArithVU::Sub, 100)))); + EXPECT_TRUE(ptr->apply(4, MapVU(initFieldValue, std::make_unique<ArithVU>(ArithVU::Sub, 100)))); ptr->commit(); if (removeIfZero) { EXPECT_EQUAL(ptr->get(4, &buf[0], 2), uint32_t(0)); @@ -1548,7 +1548,7 @@ AttributeTest::testMapValueUpdate(const AttributePtr & ptr, BufferType initValue EXPECT_EQUAL(ptr->getStatus().getNonIdempotentUpdateCount(), 6u); // createifnonexistant - EXPECT_TRUE(ptr->apply(5, MapVU(nonExistant, ArithVU(ArithVU::Add, 10)))); + EXPECT_TRUE(ptr->apply(5, MapVU(nonExistant, std::make_unique<ArithVU>(ArithVU::Add, 10)))); ptr->commit(); if (createIfNonExistant) { EXPECT_EQUAL(ptr->get(5, &buf[0], 2), uint32_t(2)); @@ -1568,7 +1568,7 @@ AttributeTest::testMapValueUpdate(const AttributePtr & ptr, BufferType initValue EXPECT_EQUAL(ptr->getStatus().getUpdateCount(), 15u); ASSERT_TRUE(vec.append(0, initValue.getValue(), 12345)); EXPECT_EQUAL(ptr->getStatus().getUpdateCount(), 16u); - EXPECT_TRUE(ptr->apply(0, MapVU(initFieldValue, ArithVU(ArithVU::Div, 0)))); + EXPECT_TRUE(ptr->apply(0, MapVU(initFieldValue, std::make_unique<ArithVU>(ArithVU::Div, 0)))); EXPECT_EQUAL(ptr->getStatus().getUpdateCount(), 16u); EXPECT_EQUAL(ptr->getStatus().getNonIdempotentUpdateCount(), 7u); ptr->commit(); diff --git a/storage/src/tests/distributor/externaloperationhandlertest.cpp b/storage/src/tests/distributor/externaloperationhandlertest.cpp index 5aa5845ac4c..c7b50b69779 100644 --- a/storage/src/tests/distributor/externaloperationhandlertest.cpp +++ b/storage/src/tests/distributor/externaloperationhandlertest.cpp @@ -595,7 +595,7 @@ TEST_F(ExternalOperationHandlerTest, non_trivial_updates_are_rejected_if_feed_is auto cmd = makeUpdateCommand("testdoctype1", "id:foo:testdoctype1::foo"); const auto* doc_type = _testDocMan.getTypeRepo().getDocumentType("testdoctype1"); document::FieldUpdate upd(doc_type->getField("title")); - upd.addUpdate(document::AssignValueUpdate(document::StringFieldValue("new value"))); + upd.addUpdate(std::make_unique<document::AssignValueUpdate>(document::StringFieldValue("new value"))); cmd->getUpdate()->addUpdate(std::move(upd)); ASSERT_NO_FATAL_FAILURE(start_operation_verify_rejected(std::move(cmd))); diff --git a/storage/src/tests/distributor/twophaseupdateoperationtest.cpp b/storage/src/tests/distributor/twophaseupdateoperationtest.cpp index 7a7e53a1d2c..df786902965 100644 --- a/storage/src/tests/distributor/twophaseupdateoperationtest.cpp +++ b/storage/src/tests/distributor/twophaseupdateoperationtest.cpp @@ -296,7 +296,7 @@ TwoPhaseUpdateOperationTest::sendUpdate(const std::string& bucketState, *_repo, *_doc_type, document::DocumentId("id:ns:" + _doc_type->getName() + "::1")); document::FieldUpdate fup(_doc_type->getField("headerval")); - fup.addUpdate(ArithmeticValueUpdate(ArithmeticValueUpdate::Add, 10)); + fup.addUpdate(std::make_unique<ArithmeticValueUpdate>(ArithmeticValueUpdate::Add, 10)); update->addUpdate(std::move(fup)); } else { // Create an update to a different doctype than the one returned as @@ -306,7 +306,7 @@ TwoPhaseUpdateOperationTest::sendUpdate(const std::string& bucketState, *_repo, *badDocType, document::DocumentId("id:ns:" + _doc_type->getName() + "::1")); document::FieldUpdate fup(badDocType->getField("onlyinchild")); - fup.addUpdate(ArithmeticValueUpdate(ArithmeticValueUpdate::Add, 10)); + fup.addUpdate(std::make_unique<ArithmeticValueUpdate>(ArithmeticValueUpdate::Add, 10)); update->addUpdate(std::move(fup)); } update->setCreateIfNonExistent(options._createIfNonExistent); diff --git a/storage/src/tests/persistence/persistencetestutils.cpp b/storage/src/tests/persistence/persistencetestutils.cpp index 0adeff5bc34..dfb245b2a52 100644 --- a/storage/src/tests/persistence/persistencetestutils.cpp +++ b/storage/src/tests/persistence/persistencetestutils.cpp @@ -225,8 +225,7 @@ PersistenceTestUtils::createBodyUpdate(const document::DocumentId& docId, const { const DocumentType* docType(getTypeRepo()->getDocumentType("testdoctype1")); auto update = std::make_shared<document::DocumentUpdate>(*getTypeRepo(), *docType, docId); - auto assignUpdate = std::make_shared<document::AssignValueUpdate>(updateValue); - update->addUpdate(std::move(document::FieldUpdate(docType->getField("content")).addUpdate(*assignUpdate))); + update->addUpdate(std::move(document::FieldUpdate(docType->getField("content")).addUpdate(std::make_unique<document::AssignValueUpdate>(updateValue)))); return update; } @@ -235,8 +234,7 @@ PersistenceTestUtils::createHeaderUpdate(const document::DocumentId& docId, cons { const DocumentType* docType(getTypeRepo()->getDocumentType("testdoctype1")); auto update = std::make_shared<document::DocumentUpdate>(*getTypeRepo(), *docType, docId); - auto assignUpdate = std::make_shared<document::AssignValueUpdate>(updateValue); - update->addUpdate(std::move(document::FieldUpdate(docType->getField("headerval")).addUpdate(*assignUpdate))); + update->addUpdate(std::move(document::FieldUpdate(docType->getField("headerval")).addUpdate(std::make_unique<document::AssignValueUpdate>(updateValue)))); return update; } diff --git a/storage/src/tests/persistence/testandsettest.cpp b/storage/src/tests/persistence/testandsettest.cpp index 267569b0bc5..30a9886cf44 100644 --- a/storage/src/tests/persistence/testandsettest.cpp +++ b/storage/src/tests/persistence/testandsettest.cpp @@ -159,7 +159,7 @@ std::shared_ptr<api::UpdateCommand> TestAndSetTest::conditional_update_test(bool createIfMissing, api::Timestamp updateTimestamp) { auto docUpdate = std::make_shared<document::DocumentUpdate>(_env->_testDocMan.getTypeRepo(), testDoc->getType(), testDocId); - docUpdate->addUpdate(std::move(document::FieldUpdate(testDoc->getField("content")).addUpdate(document::AssignValueUpdate(NEW_CONTENT)))); + docUpdate->addUpdate(std::move(document::FieldUpdate(testDoc->getField("content")).addUpdate(std::make_unique<document::AssignValueUpdate>(NEW_CONTENT)))); docUpdate->setCreateIfNonExistent(createIfMissing); auto updateUp = std::make_unique<api::UpdateCommand>(BUCKET, docUpdate, updateTimestamp); diff --git a/storageapi/src/tests/mbusprot/storageprotocoltest.cpp b/storageapi/src/tests/mbusprot/storageprotocoltest.cpp index a510ed832e8..88e827dcd5f 100644 --- a/storageapi/src/tests/mbusprot/storageprotocoltest.cpp +++ b/storageapi/src/tests/mbusprot/storageprotocoltest.cpp @@ -245,8 +245,7 @@ TEST_P(StorageProtocolTest, response_metadata_is_propagated) { TEST_P(StorageProtocolTest, update) { auto update = std::make_shared<document::DocumentUpdate>( _docMan.getTypeRepo(), *_testDoc->getDataType(), _testDoc->getId()); - auto assignUpdate = std::make_shared<document::AssignValueUpdate>(document::IntFieldValue(17)); - update->addUpdate(std::move(document::FieldUpdate(_testDoc->getField("headerval")).addUpdate(*assignUpdate))); + update->addUpdate(std::move(document::FieldUpdate(_testDoc->getField("headerval")).addUpdate(std::make_unique<document::AssignValueUpdate>(document::IntFieldValue(17))))); update->addFieldPathUpdate(document::FieldPathUpdate::CP( new document::RemoveFieldPathUpdate("headerval", "testdoctype1.headerval > 0"))); |