diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2022-03-07 08:14:04 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2022-03-07 08:14:04 +0000 |
commit | e658f2c3499901cf7e7750ca3d5be0e6e6953e8c (patch) | |
tree | 6b297ebd65ab7ea1c7970420982c0a3f6f9c2123 /document/src | |
parent | 2e05df2de19c2d5b87befa2ee6c4fd182dcb5630 (diff) |
GC redundant convenience wasy of assigning primitive field values.
Diffstat (limited to 'document/src')
23 files changed, 78 insertions, 303 deletions
diff --git a/document/src/tests/documentselectparsertest.cpp b/document/src/tests/documentselectparsertest.cpp index 8308c3bc693..3d2e4e983d7 100644 --- a/document/src/tests/documentselectparsertest.cpp +++ b/document/src/tests/documentselectparsertest.cpp @@ -153,18 +153,18 @@ DocumentSelectParserTest::createDocs() // Add some arrays and structs to doc 1 { StructFieldValue sval(_doc.back()->getField("mystruct").getDataType()); - sval.set("key", 14); - sval.set("value", "structval"); + sval.setValue("key", std::make_unique<IntFieldValue>(14)); + sval.setValue("value", std::make_unique<StringFieldValue>("structval")); _doc.back()->setValue("mystruct", sval); ArrayFieldValue aval(_doc.back()->getField("structarray").getDataType()); { StructFieldValue sval1(aval.getNestedType()); - sval1.set("key", 15); - sval1.set("value", "structval1"); + sval1.setValue("key", std::make_unique<IntFieldValue>(15)); + sval1.setValue("value", std::make_unique<StringFieldValue>("structval1")); StructFieldValue sval2(aval.getNestedType()); - sval2.set("key", 16); - sval2.set("value", "structval2"); + sval2.setValue("key", std::make_unique<IntFieldValue>(16)); + sval2.setValue("value", std::make_unique<StringFieldValue>("structval2")); aval.add(sval1); aval.add(sval2); } @@ -182,11 +182,11 @@ DocumentSelectParserTest::createDocs() ArrayFieldValue abval(_doc.back()->getField("structarray").getDataType()); { StructFieldValue sval1(aval.getNestedType()); - sval1.set("key", 17); - sval1.set("value", "structval3"); + sval1.setValue("key", std::make_unique<IntFieldValue>(17)); + sval1.setValue("value", std::make_unique<StringFieldValue>("structval3")); StructFieldValue sval2(aval.getNestedType()); - sval2.set("key", 18); - sval2.set("value", "structval4"); + sval2.setValue("key", std::make_unique<IntFieldValue>(18)); + sval2.setValue("value", std::make_unique<StringFieldValue>("structval4")); abval.add(sval1); abval.add(sval2); } diff --git a/document/src/tests/documenttestcase.cpp b/document/src/tests/documenttestcase.cpp index bcf0cbad5fe..73d94452b28 100644 --- a/document/src/tests/documenttestcase.cpp +++ b/document/src/tests/documenttestcase.cpp @@ -707,15 +707,15 @@ TEST(DocumentTest,testReadSerializedAllVersions) // Create a memory instance of document { Document doc(*docType, DocumentId("id:ns:serializetest::http://test.doc.id/")); - doc.set("intfield", 5); - doc.set("floatfield", -9.23); - doc.set("stringfield", "This is a string."); - doc.set("longfield", static_cast<int64_t>(398420092938472983LL)); - doc.set("doublefield", 98374532.398820); - doc.set("bytefield", -2); - doc.setValue("rawfield", RawFieldValue("RAW DATA", 8)); + doc.setValue("intfield", std::make_unique<IntFieldValue>(5)); + doc.setValue("floatfield", std::make_unique<FloatFieldValue>(-9.23)); + doc.setValue("stringfield", std::make_unique<StringFieldValue>("This is a string.")); + doc.setValue("longfield", std::make_unique<LongFieldValue>(static_cast<int64_t>(398420092938472983LL))); + doc.setValue("doublefield", std::make_unique<DoubleFieldValue>(98374532.398820)); + doc.setValue("bytefield", std::make_unique<ByteFieldValue>(-2)); + doc.setValue("rawfield", std::make_unique<RawFieldValue>("RAW DATA", 8)); Document docInDoc(*docInDocType, DocumentId("id:ns:docindoc::http://doc.in.doc/")); - docInDoc.set("stringindocfield", "Elvis is dead"); + docInDoc.setValue("stringindocfield", std::make_unique<StringFieldValue>("Elvis is dead")); doc.setValue("docfield", docInDoc); ArrayFieldValue floatArray(*arrayOfFloatDataType); CollectionHelper(floatArray).add(1.0); @@ -830,14 +830,14 @@ TEST(DocumentTest, testGenerateSerializedFile) DocumentTypeRepo repo(readDocumenttypesConfig(file_name)); Document doc(*repo.getDocumentType("serializetest"), DocumentId("id:ns:serializetest::http://test.doc.id/")); - doc.set("intfield", 5); - doc.set("floatfield", -9.23); - doc.set("stringfield", "This is a string."); - doc.set("longfield", (int64_t) 398420092938472983ll); - doc.set("doublefield", 98374532.398820); - doc.set("urifield", "http://this.is.a.test/"); - doc.set("bytefield", -2); - doc.set("rawfield", "RAW DATA"); + doc.setValue("intfield", std::make_unique<IntFieldValue>(5)); + doc.setValue("floatfield", std::make_unique<FloatFieldValue>(-9.23)); + doc.setValue("stringfield", std::make_unique<StringFieldValue>("This is a string.")); + doc.setValue("longfield", std::make_unique<LongFieldValue>((int64_t) 398420092938472983ll)); + doc.setValue("doublefield", std::make_unique<DoubleFieldValue>(98374532.398820)); + doc.setValue("urifield", std::make_unique<StringFieldValue>("http://this.is.a.test/")); + doc.setValue("bytefield", std::make_unique<ByteFieldValue>(-2)); + doc.setValue("rawfield", std::make_unique<RawFieldValue>("RAW DATA")); const DocumentType *docindoc_type = repo.getDocumentType("docindoc"); EXPECT_TRUE(docindoc_type); @@ -951,7 +951,7 @@ TEST(DocumentTest, testHasChanged) Document doc2(test_repo.getTypeRepo(), buf); EXPECT_TRUE(!doc2.hasChanged()); - doc2.set("headerval", 13); + doc2.setValue("headerval", std::make_unique<IntFieldValue>(13)); EXPECT_TRUE(doc2.hasChanged()); } // Overwriting a value in doc tags us changed. @@ -959,7 +959,7 @@ TEST(DocumentTest, testHasChanged) buf.rp(0); Document doc2(test_repo.getTypeRepo(), buf); - doc2.set("hstringval", "bla bla bla bla bla"); + doc2.setValue("hstringval", std::make_unique<StringFieldValue>("bla bla bla bla bla")); EXPECT_TRUE(doc2.hasChanged()); } // Clearing value tags us changed. diff --git a/document/src/tests/documentupdatetestcase.cpp b/document/src/tests/documentupdatetestcase.cpp index d5905d63455..28d254e8982 100644 --- a/document/src/tests/documentupdatetestcase.cpp +++ b/document/src/tests/documentupdatetestcase.cpp @@ -139,8 +139,8 @@ TEST(DocumentUpdateTest, testSimpleUsage) // Create a test document Document doc(*docType, DocumentId("id:ns:test::1")); - doc.set("bytef", 0); - doc.set("intf", 5); + doc.setValue("bytef", std::make_unique<ByteFieldValue>(0)); + doc.setValue("intf", std::make_unique<IntFieldValue>(5)); ArrayFieldValue array(*arrayType); array.add(IntFieldValue(3)); array.add(IntFieldValue(7)); diff --git a/document/src/tests/fieldvalue/fieldvalue_test.cpp b/document/src/tests/fieldvalue/fieldvalue_test.cpp index b70fd0d18a8..d8712768000 100644 --- a/document/src/tests/fieldvalue/fieldvalue_test.cpp +++ b/document/src/tests/fieldvalue/fieldvalue_test.cpp @@ -1,15 +1,15 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. // Unit tests for fieldvalue. -#include <vespa/log/log.h> -LOG_SETUP("fieldvalue_test"); - #include <vespa/document/fieldvalue/stringfieldvalue.h> #include <vespa/document/fieldvalue/longfieldvalue.h> #include <vespa/document/fieldvalue/intfieldvalue.h> #include <vespa/vespalib/testkit/testapp.h> +#include <vespa/log/log.h> +LOG_SETUP("fieldvalue_test"); + using namespace document; namespace { @@ -18,14 +18,6 @@ TEST("require that StringFieldValue can be assigned primitives") { StringFieldValue val; val = "foo"; EXPECT_EQUAL("foo", val.getValue()); - val = 1; - EXPECT_EQUAL("1", val.getValue()); - val = static_cast<int64_t>(2); - EXPECT_EQUAL("2", val.getValue()); - val = 3.0f; - EXPECT_EQUAL("3", val.getValue()); - val = 4.0; - EXPECT_EQUAL("4", val.getValue()); } TEST("require that FieldValues does not change their storage size.") { diff --git a/document/src/tests/primitivefieldvaluetest.cpp b/document/src/tests/primitivefieldvaluetest.cpp index 7c734544f27..ea78baa4ee6 100644 --- a/document/src/tests/primitivefieldvaluetest.cpp +++ b/document/src/tests/primitivefieldvaluetest.cpp @@ -3,7 +3,6 @@ #include <vespa/document/fieldvalue/fieldvalues.h> #include <vespa/document/serialization/vespadocumentdeserializer.h> #include <vespa/vespalib/objects/nbostream.h> -#include <vespa/document/util/bytebuffer.h> #include <vespa/document/repo/documenttyperepo.h> #include <limits> #include <gtest/gtest.h> @@ -32,7 +31,7 @@ void deserialize(nbostream & stream, T &value) { const Type& medium2, const Type& largest) { try{ - // Less + // Less EXPECT_TRUE(!(smallest < smallest)); EXPECT_TRUE(smallest < medium1); EXPECT_TRUE(smallest < medium2); @@ -203,31 +202,6 @@ TEST(PrimitiveFieldValueTest, testRaw) value.getValueRef().size()) == 0); } -#define ASSERT_FAILED_CONV(getter, totype, floating) \ -{ \ - totype toType; \ - FieldValue::UP copy(value.clone()); \ - try{ \ - getter; \ - std::ostringstream ost; \ - ost << "Conversion unexpectedly worked from max value of " \ - << *value.getDataType() << " to " << *toType.getDataType(); \ - FAIL() << ost.str(); \ - } catch (std::exception& e) { \ - EXPECT_EQ( \ - std::string("bad numeric conversion: positive overflow"), \ - std::string(e.what())); \ - } \ - /* Verify that we can convert to smaller type if value is within \ - range. Only tests integer to integer. No floating point. */ \ - if (!floating) { \ - totype::Number maxV = std::numeric_limits<totype::Number>::max(); \ - value.setValue((Number) maxV); \ - getter; \ - } \ - value.assign(*copy); \ -} - namespace { template<typename Numeric> @@ -258,25 +232,21 @@ namespace { // representation can keep the value. if (floatingPoint || sizeof(Number) > sizeof(unsigned char)) { // No longer throws. This is guarded on the perimeter by java code. - // ASSERT_FAILED_CONV(value.getAsByte(), ByteFieldValue, floatingPoint); } else { EXPECT_EQ((char) maxValue, value.getAsByte()); } if (floatingPoint || sizeof(Number) > sizeof(int32_t)) { // No longer throws. This is guarded on the perimeter by java code. - // ASSERT_FAILED_CONV(value.getAsInt(), IntFieldValue, floatingPoint); } else { EXPECT_EQ((int32_t) maxValue, value.getAsInt()); } if (floatingPoint || sizeof(Number) > sizeof(int64_t)) { // No longer throws. This is guarded on the perimeter by java code. - // ASSERT_FAILED_CONV(value.getAsLong(), LongFieldValue, floatingPoint); } else { EXPECT_EQ((int64_t) maxValue, value.getAsLong()); } if (floatingPoint && sizeof(Number) > sizeof(float)) { // No longer throws. This is guarded on the perimeter by java code. - // ASSERT_FAILED_CONV(value.getAsFloat(), FloatFieldValue, true); } else { EXPECT_EQ((float) maxValue, value.getAsFloat()); } @@ -303,30 +273,15 @@ TEST(PrimitiveFieldValueTest, testBool) v = BoolFieldValue(true); EXPECT_TRUE(v.getValue()); - v = 0; - EXPECT_TRUE( ! v.getValue()); - v = 1; - EXPECT_TRUE(v.getValue()); - - v = INT64_C(0); - EXPECT_TRUE( ! v.getValue()); - v = INT64_C(1); - EXPECT_TRUE(v.getValue()); - - v = 0.0f; - EXPECT_TRUE( ! v.getValue()); - v = 1.0f; - EXPECT_TRUE(v.getValue()); - - v = 0.0; - EXPECT_TRUE( ! v.getValue()); - v = 1.0; + v.setValue(false); + EXPECT_FALSE(v.getValue()); + v.setValue(true); EXPECT_TRUE(v.getValue()); v = vespalib::stringref("true"); EXPECT_TRUE(v.getValue()); v = vespalib::stringref("something not true"); - EXPECT_TRUE( ! v.getValue()); + EXPECT_FALSE(v.getValue()); } TEST(PrimitiveFieldValueTest, testNumerics) diff --git a/document/src/vespa/document/fieldvalue/boolfieldvalue.cpp b/document/src/vespa/document/fieldvalue/boolfieldvalue.cpp index c542936825d..1c5261877fd 100644 --- a/document/src/vespa/document/fieldvalue/boolfieldvalue.cpp +++ b/document/src/vespa/document/fieldvalue/boolfieldvalue.cpp @@ -87,25 +87,5 @@ BoolFieldValue::operator=(vespalib::stringref v) { _value = (v == "true"); return *this; } -BoolFieldValue& -BoolFieldValue::operator=(int32_t v) { - _value = (v != 0); - return *this; -} -BoolFieldValue& -BoolFieldValue::operator=(int64_t v) { - _value = (v != 0); - return *this; -} -BoolFieldValue& -BoolFieldValue::operator=(float v) { - _value = (v != 0); - return *this; -} -BoolFieldValue& -BoolFieldValue::operator=(double v) { - _value = (v != 0); - return *this; -} } // namespace document diff --git a/document/src/vespa/document/fieldvalue/boolfieldvalue.h b/document/src/vespa/document/fieldvalue/boolfieldvalue.h index d03ded5c9f1..c24428beaf4 100644 --- a/document/src/vespa/document/fieldvalue/boolfieldvalue.h +++ b/document/src/vespa/document/fieldvalue/boolfieldvalue.h @@ -42,10 +42,6 @@ public: vespalib::string getAsString() const override; BoolFieldValue& operator=(vespalib::stringref) override; - BoolFieldValue& operator=(int32_t) override; - BoolFieldValue& operator=(int64_t) override; - BoolFieldValue& operator=(float) override; - BoolFieldValue& operator=(double) override; DECLARE_IDENTIFIABLE(BoolFieldValue); }; diff --git a/document/src/vespa/document/fieldvalue/bytefieldvalue.h b/document/src/vespa/document/fieldvalue/bytefieldvalue.h index 7f6bc429b69..b817c4e16ec 100644 --- a/document/src/vespa/document/fieldvalue/bytefieldvalue.h +++ b/document/src/vespa/document/fieldvalue/bytefieldvalue.h @@ -14,7 +14,6 @@ namespace document { class ByteFieldValue : public NumericFieldValue<int8_t> { public: - typedef std::unique_ptr<ByteFieldValue> UP; typedef int8_t Number; ByteFieldValue(Number value = 0) diff --git a/document/src/vespa/document/fieldvalue/doublefieldvalue.h b/document/src/vespa/document/fieldvalue/doublefieldvalue.h index feb15e52223..c0c6d0781f0 100644 --- a/document/src/vespa/document/fieldvalue/doublefieldvalue.h +++ b/document/src/vespa/document/fieldvalue/doublefieldvalue.h @@ -14,7 +14,6 @@ namespace document { class DoubleFieldValue : public NumericFieldValue<double> { public: - typedef std::unique_ptr<DoubleFieldValue> UP; typedef double Number; DoubleFieldValue(Number value = 0) : NumericFieldValue<Number>(value) {} diff --git a/document/src/vespa/document/fieldvalue/fieldvalue.cpp b/document/src/vespa/document/fieldvalue/fieldvalue.cpp index 8a678ddf968..c69b7169aa0 100644 --- a/document/src/vespa/document/fieldvalue/fieldvalue.cpp +++ b/document/src/vespa/document/fieldvalue/fieldvalue.cpp @@ -95,30 +95,6 @@ FieldValue::operator=(vespalib::stringref) throw IllegalArgumentException("Cannot assign string to datatype " + getDataType()->toString(), VESPA_STRLOC); } -FieldValue& -FieldValue::operator=(int32_t) -{ - throw IllegalArgumentException("Cannot assign int to datatype " + getDataType()->toString(), VESPA_STRLOC); -} - -FieldValue& -FieldValue::operator=(int64_t) -{ - throw IllegalArgumentException("Cannot assign long to datatype " + getDataType()->toString(), VESPA_STRLOC); -} - -FieldValue& -FieldValue::operator=(float) -{ - throw IllegalArgumentException("Cannot assign float to datatype " + getDataType()->toString(), VESPA_STRLOC); -} - -FieldValue& -FieldValue::operator=(double) -{ - throw IllegalArgumentException("Cannot assign double to datatype " + getDataType()->toString(), VESPA_STRLOC); -} - char FieldValue::getAsByte() const { diff --git a/document/src/vespa/document/fieldvalue/fieldvalue.h b/document/src/vespa/document/fieldvalue/fieldvalue.h index b0507a6c251..fedb0141391 100644 --- a/document/src/vespa/document/fieldvalue/fieldvalue.h +++ b/document/src/vespa/document/fieldvalue/fieldvalue.h @@ -24,7 +24,6 @@ namespace document { namespace fieldvalue { class IteratorHandler; } -class ByteBuffer; class DataType; class FieldValue : public vespalib::Identifiable @@ -108,13 +107,6 @@ public: /** Override toXml from XmlSerializable to add start/stop tags. */ virtual std::string toXml(const std::string& indent = "") const; - // Utility functions to set commonly used value types. - virtual FieldValue& operator=(vespalib::stringref); - virtual FieldValue& operator=(int32_t); - virtual FieldValue& operator=(int64_t); - virtual FieldValue& operator=(float); - virtual FieldValue& operator=(double); - // Utility functions to unwrap field values if you know the type. /** @@ -187,6 +179,8 @@ public: std::string toString(bool verbose=false, const std::string& indent="") const; virtual void printXml(XmlOutputStream& out) const = 0; + // Utility functions to set commonly used value types. + virtual FieldValue& operator=(vespalib::stringref); private: fieldvalue::ModificationStatus iterateNested(FieldPath::const_iterator start, FieldPath::const_iterator end, fieldvalue::IteratorHandler & handler) const { diff --git a/document/src/vespa/document/fieldvalue/floatfieldvalue.h b/document/src/vespa/document/fieldvalue/floatfieldvalue.h index f33939d8d67..07a645c13cb 100644 --- a/document/src/vespa/document/fieldvalue/floatfieldvalue.h +++ b/document/src/vespa/document/fieldvalue/floatfieldvalue.h @@ -14,7 +14,6 @@ namespace document { class FloatFieldValue : public NumericFieldValue<float> { public: - typedef std::unique_ptr<FloatFieldValue> UP; typedef float Number; FloatFieldValue(Number value = 0) : NumericFieldValue<Number>(value) {} diff --git a/document/src/vespa/document/fieldvalue/intfieldvalue.h b/document/src/vespa/document/fieldvalue/intfieldvalue.h index dbe419379a1..5eb511aa09c 100644 --- a/document/src/vespa/document/fieldvalue/intfieldvalue.h +++ b/document/src/vespa/document/fieldvalue/intfieldvalue.h @@ -14,7 +14,6 @@ namespace document { class IntFieldValue : public NumericFieldValue<int32_t> { public: - typedef std::unique_ptr<IntFieldValue> UP; typedef int32_t Number; IntFieldValue(Number value = 0) : NumericFieldValue<Number>(value) {} diff --git a/document/src/vespa/document/fieldvalue/literalfieldvalue.cpp b/document/src/vespa/document/fieldvalue/literalfieldvalue.cpp index 9b648400533..f362de974a8 100644 --- a/document/src/vespa/document/fieldvalue/literalfieldvalue.cpp +++ b/document/src/vespa/document/fieldvalue/literalfieldvalue.cpp @@ -1,10 +1,8 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include "literalfieldvalue.h" #include "literalfieldvalue.hpp" #include <vespa/document/util/stringutil.h> #include <vespa/vespalib/util/xmlstream.h> -#include <sstream> using namespace vespalib::xml; @@ -21,7 +19,7 @@ LiteralFieldValueB::LiteralFieldValueB() : _value = _backing; } -LiteralFieldValueB::~LiteralFieldValueB() { } +LiteralFieldValueB::~LiteralFieldValueB() = default; LiteralFieldValueB::LiteralFieldValueB(const LiteralFieldValueB& other) : FieldValue(other), @@ -117,44 +115,6 @@ LiteralFieldValueB::syncBacking() const _value = _backing; } - -namespace { -template <typename T> -std::string valueToString(T value) { - std::ostringstream ost; - ost << value; - return ost.str(); -} -} // namespace - -FieldValue& -LiteralFieldValueB::operator=(int32_t value) -{ - setValue(valueToString(value)); - return *this; -} - -FieldValue& -LiteralFieldValueB::operator=(int64_t value) -{ - setValue(valueToString(value)); - return *this; -} - -FieldValue& -LiteralFieldValueB::operator=(float value) -{ - setValue(valueToString(value)); - return *this; -} - -FieldValue& -LiteralFieldValueB::operator=(double value) -{ - setValue(valueToString(value)); - return *this; -} - template class LiteralFieldValue<RawFieldValue, DataType::T_RAW, false>; template class LiteralFieldValue<StringFieldValue, DataType::T_STRING, true>; diff --git a/document/src/vespa/document/fieldvalue/literalfieldvalue.h b/document/src/vespa/document/fieldvalue/literalfieldvalue.h index e84f0c529c7..d6bf083d0ce 100644 --- a/document/src/vespa/document/fieldvalue/literalfieldvalue.h +++ b/document/src/vespa/document/fieldvalue/literalfieldvalue.h @@ -69,10 +69,6 @@ public: bool hasChanged() const override{ return _altered; } FieldValue& operator=(vespalib::stringref) override; - FieldValue& operator=(int32_t) override; - FieldValue& operator=(int64_t) override; - FieldValue& operator=(float) override; - FieldValue& operator=(double) override; protected: void syncBacking() const __attribute__((noinline)); void sync() const { diff --git a/document/src/vespa/document/fieldvalue/longfieldvalue.h b/document/src/vespa/document/fieldvalue/longfieldvalue.h index 12a0615e0ad..b978bda7213 100644 --- a/document/src/vespa/document/fieldvalue/longfieldvalue.h +++ b/document/src/vespa/document/fieldvalue/longfieldvalue.h @@ -14,7 +14,6 @@ namespace document { class LongFieldValue : public NumericFieldValue<int64_t> { public: - typedef std::unique_ptr<LongFieldValue> UP; typedef int64_t Number; LongFieldValue(Number value = 0) : NumericFieldValue<Number>(value) {} diff --git a/document/src/vespa/document/fieldvalue/numericfieldvalue.h b/document/src/vespa/document/fieldvalue/numericfieldvalue.h index c094cf0689c..0a557af93d9 100644 --- a/document/src/vespa/document/fieldvalue/numericfieldvalue.h +++ b/document/src/vespa/document/fieldvalue/numericfieldvalue.h @@ -41,10 +41,6 @@ public: int fastCompare(const FieldValue& other) const override final; FieldValue& operator=(vespalib::stringref) override; - FieldValue& operator=(int32_t) override; - FieldValue& operator=(int64_t) override; - FieldValue& operator=(float) override; - FieldValue& operator=(double) override; size_t hash() const override final { return vespalib::hash<Number>()(_value); } char getAsByte() const override; diff --git a/document/src/vespa/document/fieldvalue/numericfieldvalue.hpp b/document/src/vespa/document/fieldvalue/numericfieldvalue.hpp index c4f1fdf13a1..f1bbce5450d 100644 --- a/document/src/vespa/document/fieldvalue/numericfieldvalue.hpp +++ b/document/src/vespa/document/fieldvalue/numericfieldvalue.hpp @@ -123,42 +123,6 @@ NumericFieldValue<Number>::operator=(vespalib::stringref value) } template<typename Number> -FieldValue& -NumericFieldValue<Number>::operator=(int32_t value) -{ - _value = static_cast<Number>(value); - _altered = true; - return *this; -} - -template<typename Number> -FieldValue& -NumericFieldValue<Number>::operator=(int64_t value) -{ - _value = static_cast<Number>(value); - _altered = true; - return *this; -} - -template<typename Number> -FieldValue& -NumericFieldValue<Number>::operator=(float value) -{ - _value = static_cast<Number>(value); - _altered = true; - return *this; -} - -template<typename Number> -FieldValue& -NumericFieldValue<Number>::operator=(double value) -{ - _value = static_cast<Number>(value); - _altered = true; - return *this; -} - -template<typename Number> char NumericFieldValue<Number>::getAsByte() const { diff --git a/document/src/vespa/document/fieldvalue/structfieldvalue.h b/document/src/vespa/document/fieldvalue/structfieldvalue.h index ab35dc04421..cbf62ce54fa 100644 --- a/document/src/vespa/document/fieldvalue/structfieldvalue.h +++ b/document/src/vespa/document/fieldvalue/structfieldvalue.h @@ -98,7 +98,6 @@ private: VESPA_DLL_LOCAL const StructDataType & getStructType() const; struct FieldIterator; - friend struct FieldIterator; StructuredIterator::UP getIterator(const Field* toFind) const override; diff --git a/document/src/vespa/document/fieldvalue/structuredfieldvalue.cpp b/document/src/vespa/document/fieldvalue/structuredfieldvalue.cpp index becdfdabb5f..53f75cb2e73 100644 --- a/document/src/vespa/document/fieldvalue/structuredfieldvalue.cpp +++ b/document/src/vespa/document/fieldvalue/structuredfieldvalue.cpp @@ -172,20 +172,6 @@ StructuredFieldValue::onIterateNested(PathRange nested, IteratorHandler & handle } } -using ConstCharP = const char *; -template void StructuredFieldValue::set(const Field& field, int32_t value); -template void StructuredFieldValue::set(const Field& field, int64_t value); -template void StructuredFieldValue::set(const Field& field, double value); -template void StructuredFieldValue::set(const Field& field, ConstCharP value); -template void StructuredFieldValue::set(const Field& field, vespalib::stringref value); -template void StructuredFieldValue::set(const Field& field, vespalib::string value); -template void StructuredFieldValue::set(vespalib::stringref field, int32_t value); -template void StructuredFieldValue::set(vespalib::stringref field, int64_t value); -template void StructuredFieldValue::set(vespalib::stringref field, double value); -template void StructuredFieldValue::set(vespalib::stringref field, ConstCharP value); -template void StructuredFieldValue::set(vespalib::stringref field, vespalib::stringref value); -template void StructuredFieldValue::set(vespalib::stringref field, vespalib::string value); - template std::unique_ptr<MapFieldValue> StructuredFieldValue::getAs<MapFieldValue>(const Field &field) const; template std::unique_ptr<ArrayFieldValue> StructuredFieldValue::getAs<ArrayFieldValue>(const Field &field) const; template std::unique_ptr<WeightedSetFieldValue> StructuredFieldValue::getAs<WeightedSetFieldValue>(const Field &field) const; diff --git a/document/src/vespa/document/fieldvalue/structuredfieldvalue.h b/document/src/vespa/document/fieldvalue/structuredfieldvalue.h index b1b88323a3b..9d79b6279a4 100644 --- a/document/src/vespa/document/fieldvalue/structuredfieldvalue.h +++ b/document/src/vespa/document/fieldvalue/structuredfieldvalue.h @@ -152,6 +152,12 @@ public: void setValue(const Field& field, FieldValue::UP value) { setFieldValue(field, std::move(value)); } + void setValue(vespalib::stringref fieldName, const FieldValue& value) { + setFieldValue(getField(fieldName), value); + } + void setValue(vespalib::stringref fieldName, FieldValue::UP value) { + setFieldValue(getField(fieldName), std::move(value)); + } /** Remove the value of given field if it is set. */ //These are affected by the begin/commitTanasaction @@ -166,13 +172,6 @@ public: void remove(vespalib::stringref fieldName) { removeFieldValue(getField(fieldName)); } - void setValue(vespalib::stringref fieldName, const FieldValue& value) { - setFieldValue(getField(fieldName), value); - } - template<typename PrimitiveType> - void set(const Field& field, PrimitiveType value); - template<typename PrimitiveType> - void set(vespalib::stringref fieldName, PrimitiveType value); size_t getSetFieldCount() const { size_t count = 0; diff --git a/document/src/vespa/document/fieldvalue/structuredfieldvalue.hpp b/document/src/vespa/document/fieldvalue/structuredfieldvalue.hpp index df02506c076..4b347d7cc07 100644 --- a/document/src/vespa/document/fieldvalue/structuredfieldvalue.hpp +++ b/document/src/vespa/document/fieldvalue/structuredfieldvalue.hpp @@ -20,20 +20,4 @@ StructuredFieldValue::getAs(const Field &field) const { return std::unique_ptr<T>(t); } -template<typename PrimitiveType> -void -StructuredFieldValue::set(const Field& field, PrimitiveType value) -{ - FieldValue::UP fval(field.getDataType().createFieldValue()); - *fval = value; - setFieldValue(field, std::move(fval)); -} - -template<typename PrimitiveType> -void -StructuredFieldValue::set(vespalib::stringref fieldName, PrimitiveType value) -{ - set(getField(fieldName), value); -} - } // document diff --git a/document/src/vespa/document/test/fieldvalue_helpers.h b/document/src/vespa/document/test/fieldvalue_helpers.h index 539ee50d2ab..a7d899b385f 100644 --- a/document/src/vespa/document/test/fieldvalue_helpers.h +++ b/document/src/vespa/document/test/fieldvalue_helpers.h @@ -4,6 +4,9 @@ #include <vespa/document/fieldvalue/collectionfieldvalue.h> #include <vespa/document/fieldvalue/weightedsetfieldvalue.h> +#include <vespa/document/fieldvalue/longfieldvalue.h> +#include <vespa/document/fieldvalue/floatfieldvalue.h> +#include <vespa/document/fieldvalue/doublefieldvalue.h> namespace document { @@ -13,22 +16,22 @@ public: // Convenience functions for using primitives directly bool add(vespalib::stringref val) { return _cfv.add(*_cfv.createNested() = val); } - bool add(int32_t val) { return _cfv.add(*_cfv.createNested() = val); } - bool add(int64_t val) { return _cfv.add(*_cfv.createNested() = val); } - bool add(float val) { return _cfv.add(*_cfv.createNested() = val); } - bool add(double val) { return _cfv.add(*_cfv.createNested() = val); } + bool add(int32_t val) { return _cfv.add(_cfv.createNested()->assign(IntFieldValue(val))); } + bool add(int64_t val) { return _cfv.add(_cfv.createNested()->assign(LongFieldValue(val))); } + bool add(float val) { return _cfv.add(_cfv.createNested()->assign(FloatFieldValue(val))); } + bool add(double val) { return _cfv.add(_cfv.createNested()->assign(DoubleFieldValue(val))); } bool contains(vespalib::stringref val) { return _cfv.contains(*_cfv.createNested() = val); } - bool contains(int32_t val) { return _cfv.contains(*_cfv.createNested() = val); } - bool contains(int64_t val) { return _cfv.contains(*_cfv.createNested() = val); } - bool contains(float val) { return _cfv.contains(*_cfv.createNested() = val); } - bool contains(double val) { return _cfv.contains(*_cfv.createNested() = val); } + bool contains(int32_t val) { return _cfv.contains(_cfv.createNested()->assign(IntFieldValue(val))); } + bool contains(int64_t val) { return _cfv.contains(_cfv.createNested()->assign(LongFieldValue(val))); } + bool contains(float val) { return _cfv.contains(_cfv.createNested()->assign(FloatFieldValue(val))); } + bool contains(double val) { return _cfv.contains(_cfv.createNested()->assign(DoubleFieldValue(val))); } bool remove(vespalib::stringref val) { return _cfv.remove(*_cfv.createNested() = val); } - bool remove(int32_t val) { return _cfv.remove(*_cfv.createNested() = val); } - bool remove(int64_t val) { return _cfv.remove(*_cfv.createNested() = val); } - bool remove(float val) { return _cfv.remove(*_cfv.createNested() = val); } - bool remove(double val) { return _cfv.remove(*_cfv.createNested() = val); } + bool remove(int32_t val) { return _cfv.remove(_cfv.createNested()->assign(IntFieldValue(val))); } + bool remove(int64_t val) { return _cfv.remove(_cfv.createNested()->assign(LongFieldValue(val))); } + bool remove(float val) { return _cfv.remove(_cfv.createNested()->assign(FloatFieldValue(val))); } + bool remove(double val) { return _cfv.remove(_cfv.createNested()->assign(DoubleFieldValue(val))); } private: CollectionFieldValue & _cfv; }; @@ -40,28 +43,28 @@ public: // Utility functions for easy use of weighted sets of primitives bool add(vespalib::stringref val, int32_t weight = 1) { return _ws.add(*_ws.createNested() = val, weight); } - bool add(int32_t val, int32_t weight = 1) { return _ws.add(*_ws.createNested() = val, weight); } - bool add(int64_t val, int32_t weight = 1) { return _ws.add(*_ws.createNested() = val, weight); } - bool add(float val, int32_t weight = 1) { return _ws.add(*_ws.createNested() = val, weight); } - bool add(double val, int32_t weight = 1) { return _ws.add(*_ws.createNested() = val, weight); } + bool add(int32_t val, int32_t weight = 1) { return _ws.add(_ws.createNested()->assign(IntFieldValue(val)), weight); } + bool add(int64_t val, int32_t weight = 1) { return _ws.add(_ws.createNested()->assign(LongFieldValue(val)), weight); } + bool add(float val, int32_t weight = 1) { return _ws.add(_ws.createNested()->assign(FloatFieldValue(val)), weight); } + bool add(double val, int32_t weight = 1) { return _ws.add(_ws.createNested()->assign(DoubleFieldValue(val)), weight); } int32_t get(vespalib::stringref val) const { return _ws.get(*_ws.createNested() = val); } - int32_t get(int32_t val) const { return _ws.get(*_ws.createNested() = val); } - int32_t get(int64_t val) const { return _ws.get(*_ws.createNested() = val); } - int32_t get(float val) const { return _ws.get(*_ws.createNested() = val); } - int32_t get(double val) const { return _ws.get(*_ws.createNested() = val); } + int32_t get(int32_t val) const { return _ws.get(_ws.createNested()->assign(IntFieldValue(val))); } + int32_t get(int64_t val) const { return _ws.get(_ws.createNested()->assign(LongFieldValue(val))); } + int32_t get(float val) const { return _ws.get(_ws.createNested()->assign(FloatFieldValue(val))); } + int32_t get(double val) const { return _ws.get(_ws.createNested()->assign(DoubleFieldValue(val))); } void increment(vespalib::stringref val, int32_t weight = 1) { _ws.increment(*_ws.createNested() = val, weight); } - void increment(int32_t val, int32_t weight = 1) { _ws.increment(*_ws.createNested() = val, weight); } - void increment(int64_t val, int32_t weight = 1) { _ws.increment(*_ws.createNested() = val, weight); } - void increment(float val, int32_t weight = 1) { _ws.increment(*_ws.createNested() = val, weight); } - void increment(double val, int32_t weight = 1) { _ws.increment(*_ws.createNested() = val, weight); } + void increment(int32_t val, int32_t weight = 1) { _ws.increment(_ws.createNested()->assign(IntFieldValue(val)), weight); } + void increment(int64_t val, int32_t weight = 1) { _ws.increment(_ws.createNested()->assign(LongFieldValue(val)), weight); } + void increment(float val, int32_t weight = 1) { _ws.increment(_ws.createNested()->assign(FloatFieldValue(val)), weight); } + void increment(double val, int32_t weight = 1) { _ws.increment(_ws.createNested()->assign(DoubleFieldValue(val)), weight); } void decrement(vespalib::stringref val, int32_t weight = 1) { _ws.decrement(*_ws.createNested() = val, weight); } - void decrement(int32_t val, int32_t weight = 1) { _ws.decrement(*_ws.createNested() = val, weight); } - void decrement(int64_t val, int32_t weight = 1) { _ws.decrement(*_ws.createNested() = val, weight); } - void decrement(float val, int32_t weight = 1) { _ws.decrement(*_ws.createNested() = val, weight); } - void decrement(double val, int32_t weight = 1) { _ws.decrement(*_ws.createNested() = val, weight); } + void decrement(int32_t val, int32_t weight = 1) { _ws.decrement(_ws.createNested()->assign(IntFieldValue(val)), weight); } + void decrement(int64_t val, int32_t weight = 1) { _ws.decrement(_ws.createNested()->assign(LongFieldValue(val)), weight); } + void decrement(float val, int32_t weight = 1) { _ws.decrement(_ws.createNested()->assign(FloatFieldValue(val)), weight); } + void decrement(double val, int32_t weight = 1) { _ws.decrement(_ws.createNested()->assign(DoubleFieldValue(val)), weight); } private: WeightedSetFieldValue & _ws; }; |