summaryrefslogtreecommitdiffstats
path: root/document/src
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2022-03-28 06:42:13 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2022-03-28 10:08:43 +0000
commit02b5efaa3bbc043e50e2c64b968241f842c3cffc (patch)
treeb9f9ea83f0dd49656791439322d5ba3d3b6be0b9 /document/src
parentbb59611ce9611986ee97f19d2bb725dc1d160074 (diff)
Avoid the need for clone by using unique_ptr.
Diffstat (limited to 'document/src')
-rw-r--r--document/src/tests/documentselectparsertest.cpp4
-rw-r--r--document/src/tests/documentupdatetestcase.cpp184
-rw-r--r--document/src/tests/feed_reject_helper_test.cpp2
-rw-r--r--document/src/tests/testxml.cpp14
-rw-r--r--document/src/vespa/document/base/forcelink.cpp2
-rw-r--r--document/src/vespa/document/update/addvalueupdate.h1
-rw-r--r--document/src/vespa/document/update/arithmeticvalueupdate.h1
-rw-r--r--document/src/vespa/document/update/assignvalueupdate.h1
-rw-r--r--document/src/vespa/document/update/clearvalueupdate.h1
-rw-r--r--document/src/vespa/document/update/fieldupdate.cpp6
-rw-r--r--document/src/vespa/document/update/fieldupdate.h2
-rw-r--r--document/src/vespa/document/update/mapvalueupdate.cpp18
-rw-r--r--document/src/vespa/document/update/mapvalueupdate.h38
-rw-r--r--document/src/vespa/document/update/removevalueupdate.h12
-rw-r--r--document/src/vespa/document/update/tensor_add_update.cpp6
-rw-r--r--document/src/vespa/document/update/tensor_add_update.h1
-rw-r--r--document/src/vespa/document/update/tensor_modify_update.cpp6
-rw-r--r--document/src/vespa/document/update/tensor_modify_update.h1
-rw-r--r--document/src/vespa/document/update/tensor_remove_update.cpp6
-rw-r--r--document/src/vespa/document/update/tensor_remove_update.h1
-rw-r--r--document/src/vespa/document/update/valueupdate.h3
21 files changed, 141 insertions, 169 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.
*