summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2022-03-29 09:32:13 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2022-03-29 09:42:53 +0000
commitda37d75e5dad5d7f819329bac3fa17f9bbe370f8 (patch)
tree7daf06a5c021e507b4c83dbdf90dd0144ce304b9
parent407db61990785f6812a0db28cdbfeb4dc8bc1308 (diff)
CloneablePtr -> std::unique_ptr
-rw-r--r--document/src/tests/fieldpathupdatetestcase.cpp159
-rw-r--r--document/src/vespa/document/annotation/annotation.cpp2
-rw-r--r--document/src/vespa/document/annotation/annotation.h13
-rw-r--r--document/src/vespa/document/annotation/spantree.cpp24
-rw-r--r--document/src/vespa/document/annotation/spantree.h2
-rw-r--r--document/src/vespa/document/fieldvalue/serializablearray.h4
-rw-r--r--document/src/vespa/document/update/documentupdate.cpp4
-rw-r--r--document/src/vespa/document/update/documentupdate.h4
-rw-r--r--document/src/vespa/document/update/fieldpathupdate.h9
-rw-r--r--documentapi/src/tests/messages/messages60test.cpp3
-rw-r--r--searchcore/src/tests/proton/documentdb/feedhandler/feedhandler_test.cpp2
-rw-r--r--searchlib/src/vespa/searchlib/index/docbuilder.cpp5
-rw-r--r--storageapi/src/tests/mbusprot/storageprotocoltest.cpp2
-rw-r--r--vespalib/src/tests/memory/memory_test.cpp31
-rw-r--r--vespalib/src/vespa/vespalib/util/memory.h146
15 files changed, 109 insertions, 301 deletions
diff --git a/document/src/tests/fieldpathupdatetestcase.cpp b/document/src/tests/fieldpathupdatetestcase.cpp
index 17b84ecc180..1d72fafa607 100644
--- a/document/src/tests/fieldpathupdatetestcase.cpp
+++ b/document/src/tests/fieldpathupdatetestcase.cpp
@@ -175,8 +175,8 @@ void testSerialize(const DocumentTypeRepo& repo, const DocumentUpdate& a) {
}
EXPECT_EQ(a.getFieldPathUpdates().size(), b->getFieldPathUpdates().size());
for (size_t i(0); i < a.getFieldPathUpdates().size(); i++) {
- const FieldPathUpdate::CP& ua = a.getFieldPathUpdates()[i];
- const FieldPathUpdate::CP& ub = b->getFieldPathUpdates()[i];
+ const auto & ua = a.getFieldPathUpdates()[i];
+ const auto & ub = b->getFieldPathUpdates()[i];
EXPECT_EQ(*ua, *ub);
}
@@ -317,7 +317,7 @@ TEST_F(FieldPathUpdateTestCase, testRemoveField)
EXPECT_EQ(vespalib::string("cocacola"), doc->getValue("strfoo")->getAsString());
//doc->print(std::cerr, true, "");
DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo"));
- docUp.addFieldPathUpdate(FieldPathUpdate::CP(new RemoveFieldPathUpdate("strfoo")));
+ docUp.addFieldPathUpdate(std::make_unique<RemoveFieldPathUpdate>("strfoo"));
docUp.applyTo(*doc);
EXPECT_TRUE(doc->hasValue("strfoo") == false);
}
@@ -337,8 +337,7 @@ TEST_F(FieldPathUpdateTestCase, testApplyRemoveMultiList)
EXPECT_TRUE(doc->hasValue("strarray"));
//doc->print(std::cerr, true, "");
DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo"));
- docUp.addFieldPathUpdate(FieldPathUpdate::CP(
- new RemoveFieldPathUpdate("strarray[$x]", "foobar.strarray[$x] == \"remove val 1\"")));
+ docUp.addFieldPathUpdate(std::make_unique<RemoveFieldPathUpdate>("strarray[$x]", "foobar.strarray[$x] == \"remove val 1\""));
docUp.applyTo(*doc);
{
std::unique_ptr<ArrayFieldValue> strArray = doc->getAs<ArrayFieldValue>(doc->getField("strarray"));
@@ -363,8 +362,7 @@ TEST_F(FieldPathUpdateTestCase, testApplyRemoveMultiList2)
EXPECT_TRUE(doc->hasValue("strarray"));
//doc->print(std::cerr, true, "");
DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo"));
- docUp.addFieldPathUpdate(FieldPathUpdate::CP(
- new RemoveFieldPathUpdate("strarray[$x]", "foobar.strarray[$x] == \"remove val 1\"")));
+ docUp.addFieldPathUpdate(std::make_unique<RemoveFieldPathUpdate>("strarray[$x]", "foobar.strarray[$x] == \"remove val 1\""));
docUp.applyTo(*doc);
{
std::unique_ptr<ArrayFieldValue> strArray = doc->getAs<ArrayFieldValue>(doc->getField("strarray"));
@@ -386,7 +384,7 @@ TEST_F(FieldPathUpdateTestCase, testApplyRemoveEntireListField)
}
//doc->print(std::cerr, true, "");
DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo"));
- docUp.addFieldPathUpdate(FieldPathUpdate::CP(new RemoveFieldPathUpdate("strarray", "")));
+ docUp.addFieldPathUpdate(std::make_unique<RemoveFieldPathUpdate>("strarray", ""));
docUp.applyTo(*doc);
EXPECT_TRUE(!doc->hasValue("strarray"));
}
@@ -404,7 +402,7 @@ TEST_F(FieldPathUpdateTestCase, testApplyRemoveMultiWset)
EXPECT_TRUE(doc->hasValue("strwset"));
//doc->print(std::cerr, true, "");
DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo"));
- docUp.addFieldPathUpdate(FieldPathUpdate::CP(new RemoveFieldPathUpdate("strwset{remove val 1}")));
+ docUp.addFieldPathUpdate(std::make_unique<RemoveFieldPathUpdate>("strwset{remove val 1}"));
docUp.applyTo(*doc);
{
std::unique_ptr<WeightedSetFieldValue> strWset = doc->getAs<WeightedSetFieldValue>(doc->getField("strwset"));
@@ -419,15 +417,13 @@ TEST_F(FieldPathUpdateTestCase, testApplyAssignSingle)
EXPECT_TRUE(doc->hasValue("strfoo") == false);
// Test assignment of non-existing
DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo"));
- docUp.addFieldPathUpdate(FieldPathUpdate::CP(
- new AssignFieldPathUpdate(*doc->getDataType(), "strfoo", std::string(), StringFieldValue("himert"))));
+ docUp.addFieldPathUpdate(std::make_unique<AssignFieldPathUpdate>(*doc->getDataType(), "strfoo", std::string(), StringFieldValue("himert")));
docUp.applyTo(*doc);
EXPECT_TRUE(doc->hasValue("strfoo"));
EXPECT_EQ(vespalib::string("himert"), doc->getValue("strfoo")->getAsString());
// Test overwriting existing
DocumentUpdate docUp2(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo"));
- docUp2.addFieldPathUpdate(FieldPathUpdate::CP(
- new AssignFieldPathUpdate(*doc->getDataType(), "strfoo", std::string(), StringFieldValue("wunderbaum"))));
+ docUp2.addFieldPathUpdate(std::make_unique<AssignFieldPathUpdate>(*doc->getDataType(), "strfoo", std::string(), StringFieldValue("wunderbaum")));
docUp2.applyTo(*doc);
EXPECT_EQ(vespalib::string("wunderbaum"), doc->getValue("strfoo")->getAsString());
}
@@ -438,7 +434,7 @@ TEST_F(FieldPathUpdateTestCase, testApplyAssignMath)
doc->setValue("num", IntFieldValue(34));
DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo"));
- docUp.addFieldPathUpdate(FieldPathUpdate::CP(new AssignFieldPathUpdate("num", "", "($value * 2) / $value")));
+ docUp.addFieldPathUpdate(std::make_unique<AssignFieldPathUpdate>("num", "", "($value * 2) / $value"));
docUp.applyTo(*doc);
EXPECT_EQ(static_cast<const FieldValue&>(IntFieldValue(2)), *doc->getValue("num"));
}
@@ -449,7 +445,7 @@ TEST_F(FieldPathUpdateTestCase, testApplyAssignMathByteToZero)
doc->setValue("byteval", ByteFieldValue(3));
DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo"));
- docUp.addFieldPathUpdate(FieldPathUpdate::CP(new AssignFieldPathUpdate("byteval", "", "$value - 3")));
+ docUp.addFieldPathUpdate(std::make_unique<AssignFieldPathUpdate>("byteval", "", "$value - 3"));
docUp.applyTo(*doc);
EXPECT_EQ(static_cast<const FieldValue&>(ByteFieldValue(0)), *doc->getValue("byteval"));
}
@@ -461,7 +457,7 @@ TEST_F(FieldPathUpdateTestCase, testApplyAssignMathNotModifiedOnUnderflow)
doc->setValue("byteval", ByteFieldValue(low_value));
DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo"));
- docUp.addFieldPathUpdate(FieldPathUpdate::CP(new AssignFieldPathUpdate("byteval", "", "$value - 4")));
+ docUp.addFieldPathUpdate(std::make_unique<AssignFieldPathUpdate>("byteval", "", "$value - 4"));
docUp.applyTo(*doc);
// Over/underflow will happen. You must have control of your data types.
EXPECT_EQ(static_cast<const FieldValue&>(ByteFieldValue((char)(low_value - 4))), *doc->getValue("byteval"));
@@ -473,7 +469,7 @@ TEST_F(FieldPathUpdateTestCase, testApplyAssignMathNotModifiedOnOverflow)
doc->setValue("byteval", ByteFieldValue(127));
DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo"));
- docUp.addFieldPathUpdate(FieldPathUpdate::CP(new AssignFieldPathUpdate("byteval", "", "$value + 200")));
+ docUp.addFieldPathUpdate(std::make_unique<AssignFieldPathUpdate>("byteval", "", "$value + 200"));
docUp.applyTo(*doc);
// Over/underflow will happen. You must have control of your data types.
EXPECT_EQ(static_cast<const FieldValue&>(ByteFieldValue(static_cast<char>(static_cast<int>(127+200)))), *doc->getValue("byteval"));
@@ -486,7 +482,7 @@ TEST_F(FieldPathUpdateTestCase, testApplyAssignMathDivZero)
doc->setValue("num", IntFieldValue(10));
DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo"));
- docUp.addFieldPathUpdate(FieldPathUpdate::CP(new AssignFieldPathUpdate("num", "", "$value / ($value - 10)")));
+ docUp.addFieldPathUpdate(std::make_unique<AssignFieldPathUpdate>("num", "", "$value / ($value - 10)"));
docUp.applyTo(*doc);
EXPECT_EQ(static_cast<const FieldValue&>(IntFieldValue(10)), *doc->getValue("num"));
}
@@ -499,7 +495,7 @@ TEST_F(FieldPathUpdateTestCase, testApplyAssignFieldNotExistingInExpression)
doc->setValue("num", IntFieldValue(10));
DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo"));
- docUp.addFieldPathUpdate(FieldPathUpdate::CP(new AssignFieldPathUpdate("num", "", "foobar.num2 + $value")));
+ docUp.addFieldPathUpdate(std::make_unique<AssignFieldPathUpdate>("num", "", "foobar.num2 + $value"));
docUp.applyTo(*doc);
EXPECT_EQ(static_cast<const FieldValue&>(IntFieldValue(10)), *doc->getValue("num"));
}
@@ -511,7 +507,7 @@ TEST_F(FieldPathUpdateTestCase, testApplyAssignFieldNotExistingInPath)
DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo"));
try {
- docUp.addFieldPathUpdate(FieldPathUpdate::CP(new AssignFieldPathUpdate("nosuchnum", "", "foobar.num + $value")));
+ docUp.addFieldPathUpdate(std::make_unique<AssignFieldPathUpdate>("nosuchnum", "", "foobar.num + $value"));
docUp.applyTo(*doc);
EXPECT_TRUE(false);
} catch (const FieldNotFoundException&) {
@@ -524,7 +520,7 @@ TEST_F(FieldPathUpdateTestCase, testApplyAssignTargetNotExisting)
EXPECT_TRUE(doc->hasValue("num") == false);
DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo"));
- docUp.addFieldPathUpdate(FieldPathUpdate::CP(new AssignFieldPathUpdate("num", "", "$value + 5")));
+ docUp.addFieldPathUpdate(std::make_unique<AssignFieldPathUpdate>("num", "", "$value + 5"));
docUp.applyTo(*doc);
EXPECT_EQ(static_cast<const FieldValue&>(IntFieldValue(5)), *doc->getValue("num"));
}
@@ -541,9 +537,8 @@ TEST_F(FieldPathUpdateTestCase, testAssignSimpleMapValueWithVariable)
DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo"));
// Select on value, not key
- docUp.addFieldPathUpdate(FieldPathUpdate::CP(
- new AssignFieldPathUpdate(*doc->getDataType(),
- "strmap{$x}", "foobar.strmap{$x} == \"bar\"", StringFieldValue("shinyvalue"))));
+ docUp.addFieldPathUpdate(std::make_unique<AssignFieldPathUpdate>(*doc->getDataType(),
+ "strmap{$x}", "foobar.strmap{$x} == \"bar\"", StringFieldValue("shinyvalue")));
docUp.applyTo(*doc);
std::unique_ptr<MapFieldValue> valueNow(doc->getAs<MapFieldValue>(doc->getField("strmap")));
@@ -565,9 +560,9 @@ TEST_F(FieldPathUpdateTestCase, testApplyAssignMathRemoveIfZero)
EXPECT_TRUE(doc->hasValue("num") == true);
DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo"));
- FieldPathUpdate::CP up1(new AssignFieldPathUpdate("num", "", "($value * 2) / $value - 2"));
+ auto up1 = std::make_unique<AssignFieldPathUpdate>("num", "", "($value * 2) / $value - 2");
static_cast<AssignFieldPathUpdate&>(*up1).setRemoveIfZero(true);
- docUp.addFieldPathUpdate(up1);
+ docUp.addFieldPathUpdate(std::move(up1));
docUp.applyTo(*doc);
EXPECT_TRUE(doc->hasValue("num") == false);
@@ -591,8 +586,7 @@ TEST_F(FieldPathUpdateTestCase, testApplyAssignMultiList)
updateArray.add(StringFieldValue("assigned val 1"));
DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo"));
- docUp.addFieldPathUpdate(FieldPathUpdate::CP(
- new AssignFieldPathUpdate(*doc->getDataType(), "strarray", std::string(), updateArray)));
+ docUp.addFieldPathUpdate(std::make_unique<AssignFieldPathUpdate>(*doc->getDataType(), "strarray", std::string(), updateArray));
docUp.applyTo(*doc);
{
std::unique_ptr<ArrayFieldValue> strArray =
@@ -622,8 +616,7 @@ TEST_F(FieldPathUpdateTestCase, testApplyAssignMultiWset)
assignWset.add(StringFieldValue("assigned val 1"), 10);
DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo"));
- docUp.addFieldPathUpdate(FieldPathUpdate::CP(
- new AssignFieldPathUpdate(*doc->getDataType(), "strwset", std::string(), assignWset)));
+ docUp.addFieldPathUpdate(std::make_unique<AssignFieldPathUpdate>(*doc->getDataType(), "strwset", std::string(), assignWset));
//doc->print(std::cerr, true, "");
docUp.applyTo(*doc);
//doc->print(std::cerr, true, "");
@@ -651,10 +644,9 @@ TEST_F(FieldPathUpdateTestCase, testAssignWsetRemoveIfZero)
{
DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo"));
IntFieldValue zeroWeight(0);
- FieldPathUpdate::CP assignUpdate(
- new AssignFieldPathUpdate(*doc->getDataType(), "strwset{you say goodbye}", std::string(), zeroWeight));
+ auto assignUpdate = std::make_unique<AssignFieldPathUpdate>(*doc->getDataType(), "strwset{you say goodbye}", std::string(), zeroWeight);
static_cast<AssignFieldPathUpdate&>(*assignUpdate).setRemoveIfZero(true);
- docUp.addFieldPathUpdate(assignUpdate);
+ docUp.addFieldPathUpdate(std::move(assignUpdate));
//doc->print(std::cerr, true, "");
docUp.applyTo(*doc);
//doc->print(std::cerr, true, "");
@@ -677,8 +669,7 @@ TEST_F(FieldPathUpdateTestCase, testApplyAddMultiList)
adds.add(StringFieldValue("george is getting upset!"));
DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo"));
- docUp.addFieldPathUpdate(FieldPathUpdate::CP(
- new AddFieldPathUpdate(*doc->getDataType(), "strarray", std::string(), adds)));
+ docUp.addFieldPathUpdate(std::make_unique<AddFieldPathUpdate>(*doc->getDataType(), "strarray", std::string(), adds));
//doc->print(std::cerr, true, "");
docUp.applyTo(*doc);
//doc->print(std::cerr, true, "");
@@ -699,15 +690,13 @@ TEST_F(FieldPathUpdateTestCase, testAddAndAssignList)
}
DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo"));
- docUp.addFieldPathUpdate(FieldPathUpdate::CP(
- new AssignFieldPathUpdate(*doc->getDataType(),
- "strarray[1]", std::string(), StringFieldValue("assigned val 1"))));
+ docUp.addFieldPathUpdate(std::make_unique<AssignFieldPathUpdate>(*doc->getDataType(),
+ "strarray[1]", std::string(), StringFieldValue("assigned val 1")));
ArrayFieldValue adds(doc->getType().getField("strarray").getDataType());
adds.add(StringFieldValue("new value"));
- docUp.addFieldPathUpdate(FieldPathUpdate::CP(new AddFieldPathUpdate(*doc->getDataType(), "strarray",
- std::string(), adds)));
+ docUp.addFieldPathUpdate(std::make_unique<AddFieldPathUpdate>(*doc->getDataType(), "strarray", std::string(), adds));
//doc->print(std::cerr, true, "");
docUp.applyTo(*doc);
//doc->print(std::cerr, true, "");
@@ -780,8 +769,7 @@ TEST_F(FieldPathUpdateTestCase, testAssignMap)
Fixture f(*_foobar_type, k);
DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo"));
- docUp.addFieldPathUpdate(FieldPathUpdate::CP(
- new AssignFieldPathUpdate(*f.doc->getDataType(), "structmap{" + k.key2 + "}", std::string(), f.fv4)));
+ docUp.addFieldPathUpdate(std::make_unique<AssignFieldPathUpdate>(*f.doc->getDataType(), "structmap{" + k.key2 + "}", std::string(), f.fv4));
docUp.applyTo(*f.doc);
std::unique_ptr<MapFieldValue> valueNow = f.doc->getAs<MapFieldValue>(f.doc->getField("structmap"));
@@ -800,9 +788,8 @@ TEST_F(FieldPathUpdateTestCase, testAssignMapStruct)
Fixture f(*_foobar_type, k);
DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo"));
- docUp.addFieldPathUpdate(FieldPathUpdate::CP(
- new AssignFieldPathUpdate(*f.doc->getDataType(), "structmap{" + k.key2 + "}.rating",
- std::string(), IntFieldValue(48))));
+ docUp.addFieldPathUpdate(std::make_unique<AssignFieldPathUpdate>(*f.doc->getDataType(), "structmap{" + k.key2 + "}.rating",
+ std::string(), IntFieldValue(48)));
docUp.applyTo(*f.doc);
std::unique_ptr<MapFieldValue> valueNow = f.doc->getAs<MapFieldValue>(f.doc->getField("structmap"));
@@ -821,9 +808,8 @@ TEST_F(FieldPathUpdateTestCase, testAssignMapStructVariable)
Fixture f(*_foobar_type, k);
DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo"));
- docUp.addFieldPathUpdate(FieldPathUpdate::CP(
- new AssignFieldPathUpdate(*f.doc->getDataType(), "structmap{$x}.rating",
- "foobar.structmap{$x}.title == \"farnsworth\"", IntFieldValue(48))));
+ docUp.addFieldPathUpdate(std::make_unique<AssignFieldPathUpdate>(*f.doc->getDataType(), "structmap{$x}.rating",
+ "foobar.structmap{$x}.title == \"farnsworth\"", IntFieldValue(48)));
f.doc->setRepo(*_repo);
docUp.applyTo(*f.doc);
@@ -847,14 +833,12 @@ TEST_F(FieldPathUpdateTestCase, testAssignMapNoExist)
fv1.setValue("rating", IntFieldValue(30));
DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo"));
- docUp.addFieldPathUpdate(FieldPathUpdate::CP(
- new AssignFieldPathUpdate(*doc->getDataType(), "structmap{foo}", std::string(), fv1)));
+ docUp.addFieldPathUpdate(std::make_unique<AssignFieldPathUpdate>(*doc->getDataType(), "structmap{foo}", std::string(), fv1));
//doc->print(std::cerr, true, "");
docUp.applyTo(*doc);
//doc->print(std::cerr, true, "");
- std::unique_ptr<MapFieldValue> valueNow =
- doc->getAs<MapFieldValue>(doc->getField("structmap"));
+ std::unique_ptr<MapFieldValue> valueNow = doc->getAs<MapFieldValue>(doc->getField("structmap"));
ASSERT_EQ(std::size_t(1), valueNow->size());
EXPECT_EQ(static_cast<FieldValue&>(fv1), *valueNow->get(StringFieldValue("foo")));
}
@@ -869,10 +853,9 @@ TEST_F(FieldPathUpdateTestCase, testAssignMapNoExistNoCreate)
fv1.setValue("rating", IntFieldValue(30));
DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo"));
- FieldPathUpdate::CP assignUpdate(
- new AssignFieldPathUpdate(*doc->getDataType(), "structmap{foo}", std::string(), fv1));
+ auto assignUpdate = std::make_unique<AssignFieldPathUpdate>(*doc->getDataType(), "structmap{foo}", std::string(), fv1);
static_cast<AssignFieldPathUpdate&>(*assignUpdate).setCreateMissingPath(false);
- docUp.addFieldPathUpdate(assignUpdate);
+ docUp.addFieldPathUpdate(std::move(assignUpdate));
//doc->print(std::cerr, true, "");
docUp.applyTo(*doc);
@@ -890,8 +873,7 @@ TEST_F(FieldPathUpdateTestCase, testQuotedStringKey)
Fixture f(*_foobar_type, k);
DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo"));
- docUp.addFieldPathUpdate(FieldPathUpdate::CP(
- new AssignFieldPathUpdate(*f.doc->getDataType(), field_path, std::string(), f.fv4)));
+ docUp.addFieldPathUpdate(std::make_unique<AssignFieldPathUpdate>(*f.doc->getDataType(), field_path, std::string(), f.fv4));
docUp.applyTo(*f.doc);
std::unique_ptr<MapFieldValue> valueNow = f.doc->getAs<MapFieldValue>(f.doc->getField("structmap"));
@@ -918,35 +900,26 @@ TEST_F(FieldPathUpdateTestCase, testEqualityComparison)
DocumentUpdate docUp2(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo"));
EXPECT_TRUE(docUp1 == docUp2);
- FieldPathUpdate::CP assignUp1(new AssignFieldPathUpdate(*doc->getDataType(),
- "structmap{here be dragons}", std::string(), fv4));
- docUp1.addFieldPathUpdate(assignUp1);
+ docUp1.addFieldPathUpdate(std::make_unique<AssignFieldPathUpdate>(*doc->getDataType(), "structmap{here be dragons}", std::string(), fv4));
EXPECT_TRUE(docUp1 != docUp2);
- docUp2.addFieldPathUpdate(assignUp1);
+ docUp2.addFieldPathUpdate(std::make_unique<AssignFieldPathUpdate>(*doc->getDataType(), "structmap{here be dragons}", std::string(), fv4));
EXPECT_TRUE(docUp1 == docUp2);
}
{
DocumentUpdate docUp1(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo"));
DocumentUpdate docUp2(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo"));
// where-clause diff
- FieldPathUpdate::CP assignUp1(new AssignFieldPathUpdate(*doc->getDataType(),
- "structmap{here be dragons}", std::string(), fv4));
- FieldPathUpdate::CP assignUp2(new AssignFieldPathUpdate(*doc->getDataType(),
- "structmap{here be dragons}", "false", fv4));
- docUp1.addFieldPathUpdate(assignUp1);
- docUp2.addFieldPathUpdate(assignUp2);
+ docUp1.addFieldPathUpdate(std::make_unique<AssignFieldPathUpdate>(*doc->getDataType(), "structmap{here be dragons}", std::string(), fv4));
+ docUp2.addFieldPathUpdate(std::make_unique<AssignFieldPathUpdate>(*doc->getDataType(), "structmap{here be dragons}", "false", fv4));
EXPECT_TRUE(docUp1 != docUp2);
}
{
DocumentUpdate docUp1(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo"));
DocumentUpdate docUp2(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo"));
// fieldpath diff
- FieldPathUpdate::CP assignUp1(new AssignFieldPathUpdate(*doc->getDataType(),
- "structmap{here be dragons}", std::string(), fv4));
- FieldPathUpdate::CP assignUp2(new AssignFieldPathUpdate(*doc->getDataType(),
- "structmap{here be kittens}", std::string(), fv4));
- docUp1.addFieldPathUpdate(assignUp1);
- docUp2.addFieldPathUpdate(assignUp2);
+
+ docUp1.addFieldPathUpdate(std::make_unique<AssignFieldPathUpdate>(*doc->getDataType(),"structmap{here be dragons}", std::string(), fv4));
+ docUp2.addFieldPathUpdate(std::make_unique<AssignFieldPathUpdate>(*doc->getDataType(), "structmap{here be kittens}", std::string(), fv4));
EXPECT_TRUE(docUp1 != docUp2);
}
@@ -965,19 +938,17 @@ TEST_F(FieldPathUpdateTestCase, testAffectsDocumentBody)
{
DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo"));
- FieldPathUpdate::CP update1(new AssignFieldPathUpdate(*doc->getDataType(),
- "structmap{janitor}", std::string(), fv4));
+ auto update1 = std::make_unique<AssignFieldPathUpdate>(*doc->getDataType(), "structmap{janitor}", std::string(), fv4);
static_cast<AssignFieldPathUpdate&>(*update1).setCreateMissingPath(true);
- docUp.addFieldPathUpdate(update1);
+ docUp.addFieldPathUpdate(std::move(update1));
}
// strfoo is header field
{
DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo"));
- FieldPathUpdate::CP update1(new AssignFieldPathUpdate(*doc->getDataType(),
- "strfoo", std::string(), StringFieldValue("helloworld")));
+ auto update1 = std::make_unique<AssignFieldPathUpdate>(*doc->getDataType(), "strfoo", std::string(), StringFieldValue("helloworld"));
static_cast<AssignFieldPathUpdate&>(*update1).setCreateMissingPath(true);
- docUp.addFieldPathUpdate(update1);
+ docUp.addFieldPathUpdate(std::move(update1));
}
}
@@ -990,8 +961,7 @@ TEST_F(FieldPathUpdateTestCase, testIncompatibleDataTypeFails)
DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo"));
try {
- FieldPathUpdate::CP update1(new AssignFieldPathUpdate(*doc->getDataType(), "structmap{foo}",
- std::string(), StringFieldValue("bad things")));
+ auto update1 = std::make_unique<AssignFieldPathUpdate>(*doc->getDataType(), "structmap{foo}", std::string(), StringFieldValue("bad things"));
EXPECT_TRUE(false);
} catch (const vespalib::IllegalArgumentException& e) {
// OK
@@ -1009,9 +979,9 @@ TEST_F(FieldPathUpdateTestCase, testSerializeAssign)
DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo"));
- FieldPathUpdate::CP update1(new AssignFieldPathUpdate(*doc->getDataType(), "structmap{ribbit}", "true", val));
+ auto update1 = std::make_unique<AssignFieldPathUpdate>(*doc->getDataType(), "structmap{ribbit}", "true", val);
static_cast<AssignFieldPathUpdate&>(*update1).setCreateMissingPath(true);
- docUp.addFieldPathUpdate(update1);
+ docUp.addFieldPathUpdate(std::move(update1));
testSerialize(*_repo, docUp);
}
@@ -1028,8 +998,7 @@ TEST_F(FieldPathUpdateTestCase, testSerializeAdd)
DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo"));
- FieldPathUpdate::CP update1(new AddFieldPathUpdate(*doc->getDataType(), "strarray", std::string(), adds));
- docUp.addFieldPathUpdate(update1);
+ docUp.addFieldPathUpdate(std::make_unique<AddFieldPathUpdate>(*doc->getDataType(), "strarray", std::string(), adds));
testSerialize(*_repo, docUp);
}
@@ -1041,8 +1010,7 @@ TEST_F(FieldPathUpdateTestCase, testSerializeRemove)
DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo"));
- FieldPathUpdate::CP update1(new RemoveFieldPathUpdate("structmap{ribbit}", std::string()));
- docUp.addFieldPathUpdate(update1);
+ docUp.addFieldPathUpdate(std::make_unique<RemoveFieldPathUpdate>("structmap{ribbit}", std::string()));
testSerialize(*_repo, docUp);
}
@@ -1054,7 +1022,7 @@ TEST_F(FieldPathUpdateTestCase, testSerializeAssignMath)
doc->setValue("num", IntFieldValue(34));
DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo"));
- docUp.addFieldPathUpdate(FieldPathUpdate::CP(new AssignFieldPathUpdate("num", "", "($value * 2) / $value")));
+ docUp.addFieldPathUpdate(std::make_unique<AssignFieldPathUpdate>("num", "", "($value * 2) / $value"));
testSerialize(*_repo, docUp);
}
@@ -1064,17 +1032,17 @@ FieldPathUpdateTestCase::createDocumentUpdateForSerialization(const DocumentType
const DocumentType *docType(repo.getDocumentType("serializetest"));
auto docUp = std::make_unique<DocumentUpdate>(repo, *docType, DocumentId("id:ns:serializetest::xlanguage"));
- FieldPathUpdate::CP assign(new AssignFieldPathUpdate("intfield", "", "3"));
+ auto assign = std::make_unique<AssignFieldPathUpdate>("intfield", "", "3");
static_cast<AssignFieldPathUpdate&>(*assign).setRemoveIfZero(true);
static_cast<AssignFieldPathUpdate&>(*assign).setCreateMissingPath(false);
- docUp->addFieldPathUpdate(assign);
+ docUp->addFieldPathUpdate(std::move(assign));
ArrayFieldValue fArray(docType->getField("arrayoffloatfield").getDataType());
fArray.add(FloatFieldValue(12.0));
fArray.add(FloatFieldValue(5.0));
- docUp->addFieldPathUpdate(FieldPathUpdate::CP(new AddFieldPathUpdate(*docType, "arrayoffloatfield", "", fArray)));
- docUp->addFieldPathUpdate(FieldPathUpdate::CP(new RemoveFieldPathUpdate("intfield", "serializetest.intfield > 0")));
+ docUp->addFieldPathUpdate(std::make_unique<AddFieldPathUpdate>(*docType, "arrayoffloatfield", "", fArray));
+ docUp->addFieldPathUpdate(std::make_unique<RemoveFieldPathUpdate>("intfield", "serializetest.intfield > 0"));
return docUp;
}
@@ -1130,8 +1098,7 @@ TEST_F(FieldPathUpdateTestCase, array_element_update_for_invalid_index_is_ignore
doc->setValue("strarray", str_array);
DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id::foobar::1"));
- docUp.addFieldPathUpdate(FieldPathUpdate::CP(
- new AssignFieldPathUpdate(*doc->getDataType(), "strarray[1]", "", StringFieldValue("george"))));
+ docUp.addFieldPathUpdate(std::make_unique<AssignFieldPathUpdate>(*doc->getDataType(), "strarray[1]", "", StringFieldValue("george")));
docUp.applyTo(*doc);
// Doc is unmodified.
@@ -1155,8 +1122,8 @@ TEST_F(FieldPathUpdateTestCase, update_can_have_removes_for_both_existent_and_no
DocumentUpdate update(*_repo, *_foobar_type, doc_id);
auto update1 = std::make_unique<RemoveFieldPathUpdate>("structmap{coolmovie}", "");
auto update2 = std::make_unique<RemoveFieldPathUpdate>("structmap{no such key}", "");
- update.addFieldPathUpdate(FieldPathUpdate::CP(std::move(update1)));
- update.addFieldPathUpdate(FieldPathUpdate::CP(std::move(update2)));
+ update.addFieldPathUpdate(std::move(update1));
+ update.addFieldPathUpdate(std::move(update2));
update.applyTo(*doc);
auto new_value = doc->getValue("structmap");
diff --git a/document/src/vespa/document/annotation/annotation.cpp b/document/src/vespa/document/annotation/annotation.cpp
index 7e8aeecc4c7..5110df6b616 100644
--- a/document/src/vespa/document/annotation/annotation.cpp
+++ b/document/src/vespa/document/annotation/annotation.cpp
@@ -12,7 +12,7 @@ std::ostream & operator << (std::ostream & os, const Annotation &annotation) {
return os << annotation.toString();
}
-Annotation::~Annotation() { }
+Annotation::~Annotation() = default;
vespalib::string
Annotation::toString() const {
diff --git a/document/src/vespa/document/annotation/annotation.h b/document/src/vespa/document/annotation/annotation.h
index 46e5a1a5d41..e11e449d5d2 100644
--- a/document/src/vespa/document/annotation/annotation.h
+++ b/document/src/vespa/document/annotation/annotation.h
@@ -4,7 +4,6 @@
#include <vespa/document/datatype/annotationtype.h>
#include <vespa/document/fieldvalue/fieldvalue.h>
-#include <memory>
namespace document {
struct SpanNode;
@@ -12,23 +11,25 @@ struct SpanNode;
class Annotation {
const AnnotationType * _type;
const SpanNode *_node;
- FieldValue::CP _value;
+ std::unique_ptr<FieldValue> _value;
public:
- typedef std::unique_ptr<Annotation> UP;
-
template <typename T>
Annotation(const AnnotationType & type, std::unique_ptr<T> value)
- : _type(&type), _node(nullptr), _value(value.release()) {}
+ : _type(&type), _node(nullptr), _value(std::move(value)) {}
Annotation(const AnnotationType &annotation) : _type(&annotation), _node(nullptr), _value(nullptr) { }
Annotation() noexcept : _type(nullptr), _node(nullptr), _value(nullptr) { }
+ Annotation(const Annotation &) = delete;
+ Annotation & operator = (const Annotation &) = delete;
+ Annotation(Annotation &&) = default;
+ Annotation & operator = (Annotation &&) = delete;
~Annotation();
void setType(const AnnotationType * v) { _type = v; }
void setSpanNode(const SpanNode &node) { _node = &node; }
template <typename T>
- void setFieldValue(std::unique_ptr<T> value) { _value.reset(value.release()); }
+ void setFieldValue(std::unique_ptr<T> value) { _value = std::move(value); }
bool operator==(const Annotation &a2) const;
const SpanNode *getSpanNode() const { return _node; }
diff --git a/document/src/vespa/document/annotation/spantree.cpp b/document/src/vespa/document/annotation/spantree.cpp
index 13d018ba029..d483d6c08ca 100644
--- a/document/src/vespa/document/annotation/spantree.cpp
+++ b/document/src/vespa/document/annotation/spantree.cpp
@@ -9,31 +9,37 @@ using vespalib::stringref;
namespace document {
-SpanTree::~SpanTree() { }
+SpanTree::~SpanTree() = default;
-size_t SpanTree::annotate(Annotation::UP annotation_) {
- _annotations.push_back(*annotation_);
+size_t
+SpanTree::annotate(std::unique_ptr<Annotation> annotation_) {
+ _annotations.push_back(std::move(*annotation_));
return _annotations.size() - 1;
}
-size_t SpanTree::annotate(const SpanNode &node, Annotation::UP annotation_) {
+size_t
+SpanTree::annotate(const SpanNode &node, std::unique_ptr<Annotation> annotation_) {
annotation_->setSpanNode(node);
return annotate(std::move(annotation_));
}
-size_t SpanTree::annotate(const SpanNode &node, const AnnotationType &type) {
- return annotate(node, Annotation::UP(new Annotation(type)));
+size_t
+SpanTree::annotate(const SpanNode &node, const AnnotationType &type) {
+ return annotate(node, std::make_unique<Annotation>(type));
}
-void SpanTree::accept(SpanTreeVisitor &visitor) const {
+void
+SpanTree::accept(SpanTreeVisitor &visitor) const {
_root->accept(visitor);
}
-int SpanTree::compare(const SpanTree &other) const {
+int
+SpanTree::compare(const SpanTree &other) const {
return toString().compare(other.toString());
}
-vespalib::string SpanTree::toString() const {
+vespalib::string
+SpanTree::toString() const {
vespalib::asciistream os;
os << "SpanTree(\"" << _name << "\"" << "\n ";
os <<_root->toString();
diff --git a/document/src/vespa/document/annotation/spantree.h b/document/src/vespa/document/annotation/spantree.h
index 0136b61438d..7635350025b 100644
--- a/document/src/vespa/document/annotation/spantree.h
+++ b/document/src/vespa/document/annotation/spantree.h
@@ -11,7 +11,7 @@ struct SpanNode;
struct SpanTreeVisitor;
class SpanTree {
- typedef std::vector<Annotation> AnnotationVector;
+ using AnnotationVector = std::vector<Annotation>;
vespalib::string _name;
std::unique_ptr<SpanNode> _root;
std::vector<Annotation> _annotations;
diff --git a/document/src/vespa/document/fieldvalue/serializablearray.h b/document/src/vespa/document/fieldvalue/serializablearray.h
index 3fef1d21c3c..1d55e2601c2 100644
--- a/document/src/vespa/document/fieldvalue/serializablearray.h
+++ b/document/src/vespa/document/fieldvalue/serializablearray.h
@@ -17,7 +17,6 @@
#pragma once
#include <vespa/vespalib/util/buffer.h>
-#include <vespa/vespalib/util/memory.h>
#include <vespa/document/util/bytebuffer.h>
#include <vector>
@@ -25,8 +24,6 @@
namespace document {
-class ByteBuffer;
-
namespace serializablearray {
class BufferMap;
}
@@ -77,7 +74,6 @@ public:
static const uint32_t ReservedId = 100;
static const uint32_t ReservedIdUpper = 128;
- using CP = vespalib::CloneablePtr<SerializableArray>;
using UP = std::unique_ptr<SerializableArray>;
SerializableArray();
diff --git a/document/src/vespa/document/update/documentupdate.cpp b/document/src/vespa/document/update/documentupdate.cpp
index 89e275bf92d..7a3eb85d3d5 100644
--- a/document/src/vespa/document/update/documentupdate.cpp
+++ b/document/src/vespa/document/update/documentupdate.cpp
@@ -130,9 +130,9 @@ DocumentUpdate::addUpdate(FieldUpdate &&update) {
}
DocumentUpdate&
-DocumentUpdate::addFieldPathUpdate(const FieldPathUpdate::CP& update) {
+DocumentUpdate::addFieldPathUpdate(std::unique_ptr<FieldPathUpdate> update) {
ensureDeserialized();
- _fieldPathUpdates.push_back(update);
+ _fieldPathUpdates.push_back(std::move(update));
reserialize();
return *this;
}
diff --git a/document/src/vespa/document/update/documentupdate.h b/document/src/vespa/document/update/documentupdate.h
index 1afadff2827..192569ba6ee 100644
--- a/document/src/vespa/document/update/documentupdate.h
+++ b/document/src/vespa/document/update/documentupdate.h
@@ -46,7 +46,7 @@ public:
using UP = std::unique_ptr<DocumentUpdate>;
using SP = std::shared_ptr<DocumentUpdate>;
using FieldUpdateV = std::vector<FieldUpdate>;
- using FieldPathUpdateV = std::vector<FieldPathUpdate::CP>;
+ using FieldPathUpdateV = std::vector<std::unique_ptr<FieldPathUpdate>>;
using XmlOutputStream = vespalib::xml::XmlOutputStream;
/**
@@ -88,7 +88,7 @@ public:
void applyTo(Document& doc) const;
DocumentUpdate& addUpdate(FieldUpdate && update);
- DocumentUpdate& addFieldPathUpdate(const FieldPathUpdate::CP& update);
+ DocumentUpdate& addFieldPathUpdate(std::unique_ptr<FieldPathUpdate> update);
/** @return The list of updates. */
const FieldUpdateV & getUpdates() const;
diff --git a/document/src/vespa/document/update/fieldpathupdate.h b/document/src/vespa/document/update/fieldpathupdate.h
index 28faad722d4..327493407a1 100644
--- a/document/src/vespa/document/update/fieldpathupdate.h
+++ b/document/src/vespa/document/update/fieldpathupdate.h
@@ -3,7 +3,6 @@
#include "updatevisitor.h"
#include <vespa/document/base/fieldpath.h>
-#include <vespa/document/util/printable.h>
#include <vespa/document/util/identifiableid.h>
namespace document {
@@ -18,8 +17,7 @@ class DataType;
namespace select { class Node; }
namespace fieldvalue { class IteratorHandler; }
-class FieldPathUpdate : public Printable,
- public vespalib::Identifiable
+class FieldPathUpdate : public vespalib::Identifiable
{
protected:
using nbostream = vespalib::nbostream;
@@ -31,9 +29,6 @@ protected:
static stringref getString(nbostream & stream);
public:
- using SP = std::shared_ptr<FieldPathUpdate>;
- using CP = vespalib::CloneablePtr<FieldPathUpdate>;
-
~FieldPathUpdate() override;
enum FieldPathUpdateType {
@@ -61,7 +56,7 @@ public:
*/
void checkCompatibility(const FieldValue& fv, const DataType & type) const;
- void print(std::ostream& out, bool verbose, const std::string& indent) const override;
+ virtual void print(std::ostream& out, bool verbose, const std::string& indent) const = 0;
DECLARE_IDENTIFIABLE_ABSTRACT(FieldPathUpdate);
diff --git a/documentapi/src/tests/messages/messages60test.cpp b/documentapi/src/tests/messages/messages60test.cpp
index 18111fbd805..f51b071fc70 100644
--- a/documentapi/src/tests/messages/messages60test.cpp
+++ b/documentapi/src/tests/messages/messages60test.cpp
@@ -663,8 +663,7 @@ Messages60Test::testUpdateDocumentMessage()
auto docUpdate = std::make_shared<document::DocumentUpdate>(repo, docType, document::DocumentId("id:ns:testdoc::"));
- docUpdate->addFieldPathUpdate(document::FieldPathUpdate::CP(
- new document::RemoveFieldPathUpdate("intfield", "testdoc.intfield > 0")));
+ docUpdate->addFieldPathUpdate(std::make_unique<document::RemoveFieldPathUpdate>("intfield", "testdoc.intfield > 0"));
UpdateDocumentMessage msg(docUpdate);
msg.setOldTimestamp(666u);
diff --git a/searchcore/src/tests/proton/documentdb/feedhandler/feedhandler_test.cpp b/searchcore/src/tests/proton/documentdb/feedhandler/feedhandler_test.cpp
index 6cd92dea516..79aa681ab52 100644
--- a/searchcore/src/tests/proton/documentdb/feedhandler/feedhandler_test.cpp
+++ b/searchcore/src/tests/proton/documentdb/feedhandler/feedhandler_test.cpp
@@ -763,7 +763,7 @@ using namespace document;
TEST_F("require that update with a fieldpath update will be 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->addFieldPathUpdate(FieldPathUpdate::CP(std::make_unique<RemoveFieldPathUpdate>()));
+ docUpdate->addFieldPathUpdate(std::make_unique<RemoveFieldPathUpdate>());
EXPECT_TRUE(FeedRejectHelper::mustReject(*docUpdate));
}
diff --git a/searchlib/src/vespa/searchlib/index/docbuilder.cpp b/searchlib/src/vespa/searchlib/index/docbuilder.cpp
index 0792dd7be61..d4bf9e86c74 100644
--- a/searchlib/src/vespa/searchlib/index/docbuilder.cpp
+++ b/searchlib/src/vespa/searchlib/index/docbuilder.cpp
@@ -154,11 +154,10 @@ using namespace docbuilderkludge;
namespace {
-Annotation::UP
+std::unique_ptr<Annotation>
makeTokenType(linguistics::TokenType type)
{
- return makeUP(new Annotation(*AnnotationType::TOKEN_TYPE,
- makeUP(new IntFieldValue(type))));
+ return std::make_unique<Annotation>(*AnnotationType::TOKEN_TYPE, std::make_unique<IntFieldValue>(type));
}
}
diff --git a/storageapi/src/tests/mbusprot/storageprotocoltest.cpp b/storageapi/src/tests/mbusprot/storageprotocoltest.cpp
index 40969455d68..1ab5c2398c9 100644
--- a/storageapi/src/tests/mbusprot/storageprotocoltest.cpp
+++ b/storageapi/src/tests/mbusprot/storageprotocoltest.cpp
@@ -252,7 +252,7 @@ TEST_P(StorageProtocolTest, update) {
_docMan.getTypeRepo(), *_testDoc->getDataType(), _testDoc->getId());
update->addUpdate(FieldUpdate(_testDoc->getField("headerval")).addUpdate(std::make_unique<AssignValueUpdate>(IntFieldValue(17))));
- update->addFieldPathUpdate(FieldPathUpdate::CP(new RemoveFieldPathUpdate("headerval", "testdoctype1.headerval > 0")));
+ update->addFieldPathUpdate(std::make_unique<RemoveFieldPathUpdate>("headerval", "testdoctype1.headerval > 0"));
auto cmd = std::make_shared<UpdateCommand>(_bucket, update, 14);
EXPECT_EQ(Timestamp(0), cmd->getOldTimestamp());
diff --git a/vespalib/src/tests/memory/memory_test.cpp b/vespalib/src/tests/memory/memory_test.cpp
index d39fbd672ea..4d7c0b1c4d4 100644
--- a/vespalib/src/tests/memory/memory_test.cpp
+++ b/vespalib/src/tests/memory/memory_test.cpp
@@ -25,50 +25,25 @@ public:
int Main() override;
};
-B* fn(auto_arr<B> param) { return param.get(); }
-auto_arr<B> fn(B *param) { auto_arr<B> bb(param); return bb; }
-
int
Test::Main()
{
TEST_INIT("memory_test");
{
- B* p = new B[5];
- auto_arr<B> apb(p);
- EXPECT_TRUE(apb.get() == p);
- EXPECT_TRUE(fn(apb) == p);
- EXPECT_TRUE(apb.get() == nullptr);
- }
- {
- A* p = new A[5];
- auto_arr<A> apa(p);
- EXPECT_TRUE(apa.get() == p);
- auto_arr<A> apb = apa;
- EXPECT_TRUE(apa.get() == nullptr);
- EXPECT_TRUE(apb.get() == p);
- A& ref = apb[2];
- EXPECT_TRUE(&ref == (p+2));
- }
- {
- B* p = new B[5];
- auto_arr<B> apb = fn(p);
- EXPECT_TRUE(apb.get() == p);
- }
- {
MallocAutoPtr a(malloc(30));
EXPECT_TRUE(a.get() != nullptr);
void * tmp = a.get();
- MallocAutoPtr b(a);
+ MallocAutoPtr b(std::move(a));
EXPECT_TRUE(tmp == b.get());
EXPECT_TRUE(a.get() == nullptr);
MallocAutoPtr c;
- c = b;
+ c = std::move(b);
EXPECT_TRUE(b.get() == nullptr);
EXPECT_TRUE(tmp == c.get());
MallocAutoPtr d(malloc(30));
EXPECT_TRUE(d.get() != nullptr);
tmp = c.get();
- d = c;
+ d = std::move(c);
EXPECT_TRUE(tmp == d.get());
EXPECT_TRUE(c.get() == nullptr);
}
diff --git a/vespalib/src/vespa/vespalib/util/memory.h b/vespalib/src/vespa/vespalib/util/memory.h
index 0391a7730f5..da164eba0a6 100644
--- a/vespalib/src/vespa/vespalib/util/memory.h
+++ b/vespalib/src/vespa/vespalib/util/memory.h
@@ -12,110 +12,6 @@
namespace vespalib {
/**
- * @brief Helper class
- *
- * Helper to enable auto_arr instances as parameters and return values.
- * You should not use this class directly.
- **/
-template<class OtherArray> struct auto_arr_ref {
- OtherArray* _array;
- auto_arr_ref(OtherArray* a) : _array(a) {}
-};
-
-/**
- * @brief std::unique_ptr for arrays
- *
- * This class behaves just like unique_ptr, but wraps a pointer allocated
- * with new[]; so it will call delete[] when doing cleanup.
- */
-template <class Array> class auto_arr {
-private:
- Array* _array; // actual owned array (if any)
-
-public:
- /**
- * @brief constructor from pointer
- *
- * Note: the pointer must have been allocated with new[]
- **/
- explicit auto_arr(Array* a = 0) throw() : _array(a) {}
-
- /**
- * @brief "copy" contructor
- *
- * Note: non-const parameter; transfers ownership
- * instead of copying.
- **/
- auto_arr(auto_arr& a) throw() : _array(a.release()) {}
-
- /**
- * @brief assignment operator
- *
- * Note: non-const parameter; transfers ownership
- * instead of copying.
- **/
- auto_arr& operator=(auto_arr& a) throw() {
- reset(a.release());
- return *this;
- }
-
- /** @brief destructor, calls delete[] on owned pointer */
- ~auto_arr() throw() { delete[] _array; }
-
- /** @brief value access */
- Array& operator [] (size_t i) const throw() { return _array[i]; }
-
- /** @brief access underlying array */
- Array* get() const throw() { return _array; }
-
- /**
- * @brief release ownership
- *
- * The caller of release() must take responsibility for eventually calling delete[].
- * @return previously owned pointer
- **/
- Array* release() throw() {
- Array* tmp = _array;
- _array = 0;
- return tmp;
- }
-
- /**
- * @brief reset value
- *
- * Behaves like destruct then construct.
- **/
- void reset(Array* a = 0) throw() {
- delete[] _array;
- _array = a;
- }
-
- /**
- * @brief special implicit conversion from auxiliary type
- * to enable parameter / return value passing
- **/
- auto_arr(auto_arr_ref<Array> ref) throw()
- : _array(ref._array) {}
-
- /**
- * @brief special assignment from auxiliary type
- * to enable parameter / return value passing
- **/
- auto_arr& operator=(auto_arr_ref<Array> ref) throw() {
- reset(ref._array);
- return *this;
- }
-
- /**
- * @brief special implicit conversion to auxiliary type
- * to enable parameter / return value passing
- **/
- operator auto_arr_ref<Array>() throw() {
- return auto_arr_ref<Array>(this->release());
- }
-};
-
-/**
* @brief Keep ownership of memory allocated via malloc()
*
* A MallocAutoPtr does for c type alloced objects as std::unique_ptr does
@@ -130,51 +26,25 @@ public:
*
* Note: the pointer must have been allocated with malloc()
**/
- MallocAutoPtr(void *p=nullptr) : _p(p) { }
+ MallocAutoPtr(void *p=nullptr) noexcept : _p(p) { }
/** @brief destructor, calls free() on owned pointer */
~MallocAutoPtr() { cleanup(); }
- MallocAutoPtr(MallocAutoPtr && rhs) : _p(rhs._p) { rhs._p = nullptr; }
- MallocAutoPtr & operator = (MallocAutoPtr && rhs) {
+ MallocAutoPtr(MallocAutoPtr && rhs) noexcept : _p(rhs._p) { rhs._p = nullptr; }
+ MallocAutoPtr & operator = (MallocAutoPtr && rhs) noexcept {
cleanup();
std::swap(_p, rhs._p);
return *this;
}
- /**
- * @brief "copy" contructor
- *
- * Note: non-const parameter; transfers ownership
- * instead of copying.
- **/
- MallocAutoPtr(const MallocAutoPtr & rhs)
- : _p(rhs._p) { const_cast<MallocAutoPtr &>(rhs)._p = nullptr; }
+ MallocAutoPtr(const MallocAutoPtr & rhs) = delete;
+ MallocAutoPtr & operator = (const MallocAutoPtr & rhs) = delete;
- /**
- * @brief assignment operator
- *
- * Note: non-const parameter; transfers ownership
- * instead of copying.
- **/
- MallocAutoPtr & operator = (const MallocAutoPtr & rhs) {
- if (this != &rhs) {
- MallocAutoPtr tmp(rhs);
- swap(tmp);
- }
- return *this;
- }
-
- /** @brief swap contents */
- void swap(MallocAutoPtr & rhs) { std::swap(_p, rhs._p); }
-
- /** @brief value access */
- const void * get() const { return _p; }
-
- /** @brief value access */
- void * get() { return _p; }
+ const void * get() const noexcept { return _p; }
+ void * get() noexcept { return _p; }
private:
- void cleanup() {
+ void cleanup() noexcept {
if (_p) {
free(_p);
_p = nullptr;