diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2022-03-16 17:36:04 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2022-03-16 18:06:45 +0000 |
commit | cea11eaf40659b879d143f99eee2f6b78e427761 (patch) | |
tree | 88a81f4697a51d889af52daf1b581eeb3ee6385e /document | |
parent | fd26131762bf938c033178637604df97076ffcdf (diff) |
Avoid requiring identifiable for FieldValue
Diffstat (limited to 'document')
74 files changed, 271 insertions, 354 deletions
diff --git a/document/src/tests/arrayfieldvaluetest.cpp b/document/src/tests/arrayfieldvaluetest.cpp index 375ce05a4e6..86cd50cf965 100644 --- a/document/src/tests/arrayfieldvaluetest.cpp +++ b/document/src/tests/arrayfieldvaluetest.cpp @@ -105,7 +105,7 @@ TEST(ArrayFieldValueTest, testArray) // Iterating const ArrayFieldValue& constVal(value); for(const FieldValue & fval1 : constVal) { - EXPECT_EQ((uint32_t) IntFieldValue::classId, fval1.getClass().id()); + EXPECT_EQ(FieldValue::Type::INT, fval1.type()); } value2 = value; for(size_t i(0); i < value2.size(); i++) { diff --git a/document/src/tests/documenttestcase.cpp b/document/src/tests/documenttestcase.cpp index c852e219faa..6967be5b969 100644 --- a/document/src/tests/documenttestcase.cpp +++ b/document/src/tests/documenttestcase.cpp @@ -50,11 +50,11 @@ TEST(DocumentTest, testSizeOf) EXPECT_EQ(32u, sizeof(vespalib::GrowableByteBuffer)); EXPECT_EQ(88ul, sizeof(IdString)); EXPECT_EQ(104ul, sizeof(DocumentId)); - EXPECT_EQ(240ul, sizeof(Document)); + EXPECT_EQ(256ul, sizeof(Document)); EXPECT_EQ(80ul, sizeof(NumericDataType)); - EXPECT_EQ(24ul, sizeof(LongFieldValue)); - EXPECT_EQ(96ul, sizeof(StructFieldValue)); - EXPECT_EQ(16ul, sizeof(StructuredFieldValue)); + EXPECT_EQ(32ul, sizeof(LongFieldValue)); + EXPECT_EQ(104ul, sizeof(StructFieldValue)); + EXPECT_EQ(24ul, sizeof(StructuredFieldValue)); EXPECT_EQ(56ul, sizeof(SerializableArray)); } diff --git a/document/src/tests/documentupdatetestcase.cpp b/document/src/tests/documentupdatetestcase.cpp index 26819699db4..e1e86bca671 100644 --- a/document/src/tests/documentupdatetestcase.cpp +++ b/document/src/tests/documentupdatetestcase.cpp @@ -495,7 +495,7 @@ TEST(DocumentUpdateTest, testReadSerializedFile) const AddValueUpdate* add = static_cast<const AddValueUpdate*>(serValue); const FieldValue* value = &add->getValue(); - EXPECT_TRUE(value->inherits(FloatFieldValue::classId)); + EXPECT_TRUE(value->isA(FieldValue::Type::FLOAT)); EXPECT_FLOAT_EQ(value->getAsFloat(), 5.00f); serValue = &serField3[1]; @@ -503,7 +503,7 @@ TEST(DocumentUpdateTest, testReadSerializedFile) add = static_cast<const AddValueUpdate*>(serValue); value = &add->getValue(); - EXPECT_TRUE(value->inherits(FloatFieldValue::classId)); + EXPECT_TRUE(value->isA(FieldValue::Type::FLOAT)); EXPECT_FLOAT_EQ(value->getAsFloat(), 4.23f); serValue = &serField3[2]; @@ -511,7 +511,7 @@ TEST(DocumentUpdateTest, testReadSerializedFile) add = static_cast<const AddValueUpdate*>(serValue); value = &add->getValue(); - EXPECT_TRUE(value->inherits(FloatFieldValue::classId)); + EXPECT_TRUE(value->isA(FieldValue::Type::FLOAT)); EXPECT_FLOAT_EQ(value->getAsFloat(), -1.00f); } diff --git a/document/src/tests/fieldvalue/fieldvalue_test.cpp b/document/src/tests/fieldvalue/fieldvalue_test.cpp index d8712768000..c9b56bdc4b2 100644 --- a/document/src/tests/fieldvalue/fieldvalue_test.cpp +++ b/document/src/tests/fieldvalue/fieldvalue_test.cpp @@ -21,10 +21,10 @@ TEST("require that StringFieldValue can be assigned primitives") { } TEST("require that FieldValues does not change their storage size.") { - EXPECT_EQUAL(8u, sizeof(FieldValue)); - EXPECT_EQUAL(16u, sizeof(IntFieldValue)); - EXPECT_EQUAL(24u, sizeof(LongFieldValue)); - EXPECT_EQUAL(104u, sizeof(StringFieldValue)); + EXPECT_EQUAL(16u, sizeof(FieldValue)); + EXPECT_EQUAL(24u, sizeof(IntFieldValue)); + EXPECT_EQUAL(32u, sizeof(LongFieldValue)); + EXPECT_EQUAL(112u, sizeof(StringFieldValue)); } } // namespace diff --git a/document/src/tests/weightedsetfieldvaluetest.cpp b/document/src/tests/weightedsetfieldvaluetest.cpp index 61f727120d1..4cc897f22d7 100644 --- a/document/src/tests/weightedsetfieldvaluetest.cpp +++ b/document/src/tests/weightedsetfieldvaluetest.cpp @@ -141,8 +141,7 @@ TEST(WeightedSetFieldValueTest, testWeightedSet) { const FieldValue& fval1(*it->first); (void) fval1; - EXPECT_EQ((uint32_t) IntFieldValue::classId, - it->first->getClass().id()); + EXPECT_TRUE(it->first->isA(FieldValue::Type::INT)); const IntFieldValue& val = dynamic_cast<const IntFieldValue&>(*it->second); (void) val; } diff --git a/document/src/vespa/document/base/fieldpath.cpp b/document/src/vespa/document/base/fieldpath.cpp index 5da64272364..fcac59847cb 100644 --- a/document/src/vespa/document/base/fieldpath.cpp +++ b/document/src/vespa/document/base/fieldpath.cpp @@ -5,7 +5,6 @@ #include <vespa/document/datatype/mapdatatype.h> #include <vespa/vespalib/util/exceptions.h> #include <vespa/document/fieldvalue/fieldvalue.h> -#include <vespa/vespalib/objects/visit.hpp> using vespalib::IllegalArgumentException; using vespalib::make_string; @@ -127,17 +126,6 @@ FieldPathEntry::stealFieldValueToSet() const return FieldValue::UP(_fillInVal.release()); } -void -FieldPathEntry::visitMembers(vespalib::ObjectVisitor &visitor) const -{ - visit(visitor, "type", _type); - visit(visitor, "name", _name); - visit(visitor, "lookupIndex", _lookupIndex); - visit(visitor, "lookupKey", _lookupKey); - visit(visitor, "variableName", _variableName); - visit(visitor, "fillInVal", _fillInVal); -} - vespalib::string FieldPathEntry::parseKey(vespalib::stringref & key) { @@ -191,7 +179,8 @@ FieldPath::FieldPath(const FieldPath &) = default; FieldPath & FieldPath::operator=(const FieldPath &) = default; FieldPath::~FieldPath() = default; -FieldPath::iterator FieldPath::insert(iterator pos, std::unique_ptr<FieldPathEntry> entry) { +FieldPath::iterator +FieldPath::insert(iterator pos, std::unique_ptr<FieldPathEntry> entry) { return _path.insert(pos, vespalib::CloneablePtr<FieldPathEntry>(entry.release())); } void FieldPath::push_back(std::unique_ptr<FieldPathEntry> entry) { _path.emplace_back(entry.release()); } @@ -199,13 +188,4 @@ void FieldPath::pop_back() { _path.pop_back(); } void FieldPath::clear() { _path.clear(); } void FieldPath::reserve(size_t sz) { _path.reserve(sz); } -void -FieldPath::visitMembers(vespalib::ObjectVisitor& visitor) const -{ - (void) visitor; - for (uint32_t i = 0; i < _path.size(); ++i) { -// visit(visitor, vespalib::make_string("[%u]", i), _path[i]); - } -} - } diff --git a/document/src/vespa/document/base/fieldpath.h b/document/src/vespa/document/base/fieldpath.h index 679fd0885dd..a79e4595a61 100644 --- a/document/src/vespa/document/base/fieldpath.h +++ b/document/src/vespa/document/base/fieldpath.h @@ -2,10 +2,7 @@ #pragma once #include "field.h" -#include <vespa/document/util/identifiableid.h> -#include <vector> - -namespace vespalib { class ObjectVisitor; } +#include <vespa/vespalib/util/memory.h> namespace document { @@ -80,7 +77,6 @@ public: FieldValue * getFieldValueToSetPtr() const { return _fillInVal.get(); } FieldValue & getFieldValueToSet() const { return *_fillInVal; } std::unique_ptr<FieldValue> stealFieldValueToSet() const; - void visitMembers(vespalib::ObjectVisitor &visitor) const; /** * Parses a string of the format {["]escaped string["]} to its unescaped value. * @param key is the incoming value, and contains what is left when done. @@ -115,8 +111,8 @@ public: FieldPath(); FieldPath(const FieldPath &); FieldPath & operator=(const FieldPath &); - FieldPath(FieldPath &&) = default; - FieldPath & operator=(FieldPath &&) = default; + FieldPath(FieldPath &&) noexcept = default; + FieldPath & operator=(FieldPath &&) noexcept = default; ~FieldPath(); template <typename InputIterator> @@ -151,8 +147,6 @@ public: const FieldPathEntry & operator[](Container::size_type i) const { return *_path[i]; } - void visitMembers(vespalib::ObjectVisitor &visitor) const; - template <typename IT> class Range { public: diff --git a/document/src/vespa/document/datatype/datatype.cpp b/document/src/vespa/document/datatype/datatype.cpp index 87464a197ee..3cc7034e336 100644 --- a/document/src/vespa/document/datatype/datatype.cpp +++ b/document/src/vespa/document/datatype/datatype.cpp @@ -51,32 +51,32 @@ class DataType2FieldValueId { public: DataType2FieldValueId(); - unsigned int getFieldValueId(unsigned int id) const { + FieldValue::Type getFieldValueId(unsigned int id) const { return id < sizeof(_type2FieldValueId)/sizeof(_type2FieldValueId[0]) ? _type2FieldValueId[id] - : 0; + : FieldValue::Type::NONE; } private: - unsigned int _type2FieldValueId[DataType::MAX]; + FieldValue::Type _type2FieldValueId[DataType::MAX]; }; DataType2FieldValueId::DataType2FieldValueId() { for (size_t i(0); i < sizeof(_type2FieldValueId)/sizeof(_type2FieldValueId[0]); i++) { - _type2FieldValueId[i] = 0; + _type2FieldValueId[i] = FieldValue::Type::NONE; } - _type2FieldValueId[DataType::T_BYTE] = ByteFieldValue::classId; - _type2FieldValueId[DataType::T_SHORT] = ShortFieldValue::classId; - _type2FieldValueId[DataType::T_INT] = IntFieldValue::classId; - _type2FieldValueId[DataType::T_LONG] = LongFieldValue::classId; - _type2FieldValueId[DataType::T_FLOAT] = FloatFieldValue::classId; - _type2FieldValueId[DataType::T_DOUBLE] = DoubleFieldValue::classId; - _type2FieldValueId[DataType::T_BOOL] = BoolFieldValue::classId; - _type2FieldValueId[DataType::T_STRING] = StringFieldValue::classId; - _type2FieldValueId[DataType::T_RAW] = RawFieldValue::classId; - _type2FieldValueId[DataType::T_URI] = StringFieldValue::classId; - _type2FieldValueId[DataType::T_PREDICATE] = PredicateFieldValue::classId; - _type2FieldValueId[DataType::T_TENSOR] = TensorFieldValue::classId; + _type2FieldValueId[DataType::T_BYTE] = FieldValue::Type::BYTE; + _type2FieldValueId[DataType::T_SHORT] = FieldValue::Type::SHORT; + _type2FieldValueId[DataType::T_INT] = FieldValue::Type::INT; + _type2FieldValueId[DataType::T_LONG] = FieldValue::Type::LONG; + _type2FieldValueId[DataType::T_FLOAT] = FieldValue::Type::FLOAT; + _type2FieldValueId[DataType::T_DOUBLE] = FieldValue::Type::DOUBLE; + _type2FieldValueId[DataType::T_BOOL] = FieldValue::Type::BOOL; + _type2FieldValueId[DataType::T_STRING] = FieldValue::Type::STRING; + _type2FieldValueId[DataType::T_RAW] = FieldValue::Type::RAW; + _type2FieldValueId[DataType::T_URI] = FieldValue::Type::STRING; + _type2FieldValueId[DataType::T_PREDICATE] = FieldValue::Type::PREDICATE; + _type2FieldValueId[DataType::T_TENSOR] = FieldValue::Type::TENSOR; } DataType2FieldValueId _G_type2FieldValueId; @@ -86,9 +86,8 @@ DataType2FieldValueId _G_type2FieldValueId; bool DataType::isValueType(const FieldValue & fv) const { if ((_dataTypeId >= 0) && _dataTypeId < MAX) { - const uint32_t cid(_G_type2FieldValueId.getFieldValueId(_dataTypeId)); - if (cid != 0) { - return cid == fv.getClass().id(); + if (fv.isA(_G_type2FieldValueId.getFieldValueId(_dataTypeId))) { + return true; } } return _dataTypeId == fv.getDataType()->getId(); diff --git a/document/src/vespa/document/fieldvalue/annotationreferencefieldvalue.cpp b/document/src/vespa/document/fieldvalue/annotationreferencefieldvalue.cpp index e26f0f15759..d63212e402b 100644 --- a/document/src/vespa/document/fieldvalue/annotationreferencefieldvalue.cpp +++ b/document/src/vespa/document/fieldvalue/annotationreferencefieldvalue.cpp @@ -9,12 +9,6 @@ using std::string; namespace document { -AnnotationReferenceFieldValue::AnnotationReferenceFieldValue( - const DataType &type, int32_t annotation_index) - : _type(&type), - _annotation_index(annotation_index) { -} - int AnnotationReferenceFieldValue::compare(const FieldValue &other) const { if (getDataType()->equals(*other.getDataType())) { const AnnotationReferenceFieldValue &val(static_cast<const AnnotationReferenceFieldValue &>(other)); diff --git a/document/src/vespa/document/fieldvalue/annotationreferencefieldvalue.h b/document/src/vespa/document/fieldvalue/annotationreferencefieldvalue.h index 6fc85bf384f..0651e429878 100644 --- a/document/src/vespa/document/fieldvalue/annotationreferencefieldvalue.h +++ b/document/src/vespa/document/fieldvalue/annotationreferencefieldvalue.h @@ -9,15 +9,17 @@ namespace document { class Annotation; class AnnotationReferenceDataType; -class AnnotationReferenceFieldValue : public FieldValue { +class AnnotationReferenceFieldValue final : public FieldValue { const DataType *_type; int32_t _annotation_index; public: AnnotationReferenceFieldValue(const DataType &type) - : _type(&type), _annotation_index(0) {} - AnnotationReferenceFieldValue(const DataType &type, - int32_t annotation_index); + : AnnotationReferenceFieldValue(type, 0) {} + AnnotationReferenceFieldValue(const DataType &type, int32_t annotation_index) + : FieldValue(Type::ANNOTATION_REFERENCE), _type(&type), _annotation_index(annotation_index) + {} + void setAnnotationIndex(int32_t index) { _annotation_index = index; } void accept(FieldValueVisitor &visitor) override { visitor.visit(*this); } diff --git a/document/src/vespa/document/fieldvalue/arrayfieldvalue.cpp b/document/src/vespa/document/fieldvalue/arrayfieldvalue.cpp index 07f731a9ea7..457b510e78a 100644 --- a/document/src/vespa/document/fieldvalue/arrayfieldvalue.cpp +++ b/document/src/vespa/document/fieldvalue/arrayfieldvalue.cpp @@ -23,10 +23,8 @@ using fieldvalue::ModificationStatus; using fieldvalue::IteratorHandler; using fieldvalue::VariableMap; -IMPLEMENT_IDENTIFIABLE_ABSTRACT(ArrayFieldValue, CollectionFieldValue); - ArrayFieldValue::ArrayFieldValue(const DataType &type) - : CollectionFieldValue(type), + : CollectionFieldValue(Type::ARRAY, type), _array() { _array.reset(static_cast<IArray *>(createArray(getNestedType()).release())); diff --git a/document/src/vespa/document/fieldvalue/arrayfieldvalue.h b/document/src/vespa/document/fieldvalue/arrayfieldvalue.h index c4f879f7348..af14c689be3 100644 --- a/document/src/vespa/document/fieldvalue/arrayfieldvalue.h +++ b/document/src/vespa/document/fieldvalue/arrayfieldvalue.h @@ -18,7 +18,7 @@ namespace document { -class ArrayFieldValue : public CollectionFieldValue { +class ArrayFieldValue final : public CollectionFieldValue { private: using IArray = vespalib::IArrayT<FieldValue>; std::unique_ptr<IArray> _array; @@ -75,7 +75,6 @@ public: const_iterator begin() const { return array().begin(); } const_iterator end() const { return array().end(); } - DECLARE_IDENTIFIABLE_ABSTRACT(ArrayFieldValue); private: iterator begin() { return array().begin(); } iterator end() { return array().end(); } diff --git a/document/src/vespa/document/fieldvalue/boolfieldvalue.cpp b/document/src/vespa/document/fieldvalue/boolfieldvalue.cpp index 1c5261877fd..a249f6e2a68 100644 --- a/document/src/vespa/document/fieldvalue/boolfieldvalue.cpp +++ b/document/src/vespa/document/fieldvalue/boolfieldvalue.cpp @@ -9,16 +9,15 @@ using namespace vespalib::xml; namespace document { -IMPLEMENT_IDENTIFIABLE(BoolFieldValue, FieldValue); - BoolFieldValue::BoolFieldValue(bool value) - : _value(value), _altered(false) { + : FieldValue(Type::BOOL), _value(value), _altered(false) { } BoolFieldValue::~BoolFieldValue() = default; -FieldValue &BoolFieldValue::assign(const FieldValue &rhs) { - if (rhs.inherits(BoolFieldValue::classId)) { +FieldValue & +BoolFieldValue::assign(const FieldValue &rhs) { + if (rhs.isA(Type::BOOL)) { operator=(static_cast<const BoolFieldValue &>(rhs)); return *this; } else { @@ -27,18 +26,21 @@ FieldValue &BoolFieldValue::assign(const FieldValue &rhs) { } } -int BoolFieldValue::compare(const FieldValue&rhs) const { +int +BoolFieldValue::compare(const FieldValue&rhs) const { int diff = FieldValue::compare(rhs); if (diff != 0) return diff; const BoolFieldValue &o = static_cast<const BoolFieldValue &>(rhs); return (_value == o._value) ? 0 : _value ? 1 : -1; } -void BoolFieldValue::printXml(XmlOutputStream& out) const { +void +BoolFieldValue::printXml(XmlOutputStream& out) const { out << XmlContent(getAsString()); } -void BoolFieldValue::print(std::ostream& out, bool, const std::string&) const { +void +BoolFieldValue::print(std::ostream& out, bool, const std::string&) const { out << (_value ? "true" : "false") << "\n"; } diff --git a/document/src/vespa/document/fieldvalue/boolfieldvalue.h b/document/src/vespa/document/fieldvalue/boolfieldvalue.h index 01cfcf2cd48..e4431b36a6d 100644 --- a/document/src/vespa/document/fieldvalue/boolfieldvalue.h +++ b/document/src/vespa/document/fieldvalue/boolfieldvalue.h @@ -9,7 +9,7 @@ namespace document { /** * Represent the value in a field of type 'bool' which can be either true or false. **/ -class BoolFieldValue : public FieldValue { +class BoolFieldValue final : public FieldValue { bool _value; bool _altered; @@ -42,7 +42,6 @@ public: vespalib::string getAsString() const override; BoolFieldValue& operator=(vespalib::stringref) override; - DECLARE_IDENTIFIABLE(BoolFieldValue); static std::unique_ptr<BoolFieldValue> make(bool value=false) { return std::make_unique<BoolFieldValue>(value); } }; diff --git a/document/src/vespa/document/fieldvalue/bytefieldvalue.cpp b/document/src/vespa/document/fieldvalue/bytefieldvalue.cpp index 5d514352302..fff07d9de4e 100644 --- a/document/src/vespa/document/fieldvalue/bytefieldvalue.cpp +++ b/document/src/vespa/document/fieldvalue/bytefieldvalue.cpp @@ -5,6 +5,4 @@ namespace document { -IMPLEMENT_IDENTIFIABLE(ByteFieldValue, NumericFieldValueBase); - } // document diff --git a/document/src/vespa/document/fieldvalue/bytefieldvalue.h b/document/src/vespa/document/fieldvalue/bytefieldvalue.h index 2cccf483c84..1b810828c53 100644 --- a/document/src/vespa/document/fieldvalue/bytefieldvalue.h +++ b/document/src/vespa/document/fieldvalue/bytefieldvalue.h @@ -12,12 +12,12 @@ namespace document { -class ByteFieldValue : public NumericFieldValue<int8_t> { +class ByteFieldValue final : public NumericFieldValue<int8_t> { public: typedef int8_t Number; ByteFieldValue(Number value = 0) - : NumericFieldValue<Number>(value) {} + : NumericFieldValue<Number>(Type::BYTE, value) {} void accept(FieldValueVisitor &visitor) override { visitor.visit(*this); } void accept(ConstFieldValueVisitor &visitor) const override { visitor.visit(*this); } @@ -25,7 +25,6 @@ public: ByteFieldValue* clone() const override { return new ByteFieldValue(*this); } using NumericFieldValue<Number>::operator=; - DECLARE_IDENTIFIABLE(ByteFieldValue); static std::unique_ptr<ByteFieldValue> make(Number value=0) { return std::make_unique<ByteFieldValue>(value); } }; diff --git a/document/src/vespa/document/fieldvalue/collectionfieldvalue.cpp b/document/src/vespa/document/fieldvalue/collectionfieldvalue.cpp index 4c960502b71..b9400a1e663 100644 --- a/document/src/vespa/document/fieldvalue/collectionfieldvalue.cpp +++ b/document/src/vespa/document/fieldvalue/collectionfieldvalue.cpp @@ -5,7 +5,6 @@ namespace document { -IMPLEMENT_IDENTIFIABLE_ABSTRACT(CollectionFieldValue, FieldValue); CollectionFieldValue::CollectionFieldValue(const CollectionFieldValue& other) : FieldValue(other), diff --git a/document/src/vespa/document/fieldvalue/collectionfieldvalue.h b/document/src/vespa/document/fieldvalue/collectionfieldvalue.h index 9efd3b91bc6..d4a1367bee2 100644 --- a/document/src/vespa/document/fieldvalue/collectionfieldvalue.h +++ b/document/src/vespa/document/fieldvalue/collectionfieldvalue.h @@ -27,9 +27,9 @@ protected: void verifyType(const CollectionFieldValue& other) const; public: - CollectionFieldValue(const DataType &type) - : FieldValue(), - _type(&type) + CollectionFieldValue(Type type, const DataType &dataType) + : FieldValue(type), + _type(&dataType) {} CollectionFieldValue(const CollectionFieldValue& other); @@ -61,8 +61,6 @@ public: virtual bool isEmpty() const = 0; virtual size_t size() const = 0; virtual void clear() = 0; - - DECLARE_IDENTIFIABLE_ABSTRACT(CollectionFieldValue); }; } diff --git a/document/src/vespa/document/fieldvalue/document.cpp b/document/src/vespa/document/fieldvalue/document.cpp index 57787738502..04c328cad5c 100644 --- a/document/src/vespa/document/fieldvalue/document.cpp +++ b/document/src/vespa/document/fieldvalue/document.cpp @@ -65,10 +65,8 @@ Document::setType(const DataType & type) { _fields.setType(getType().getFieldsType()); } -IMPLEMENT_IDENTIFIABLE_ABSTRACT(Document, StructuredFieldValue); - Document::Document() - : StructuredFieldValue(*DataType::DOCUMENT), + : StructuredFieldValue(Type::DOCUMENT, *DataType::DOCUMENT), _id(), _fields(getType().getFieldsType()), _backingBuffer(), @@ -86,7 +84,7 @@ Document::Document(const Document& rhs) {} Document::Document(const DataType &type, DocumentId documentId) - : StructuredFieldValue(verifyDocumentType(&type)), + : StructuredFieldValue(Type::DOCUMENT, verifyDocumentType(&type)), _id(std::move(documentId)), _fields(getType().getFieldsType()), _backingBuffer(), @@ -104,7 +102,7 @@ void Document::setRepo(const DocumentTypeRepo& repo) } Document::Document(const DocumentTypeRepo& repo, vespalib::nbostream & is) - : StructuredFieldValue(*DataType::DOCUMENT), + : StructuredFieldValue(Type::DOCUMENT, *DataType::DOCUMENT), _id(), _fields(static_cast<const DocumentType &>(getType()).getFieldsType()), _backingBuffer(), @@ -114,7 +112,7 @@ Document::Document(const DocumentTypeRepo& repo, vespalib::nbostream & is) } Document::Document(const DocumentTypeRepo& repo, vespalib::DataBuffer && backingBuffer) - : StructuredFieldValue(*DataType::DOCUMENT), + : StructuredFieldValue(Type::DOCUMENT, *DataType::DOCUMENT), _id(), _fields(static_cast<const DocumentType &>(getType()).getFieldsType()), _backingBuffer(), diff --git a/document/src/vespa/document/fieldvalue/document.h b/document/src/vespa/document/fieldvalue/document.h index da6bcca777c..30a168ca5b0 100644 --- a/document/src/vespa/document/fieldvalue/document.h +++ b/document/src/vespa/document/fieldvalue/document.h @@ -24,7 +24,7 @@ namespace document { class TransactionGuard; -class Document : public StructuredFieldValue +class Document final : public StructuredFieldValue { private: DocumentId _id; @@ -109,9 +109,6 @@ public: bool empty() const override { return _fields.empty(); } uint32_t calculateChecksum() const; - - DECLARE_IDENTIFIABLE_ABSTRACT(Document); - void setFieldValue(const Field& field, FieldValue::UP data) override; private: friend TransactionGuard; diff --git a/document/src/vespa/document/fieldvalue/doublefieldvalue.cpp b/document/src/vespa/document/fieldvalue/doublefieldvalue.cpp index 943255e5ffc..3ab255be8db 100644 --- a/document/src/vespa/document/fieldvalue/doublefieldvalue.cpp +++ b/document/src/vespa/document/fieldvalue/doublefieldvalue.cpp @@ -5,6 +5,5 @@ namespace document { -IMPLEMENT_IDENTIFIABLE(DoubleFieldValue, NumericFieldValueBase); } // document diff --git a/document/src/vespa/document/fieldvalue/doublefieldvalue.h b/document/src/vespa/document/fieldvalue/doublefieldvalue.h index b9b20bbd24a..56ba6e334e9 100644 --- a/document/src/vespa/document/fieldvalue/doublefieldvalue.h +++ b/document/src/vespa/document/fieldvalue/doublefieldvalue.h @@ -12,11 +12,11 @@ namespace document { -class DoubleFieldValue : public NumericFieldValue<double> { +class DoubleFieldValue final : public NumericFieldValue<double> { public: typedef double Number; - DoubleFieldValue(Number value = 0) : NumericFieldValue<Number>(value) {} + DoubleFieldValue(Number value = 0) : NumericFieldValue<Number>(Type::DOUBLE, value) {} void accept(FieldValueVisitor &visitor) override { visitor.visit(*this); } void accept(ConstFieldValueVisitor &visitor) const override { visitor.visit(*this); } @@ -25,7 +25,6 @@ public: DoubleFieldValue* clone() const override { return new DoubleFieldValue(*this); } using NumericFieldValue<Number>::operator=; - DECLARE_IDENTIFIABLE(DoubleFieldValue); static std::unique_ptr<DoubleFieldValue> make(Number value=0) { return std::make_unique<DoubleFieldValue>(value); } }; diff --git a/document/src/vespa/document/fieldvalue/fieldvalue.cpp b/document/src/vespa/document/fieldvalue/fieldvalue.cpp index cc55775d54c..465847c1221 100644 --- a/document/src/vespa/document/fieldvalue/fieldvalue.cpp +++ b/document/src/vespa/document/fieldvalue/fieldvalue.cpp @@ -26,8 +26,6 @@ namespace document { using namespace fieldvalue; -IMPLEMENT_IDENTIFIABLE_ABSTRACT(FieldValue, vespalib::Identifiable); - void FieldValue::serialize(nbostream &stream) const { VespaDocumentSerializer serializer(stream); serializer.write(*this); diff --git a/document/src/vespa/document/fieldvalue/fieldvalue.h b/document/src/vespa/document/fieldvalue/fieldvalue.h index 5eadb3307b5..1099f9c00f7 100644 --- a/document/src/vespa/document/fieldvalue/fieldvalue.h +++ b/document/src/vespa/document/fieldvalue/fieldvalue.h @@ -13,38 +13,31 @@ #include "fieldvaluevisitor.h" #include "modificationstatus.h" -#include <vespa/document/util/xmlserializable.h> +#include <vespa/document/util/identifiableid.h> #include <vespa/document/base/fieldpath.h> #include <vespa/vespalib/objects/identifiable.h> #include <vespa/vespalib/util/polymorphicarraybase.h> namespace vespalib { class nbostream; } +namespace vespalib::xml { class XmlOutputStream; } -namespace document { +namespace document::fieldvalue { class IteratorHandler; } -namespace fieldvalue { class IteratorHandler; } +namespace document { class DataType; -class FieldValue : public vespalib::Identifiable +class FieldValue { -protected: - FieldValue(const FieldValue&) = default; - FieldValue& operator=(const FieldValue&) = default; - FieldValue(FieldValue &&) = default; - FieldValue& operator=(FieldValue &&) = default; - static std::unique_ptr<vespalib::IArrayBase> createArray(const DataType & baseType); - public: + enum class Type : uint8_t {NONE,BOOL, BYTE, SHORT, INT, LONG, FLOAT, DOUBLE, STRING, RAW, PREDICATE, TENSOR, ANNOTATION_REFERENCE, REFERENCE, ARRAY, WSET, MAP, STRUCT, DOCUMENT}; using PathRange = FieldPath::Range<FieldPath::const_iterator>; using UP = std::unique_ptr<FieldValue>; using SP = std::shared_ptr<FieldValue>; using CP = vespalib::CloneablePtr<FieldValue>; + using XmlOutputStream = vespalib::xml::XmlOutputStream; - DECLARE_IDENTIFIABLE_ABSTRACT(FieldValue); - - FieldValue() = default; - + virtual ~FieldValue() = default; /** * Visit this fieldvalue for double dispatch. */ @@ -174,6 +167,26 @@ public: // Utility functions to set commonly used value types. virtual FieldValue& operator=(vespalib::stringref); + + Type type() const { return _type; } + bool isA(Type type) const { return type == _type; } + bool isCollection() const { return (_type == Type::WSET) || (_type == Type::ARRAY); } + bool isStructured() const { return (_type == Type::DOCUMENT) || (_type == Type::STRUCT); } + bool isLiteral() const { return (_type == Type::STRING) || (_type == Type::RAW); } + bool isNumeric() const { + return (_type == Type::BYTE) || (_type == Type::SHORT) || + (_type == Type::INT) || (_type == Type::LONG) || (_type == Type::FLOAT) || (_type == Type::DOUBLE); + } + bool isFixedSizeSingleValue() const { + return (_type == Type::BOOL) || isNumeric(); + } +protected: + FieldValue(Type type) : _type(type) { } + FieldValue(const FieldValue&) = default; + FieldValue& operator=(const FieldValue&) = default; + FieldValue(FieldValue &&) = default; + FieldValue& operator=(FieldValue &&) = default; + static std::unique_ptr<vespalib::IArrayBase> createArray(const DataType & baseType); private: fieldvalue::ModificationStatus iterateNested(FieldPath::const_iterator start, FieldPath::const_iterator end, fieldvalue::IteratorHandler & handler) const { @@ -181,10 +194,12 @@ private: } virtual FieldValue::UP onGetNestedFieldValue(PathRange nested) const; virtual fieldvalue::ModificationStatus onIterateNested(PathRange nested, fieldvalue::IteratorHandler & handler) const; + + Type _type; }; std::ostream& operator<<(std::ostream& out, const FieldValue & p); -XmlOutputStream & operator<<(XmlOutputStream & out, const FieldValue & p); +vespalib::xml::XmlOutputStream & operator<<(vespalib::xml::XmlOutputStream & out, const FieldValue & p); } // document diff --git a/document/src/vespa/document/fieldvalue/floatfieldvalue.cpp b/document/src/vespa/document/fieldvalue/floatfieldvalue.cpp index e44f36295c4..b3698841667 100644 --- a/document/src/vespa/document/fieldvalue/floatfieldvalue.cpp +++ b/document/src/vespa/document/fieldvalue/floatfieldvalue.cpp @@ -5,6 +5,4 @@ namespace document { -IMPLEMENT_IDENTIFIABLE(FloatFieldValue, NumericFieldValueBase); - } // document diff --git a/document/src/vespa/document/fieldvalue/floatfieldvalue.h b/document/src/vespa/document/fieldvalue/floatfieldvalue.h index f662c400633..783459dec64 100644 --- a/document/src/vespa/document/fieldvalue/floatfieldvalue.h +++ b/document/src/vespa/document/fieldvalue/floatfieldvalue.h @@ -12,11 +12,11 @@ namespace document { -class FloatFieldValue : public NumericFieldValue<float> { +class FloatFieldValue final : public NumericFieldValue<float> { public: typedef float Number; - FloatFieldValue(Number value = 0) : NumericFieldValue<Number>(value) {} + FloatFieldValue(Number value = 0) : NumericFieldValue<Number>(Type::FLOAT, value) {} void accept(FieldValueVisitor &visitor) override { visitor.visit(*this); } void accept(ConstFieldValueVisitor &visitor) const override { visitor.visit(*this); } @@ -25,7 +25,6 @@ public: FloatFieldValue* clone() const override { return new FloatFieldValue(*this); } using NumericFieldValue<Number>::operator=; - DECLARE_IDENTIFIABLE(FloatFieldValue); static std::unique_ptr<FloatFieldValue> make(Number value = 0) { return std::make_unique<FloatFieldValue>(value); } }; diff --git a/document/src/vespa/document/fieldvalue/intfieldvalue.cpp b/document/src/vespa/document/fieldvalue/intfieldvalue.cpp index 06edafcf374..42884c9fc8b 100644 --- a/document/src/vespa/document/fieldvalue/intfieldvalue.cpp +++ b/document/src/vespa/document/fieldvalue/intfieldvalue.cpp @@ -5,6 +5,5 @@ namespace document { -IMPLEMENT_IDENTIFIABLE(IntFieldValue, NumericFieldValueBase); } // document diff --git a/document/src/vespa/document/fieldvalue/intfieldvalue.h b/document/src/vespa/document/fieldvalue/intfieldvalue.h index d365e34779e..521aced292c 100644 --- a/document/src/vespa/document/fieldvalue/intfieldvalue.h +++ b/document/src/vespa/document/fieldvalue/intfieldvalue.h @@ -12,11 +12,11 @@ namespace document { -class IntFieldValue : public NumericFieldValue<int32_t> { +class IntFieldValue final : public NumericFieldValue<int32_t> { public: typedef int32_t Number; - IntFieldValue(Number value = 0) : NumericFieldValue<Number>(value) {} + IntFieldValue(Number value = 0) : NumericFieldValue<Number>(Type::INT, value) {} void accept(FieldValueVisitor &visitor) override { visitor.visit(*this); } void accept(ConstFieldValueVisitor &visitor) const override { visitor.visit(*this); } @@ -25,7 +25,6 @@ public: IntFieldValue* clone() const override { return new IntFieldValue(*this); } using NumericFieldValue<Number>::operator=; - DECLARE_IDENTIFIABLE(IntFieldValue); static std::unique_ptr<IntFieldValue> make(Number value=0) { return std::make_unique<IntFieldValue>(value); } }; diff --git a/document/src/vespa/document/fieldvalue/literalfieldvalue.cpp b/document/src/vespa/document/fieldvalue/literalfieldvalue.cpp index 7ba537d9cc2..ea945dfd688 100644 --- a/document/src/vespa/document/fieldvalue/literalfieldvalue.cpp +++ b/document/src/vespa/document/fieldvalue/literalfieldvalue.cpp @@ -8,10 +8,8 @@ using namespace vespalib::xml; namespace document { -IMPLEMENT_IDENTIFIABLE_ABSTRACT(LiteralFieldValueB, FieldValue); - -LiteralFieldValueB::LiteralFieldValueB() : - FieldValue(), +LiteralFieldValueB::LiteralFieldValueB(Type type) : + FieldValue(type), _value(), _backing(), _altered(true) @@ -30,8 +28,8 @@ LiteralFieldValueB::LiteralFieldValueB(const LiteralFieldValueB& other) _value = _backing; } -LiteralFieldValueB::LiteralFieldValueB(const stringref & value) - : FieldValue(), +LiteralFieldValueB::LiteralFieldValueB(Type type, const stringref & value) + : FieldValue(type), _value(), _backing(value), _altered(true) diff --git a/document/src/vespa/document/fieldvalue/literalfieldvalue.h b/document/src/vespa/document/fieldvalue/literalfieldvalue.h index 6e3f0223b20..20da3b3e70d 100644 --- a/document/src/vespa/document/fieldvalue/literalfieldvalue.h +++ b/document/src/vespa/document/fieldvalue/literalfieldvalue.h @@ -24,15 +24,14 @@ class LiteralFieldValueB : public FieldValue { public: typedef vespalib::string string; typedef vespalib::stringref stringref; - DECLARE_IDENTIFIABLE_ABSTRACT(LiteralFieldValueB); typedef std::unique_ptr<LiteralFieldValueB> UP; typedef string value_type; - LiteralFieldValueB(); + LiteralFieldValueB(Type type); ~LiteralFieldValueB(); LiteralFieldValueB(const LiteralFieldValueB &); - LiteralFieldValueB(const stringref & value); + LiteralFieldValueB(Type type, const stringref & value); const value_type & getValue() const { sync(); return _backing; } /** @@ -83,15 +82,15 @@ private: virtual bool getAddZeroTerm() const = 0; }; -template<typename SubClass, int type, bool addZeroTerm> +template<typename SubClass, int dataType, bool addZeroTerm> class LiteralFieldValue : public LiteralFieldValueB { private: bool getAddZeroTerm() const override{ return addZeroTerm; } public: typedef std::unique_ptr<SubClass> UP; - LiteralFieldValue() : LiteralFieldValueB() { } - LiteralFieldValue(const stringref& value) : LiteralFieldValueB(value) { } + LiteralFieldValue(Type type) : LiteralFieldValueB(type) { } + LiteralFieldValue(Type type, const stringref& value) : LiteralFieldValueB(type, value) { } const DataType *getDataType() const override; }; diff --git a/document/src/vespa/document/fieldvalue/literalfieldvalue.hpp b/document/src/vespa/document/fieldvalue/literalfieldvalue.hpp index c5b30bc5ff1..b9335da67b4 100644 --- a/document/src/vespa/document/fieldvalue/literalfieldvalue.hpp +++ b/document/src/vespa/document/fieldvalue/literalfieldvalue.hpp @@ -6,17 +6,17 @@ namespace document { -template<typename SubClass, int type, bool addZeroTerm> +template<typename SubClass, int dataType, bool addZeroTerm> const DataType * -LiteralFieldValue<SubClass, type, addZeroTerm>::getDataType() const +LiteralFieldValue<SubClass, dataType, addZeroTerm>::getDataType() const { - switch (type) { + switch (dataType) { case DataType::T_URI: return DataType::URI; case DataType::T_STRING: return DataType::STRING; case DataType::T_RAW: return DataType::RAW; default: throw vespalib::IllegalStateException(vespalib::make_string( - "Illegal literal type id %i", type), VESPA_STRLOC); + "Illegal literal type id %i", dataType), VESPA_STRLOC); } } diff --git a/document/src/vespa/document/fieldvalue/longfieldvalue.cpp b/document/src/vespa/document/fieldvalue/longfieldvalue.cpp index f2f6cdb52b5..04f39f64beb 100644 --- a/document/src/vespa/document/fieldvalue/longfieldvalue.cpp +++ b/document/src/vespa/document/fieldvalue/longfieldvalue.cpp @@ -4,6 +4,4 @@ namespace document { -IMPLEMENT_IDENTIFIABLE(LongFieldValue, NumericFieldValueBase); - } // document diff --git a/document/src/vespa/document/fieldvalue/longfieldvalue.h b/document/src/vespa/document/fieldvalue/longfieldvalue.h index 64ab4332cef..4b73ef0c2ea 100644 --- a/document/src/vespa/document/fieldvalue/longfieldvalue.h +++ b/document/src/vespa/document/fieldvalue/longfieldvalue.h @@ -12,11 +12,11 @@ namespace document { -class LongFieldValue : public NumericFieldValue<int64_t> { +class LongFieldValue final : public NumericFieldValue<int64_t> { public: typedef int64_t Number; - LongFieldValue(Number value = 0) : NumericFieldValue<Number>(value) {} + LongFieldValue(Number value = 0) : NumericFieldValue<Number>(Type::LONG, value) {} void accept(FieldValueVisitor &visitor) override { visitor.visit(*this); } void accept(ConstFieldValueVisitor &visitor) const override { visitor.visit(*this); } @@ -25,7 +25,6 @@ public: LongFieldValue* clone() const override { return new LongFieldValue(*this); } using NumericFieldValue<Number>::operator=; - DECLARE_IDENTIFIABLE(LongFieldValue); static std::unique_ptr<LongFieldValue> make(Number value=0) { return std::make_unique<LongFieldValue>(value); } }; diff --git a/document/src/vespa/document/fieldvalue/mapfieldvalue.cpp b/document/src/vespa/document/fieldvalue/mapfieldvalue.cpp index 872185e7523..3fc8a3129f0 100644 --- a/document/src/vespa/document/fieldvalue/mapfieldvalue.cpp +++ b/document/src/vespa/document/fieldvalue/mapfieldvalue.cpp @@ -25,8 +25,6 @@ namespace document { using namespace fieldvalue; -IMPLEMENT_IDENTIFIABLE_ABSTRACT(MapFieldValue, FieldValue); - namespace { const MapDataType *verifyMapType(const DataType& type) { const MapDataType *ptr(dynamic_cast<const MapDataType *>(&type)); @@ -75,7 +73,7 @@ public: } MapFieldValue::MapFieldValue(const DataType &mapType) - : FieldValue(), + : FieldValue(Type::MAP), _type(verifyMapType(mapType)), _count(0), _keys(static_cast<IArray *>(createArray(getMapType().getKeyType()).release())), @@ -369,7 +367,7 @@ MapFieldValue::buildLookupMap() const { MapFieldValue::const_iterator MapFieldValue::find(const FieldValue& key) const { - if ((size() > 0) && (key.getClass().id() == (*_keys)[0].getClass().id())) { + if ((size() > 0) && (key.type() == (*_keys)[0].type())) { ssize_t index = findIndex(key); if (index >= 0) { return const_iterator(*this, index); @@ -381,7 +379,7 @@ MapFieldValue::find(const FieldValue& key) const MapFieldValue::iterator MapFieldValue::find(const FieldValue& key) { - if ((size() > 0) && (key.getClass().id() == (*_keys)[0].getClass().id())) { + if ((size() > 0) && (key.type() == (*_keys)[0].type())) { ssize_t index = findIndex(key); if (index >= 0) { return iterator(*this, index); @@ -393,7 +391,7 @@ MapFieldValue::find(const FieldValue& key) ssize_t MapFieldValue::findIndex(const FieldValue& key) const { - if ((size() > 0) && (key.getClass().id() == (*_keys)[0].getClass().id())) { + if ((size() > 0) && (key.type() == (*_keys)[0].type())) { ensureLookupMap(); auto found = _lookupMap->find(key); if (found != _lookupMap->end()) { @@ -428,7 +426,7 @@ MapFieldValue::iterateNestedImpl(PathRange nested, IteratorHandler::CollectionScope autoScope(handler, complexFieldValue); std::vector<const FieldValue*> keysToRemove; bool wasModified = false; - const bool isWSet(complexFieldValue.inherits(WeightedSetFieldValue::classId)); + const bool isWSet(complexFieldValue.isA(FieldValue::Type::WSET)); uint32_t index(0); if ( ! nested.atEnd() ) { diff --git a/document/src/vespa/document/fieldvalue/mapfieldvalue.h b/document/src/vespa/document/fieldvalue/mapfieldvalue.h index 5e8de6f3ed8..5645bfbe176 100644 --- a/document/src/vespa/document/fieldvalue/mapfieldvalue.h +++ b/document/src/vespa/document/fieldvalue/mapfieldvalue.h @@ -18,7 +18,7 @@ namespace document { namespace mapfieldvalue { class HashMap; } -class MapFieldValue : public FieldValue +class MapFieldValue final : public FieldValue { public: using IArray=vespalib::IArrayT<FieldValue>; @@ -162,8 +162,6 @@ public: } FieldValue::UP createValue() const; - - DECLARE_IDENTIFIABLE_ABSTRACT(MapFieldValue); }; } // namespace document diff --git a/document/src/vespa/document/fieldvalue/numericfieldvalue.cpp b/document/src/vespa/document/fieldvalue/numericfieldvalue.cpp index 7d02054f668..6247e815d73 100644 --- a/document/src/vespa/document/fieldvalue/numericfieldvalue.cpp +++ b/document/src/vespa/document/fieldvalue/numericfieldvalue.cpp @@ -6,8 +6,6 @@ namespace document { -IMPLEMENT_IDENTIFIABLE_ABSTRACT(NumericFieldValueBase, FieldValue); - void NumericFieldValueBase::printXml(XmlOutputStream& out) const { diff --git a/document/src/vespa/document/fieldvalue/numericfieldvalue.h b/document/src/vespa/document/fieldvalue/numericfieldvalue.h index 28981fc5286..91c6826d174 100644 --- a/document/src/vespa/document/fieldvalue/numericfieldvalue.h +++ b/document/src/vespa/document/fieldvalue/numericfieldvalue.h @@ -18,21 +18,21 @@ namespace document { class NumericFieldValueBase : public FieldValue { public: - DECLARE_IDENTIFIABLE_ABSTRACT(NumericFieldValueBase); void printXml(XmlOutputStream& out) const override; +protected: + NumericFieldValueBase(Type type) : FieldValue(type) {} }; template<typename Number> class NumericFieldValue : public NumericFieldValueBase { protected: + explicit NumericFieldValue(Type type, Number value=0) : NumericFieldValueBase(type), _value(value), _altered(false) { } Number _value; bool _altered; public: typedef Number value_type; - explicit NumericFieldValue(Number value=0) : NumericFieldValueBase(), _value(value), _altered(false) { } - value_type getValue() const { return _value; } void setValue(Number newValue) { _value = newValue; } diff --git a/document/src/vespa/document/fieldvalue/numericfieldvalue.hpp b/document/src/vespa/document/fieldvalue/numericfieldvalue.hpp index f1bbce5450d..c9f25d67d59 100644 --- a/document/src/vespa/document/fieldvalue/numericfieldvalue.hpp +++ b/document/src/vespa/document/fieldvalue/numericfieldvalue.hpp @@ -17,17 +17,17 @@ template<typename Number> FieldValue& NumericFieldValue<Number>::assign(const FieldValue& value) { - if (value.getClass().id() == IDENTIFIABLE_CLASSID(ByteFieldValue)) { + if (value.type() == FieldValue::Type::BYTE) { _value = static_cast<Number>(value.getAsByte()); - } else if (value.getClass().id() == IDENTIFIABLE_CLASSID(ShortFieldValue)) { + } else if (value.type() == FieldValue::Type::SHORT) { _value = static_cast<Number>(value.getAsInt()); - } else if (value.getClass().id() == IDENTIFIABLE_CLASSID(IntFieldValue)) { + } else if (value.type() == FieldValue::Type::INT) { _value = static_cast<Number>(value.getAsInt()); - } else if (value.getClass().id() == IDENTIFIABLE_CLASSID(LongFieldValue)) { + } else if (value.type() == FieldValue::Type::LONG) { _value = static_cast<Number>(value.getAsLong()); - } else if (value.getClass().id() == IDENTIFIABLE_CLASSID(FloatFieldValue)) { + } else if (value.type() == FieldValue::Type::FLOAT) { _value = static_cast<Number>(value.getAsFloat()); - } else if (value.getClass().id() == IDENTIFIABLE_CLASSID(DoubleFieldValue)) { + } else if (value.type() == FieldValue::Type::DOUBLE) { _value = static_cast<Number>(value.getAsDouble()); } else { return FieldValue::assign(value); diff --git a/document/src/vespa/document/fieldvalue/predicatefieldvalue.cpp b/document/src/vespa/document/fieldvalue/predicatefieldvalue.cpp index 3a62eb5060c..05a8abc606c 100644 --- a/document/src/vespa/document/fieldvalue/predicatefieldvalue.cpp +++ b/document/src/vespa/document/fieldvalue/predicatefieldvalue.cpp @@ -14,14 +14,14 @@ using namespace vespalib::xml; namespace document { -IMPLEMENT_IDENTIFIABLE(PredicateFieldValue, FieldValue); - PredicateFieldValue::PredicateFieldValue() - : _slime(std::make_unique<Slime>()), _altered(false) { + : FieldValue(Type::PREDICATE), + _slime(std::make_unique<Slime>()), + _altered(false) { } PredicateFieldValue::PredicateFieldValue(vespalib::Slime::UP s) - : FieldValue(), + : FieldValue(Type::PREDICATE), _slime(std::move(s)), _altered(false) { } @@ -38,7 +38,7 @@ PredicateFieldValue::~PredicateFieldValue() = default; FieldValue & PredicateFieldValue::assign(const FieldValue &rhs) { - if (rhs.inherits(PredicateFieldValue::classId)) { + if (rhs.isA(Type::PREDICATE)) { operator=(static_cast<const PredicateFieldValue &>(rhs)); } else { _slime.reset(); diff --git a/document/src/vespa/document/fieldvalue/predicatefieldvalue.h b/document/src/vespa/document/fieldvalue/predicatefieldvalue.h index 5f7db35f953..585722e669a 100644 --- a/document/src/vespa/document/fieldvalue/predicatefieldvalue.h +++ b/document/src/vespa/document/fieldvalue/predicatefieldvalue.h @@ -9,7 +9,7 @@ namespace vespalib { } namespace document { -class PredicateFieldValue : public FieldValue { +class PredicateFieldValue final : public FieldValue { std::unique_ptr<vespalib::Slime> _slime; bool _altered; @@ -38,8 +38,6 @@ public: const vespalib::Slime &getSlime() const { return *_slime; } FieldValue &assign(const FieldValue &rhs) override; - - DECLARE_IDENTIFIABLE(PredicateFieldValue); }; } diff --git a/document/src/vespa/document/fieldvalue/rawfieldvalue.cpp b/document/src/vespa/document/fieldvalue/rawfieldvalue.cpp index 95f066b86ed..ab17a879dfa 100644 --- a/document/src/vespa/document/fieldvalue/rawfieldvalue.cpp +++ b/document/src/vespa/document/fieldvalue/rawfieldvalue.cpp @@ -9,8 +9,6 @@ using namespace vespalib::xml; namespace document { -IMPLEMENT_IDENTIFIABLE(RawFieldValue, LiteralFieldValueB); - void RawFieldValue::printXml(XmlOutputStream& out) const { diff --git a/document/src/vespa/document/fieldvalue/rawfieldvalue.h b/document/src/vespa/document/fieldvalue/rawfieldvalue.h index 98110816a9d..a5e137fc7bf 100644 --- a/document/src/vespa/document/fieldvalue/rawfieldvalue.h +++ b/document/src/vespa/document/fieldvalue/rawfieldvalue.h @@ -12,20 +12,19 @@ namespace document { -class RawFieldValue - : public LiteralFieldValue<RawFieldValue, DataType::T_RAW, false> +class RawFieldValue final : public LiteralFieldValue<RawFieldValue, DataType::T_RAW, false> { public: typedef LiteralFieldValue<RawFieldValue, DataType::T_RAW, false> Parent; RawFieldValue() - : Parent() { } + : Parent(Type::RAW) { } RawFieldValue(const string& value) - : Parent(value) {} + : Parent(Type::RAW, value) {} RawFieldValue(const char* rawVal, int len) - : Parent(string(rawVal, len)) + : Parent(Type::RAW, string(rawVal, len)) { } @@ -37,8 +36,6 @@ public: void print(std::ostream& out, bool verbose, const std::string& indent) const override; RawFieldValue& operator=(const string& value) { setValue(value); return *this; } - - DECLARE_IDENTIFIABLE(RawFieldValue); }; } // document diff --git a/document/src/vespa/document/fieldvalue/referencefieldvalue.cpp b/document/src/vespa/document/fieldvalue/referencefieldvalue.cpp index 328e5b67151..d4e02d2da07 100644 --- a/document/src/vespa/document/fieldvalue/referencefieldvalue.cpp +++ b/document/src/vespa/document/fieldvalue/referencefieldvalue.cpp @@ -11,26 +11,25 @@ using vespalib::make_string; namespace document { -IMPLEMENT_IDENTIFIABLE(ReferenceFieldValue, FieldValue); - ReferenceFieldValue::ReferenceFieldValue() - : _dataType(nullptr), + : FieldValue(Type::REFERENCE), + _dataType(nullptr), _documentId(), _altered(true) { } ReferenceFieldValue::ReferenceFieldValue(const ReferenceDataType& dataType) - : _dataType(&dataType), + : FieldValue(Type::REFERENCE), + _dataType(&dataType), _documentId(), _altered(true) { } -ReferenceFieldValue::ReferenceFieldValue( - const ReferenceDataType& dataType, - const DocumentId& documentId) - : _dataType(&dataType), +ReferenceFieldValue::ReferenceFieldValue(const ReferenceDataType& dataType, const DocumentId& documentId) + : FieldValue(Type::REFERENCE), + _dataType(&dataType), _documentId(documentId), _altered(true) { diff --git a/document/src/vespa/document/fieldvalue/referencefieldvalue.h b/document/src/vespa/document/fieldvalue/referencefieldvalue.h index d8160353b5f..41fb9a6665e 100644 --- a/document/src/vespa/document/fieldvalue/referencefieldvalue.h +++ b/document/src/vespa/document/fieldvalue/referencefieldvalue.h @@ -22,7 +22,7 @@ namespace document { * document type "foo" inheriting "bar", you cannot have a reference<bar> field * containing a document ID for a "foo" document. */ -class ReferenceFieldValue : public FieldValue { +class ReferenceFieldValue final : public FieldValue { const ReferenceDataType* _dataType; // TODO wrap in std::optional once available. DocumentId _documentId; @@ -66,13 +66,10 @@ public: bool hasChanged() const override; void accept(FieldValueVisitor&) override; void accept(ConstFieldValueVisitor&) const override; - - DECLARE_IDENTIFIABLE(ReferenceFieldValue); private: // Throws vespalib::IllegalArgumentException if doc type of `id` does not // match the name of `type`. - static void requireIdOfMatchingType( - const DocumentId& id, const DocumentType& type); + static void requireIdOfMatchingType(const DocumentId& id, const DocumentType& type); }; } // document diff --git a/document/src/vespa/document/fieldvalue/shortfieldvalue.cpp b/document/src/vespa/document/fieldvalue/shortfieldvalue.cpp index 9f0334a12ae..02fa8fb30a2 100644 --- a/document/src/vespa/document/fieldvalue/shortfieldvalue.cpp +++ b/document/src/vespa/document/fieldvalue/shortfieldvalue.cpp @@ -5,6 +5,4 @@ namespace document { -IMPLEMENT_IDENTIFIABLE(ShortFieldValue, NumericFieldValueBase); - } // document diff --git a/document/src/vespa/document/fieldvalue/shortfieldvalue.h b/document/src/vespa/document/fieldvalue/shortfieldvalue.h index fa61c37c4eb..e135f2a4f54 100644 --- a/document/src/vespa/document/fieldvalue/shortfieldvalue.h +++ b/document/src/vespa/document/fieldvalue/shortfieldvalue.h @@ -12,13 +12,13 @@ namespace document { -class ShortFieldValue : public NumericFieldValue<int16_t> { +class ShortFieldValue final : public NumericFieldValue<int16_t> { public: typedef std::unique_ptr<ShortFieldValue> UP; typedef int16_t Number; ShortFieldValue(Number value = 0) - : NumericFieldValue<Number>(value) {} + : NumericFieldValue<Number>(Type::SHORT, value) {} void accept(FieldValueVisitor &visitor) override { visitor.visit(*this); } void accept(ConstFieldValueVisitor &visitor) const override { visitor.visit(*this); } @@ -27,7 +27,6 @@ public: ShortFieldValue* clone() const override { return new ShortFieldValue(*this); } using NumericFieldValue<Number>::operator=; - DECLARE_IDENTIFIABLE(ShortFieldValue); static std::unique_ptr<ShortFieldValue> make(int16_t value = 0) { return std::make_unique<ShortFieldValue>(value); } }; diff --git a/document/src/vespa/document/fieldvalue/stringfieldvalue.cpp b/document/src/vespa/document/fieldvalue/stringfieldvalue.cpp index 0a46a11bddf..47e96b4f4e4 100644 --- a/document/src/vespa/document/fieldvalue/stringfieldvalue.cpp +++ b/document/src/vespa/document/fieldvalue/stringfieldvalue.cpp @@ -19,17 +19,16 @@ using vespalib::stringref; namespace document { -IMPLEMENT_IDENTIFIABLE(StringFieldValue, LiteralFieldValueB); - -StringFieldValue::StringFieldValue(const StringFieldValue & rhs) : - Parent(rhs), - _annotationData(rhs.copyAnnotationData()) +StringFieldValue::StringFieldValue(const StringFieldValue & rhs) + : Parent(rhs), + _annotationData(rhs.copyAnnotationData()) { } -StringFieldValue::~StringFieldValue() {} +StringFieldValue::~StringFieldValue() = default; -StringFieldValue & StringFieldValue::operator=(const StringFieldValue & rhs) +StringFieldValue & +StringFieldValue::operator=(const StringFieldValue & rhs) { if (&rhs != this) { Parent::operator=(rhs); @@ -38,8 +37,9 @@ StringFieldValue & StringFieldValue::operator=(const StringFieldValue & rhs) return *this; } -int StringFieldValue::compare(const FieldValue& other) const { - if (other.inherits(StringFieldValue::classId)) { +int +StringFieldValue::compare(const FieldValue& other) const { + if (other.isA(Type::STRING)) { const StringFieldValue &other_s(static_cast<const StringFieldValue &>(other)); return _value.compare(other_s._value); } else { @@ -47,7 +47,8 @@ int StringFieldValue::compare(const FieldValue& other) const { } } -void StringFieldValue::print(std::ostream& out, bool verbose, const std::string& indent) const { +void +StringFieldValue::print(std::ostream& out, bool verbose, const std::string& indent) const { if ( ! hasSpanTrees()) { Parent::print(out, verbose, indent); } else { @@ -88,7 +89,8 @@ StringFieldValue::doClearSpanTrees() { _annotationData.reset(); } -const SpanTree * StringFieldValue::findTree(const SpanTrees & trees, stringref name) +const SpanTree * +StringFieldValue::findTree(const SpanTrees & trees, stringref name) { for(const auto & tree : trees) { if (tree->getName() == name) { @@ -98,16 +100,18 @@ const SpanTree * StringFieldValue::findTree(const SpanTrees & trees, stringref n return nullptr; } -StringFieldValue &StringFieldValue::operator=(stringref value) +StringFieldValue & +StringFieldValue::operator=(stringref value) { setValue(value); _annotationData.reset(); return *this; } -FieldValue & StringFieldValue::assign(const FieldValue & rhs) +FieldValue & +StringFieldValue::assign(const FieldValue & rhs) { - if (rhs.inherits(StringFieldValue::classId)) { + if (rhs.isA(Type::STRING)) { *this = static_cast<const StringFieldValue &>(rhs); } else { *this = rhs.getAsString().operator stringref(); diff --git a/document/src/vespa/document/fieldvalue/stringfieldvalue.h b/document/src/vespa/document/fieldvalue/stringfieldvalue.h index 07e9e578692..e3ab5412637 100644 --- a/document/src/vespa/document/fieldvalue/stringfieldvalue.h +++ b/document/src/vespa/document/fieldvalue/stringfieldvalue.h @@ -17,14 +17,14 @@ namespace document { class FixedTypeRepo; class DocumentTypeRepo; -class StringFieldValue : public LiteralFieldValue<StringFieldValue, DataType::T_STRING, true> { +class StringFieldValue final : public LiteralFieldValue<StringFieldValue, DataType::T_STRING, true> { public: typedef LiteralFieldValue<StringFieldValue, DataType::T_STRING, true> Parent; typedef std::vector<SpanTree::UP> SpanTrees; - StringFieldValue() : Parent(), _annotationData() { } + StringFieldValue() : Parent(Type::STRING), _annotationData() { } StringFieldValue(const vespalib::stringref &value) - : Parent(value), _annotationData() { } + : Parent(Type::STRING, value), _annotationData() { } StringFieldValue(const StringFieldValue &rhs); @@ -55,7 +55,6 @@ public: } using LiteralFieldValueB::operator=; - DECLARE_IDENTIFIABLE(StringFieldValue); static std::unique_ptr<StringFieldValue> make(vespalib::stringref value) { return std::make_unique<StringFieldValue>(value); } static std::unique_ptr<StringFieldValue> make() { return StringFieldValue::make(""); } private: diff --git a/document/src/vespa/document/fieldvalue/structfieldvalue.cpp b/document/src/vespa/document/fieldvalue/structfieldvalue.cpp index fbe6dadb320..529e608533e 100644 --- a/document/src/vespa/document/fieldvalue/structfieldvalue.cpp +++ b/document/src/vespa/document/fieldvalue/structfieldvalue.cpp @@ -27,10 +27,8 @@ using namespace vespalib::xml; namespace document { -IMPLEMENT_IDENTIFIABLE_ABSTRACT(StructFieldValue, StructuredFieldValue); - StructFieldValue::StructFieldValue(const DataType &type) - : StructuredFieldValue(type), + : StructuredFieldValue(Type::STRUCT, type), _fields(), _repo(nullptr), _doc_type(nullptr), diff --git a/document/src/vespa/document/fieldvalue/structfieldvalue.h b/document/src/vespa/document/fieldvalue/structfieldvalue.h index 24e143ddc27..c50d8248307 100644 --- a/document/src/vespa/document/fieldvalue/structfieldvalue.h +++ b/document/src/vespa/document/fieldvalue/structfieldvalue.h @@ -22,7 +22,7 @@ class FixedTypeRepo; class FieldSet; class StructDataType; -class StructFieldValue : public StructuredFieldValue +class StructFieldValue final : public StructuredFieldValue { private: SerializableArray _fields; @@ -85,9 +85,6 @@ public: * has no content. This clears content and sets changed to false. */ void reset(); - - DECLARE_IDENTIFIABLE_ABSTRACT(StructFieldValue); - private: void setFieldValue(const Field&, FieldValue::UP value) override; FieldValue::UP getFieldValue(const Field&) const override; diff --git a/document/src/vespa/document/fieldvalue/structuredfieldvalue.cpp b/document/src/vespa/document/fieldvalue/structuredfieldvalue.cpp index 53f75cb2e73..53a5fa14fee 100644 --- a/document/src/vespa/document/fieldvalue/structuredfieldvalue.cpp +++ b/document/src/vespa/document/fieldvalue/structuredfieldvalue.cpp @@ -16,8 +16,6 @@ namespace document { using namespace fieldvalue; -IMPLEMENT_IDENTIFIABLE_ABSTRACT(StructuredFieldValue, FieldValue); - StructuredFieldValue::Iterator::Iterator() : _iterator(), _field(nullptr) diff --git a/document/src/vespa/document/fieldvalue/structuredfieldvalue.h b/document/src/vespa/document/fieldvalue/structuredfieldvalue.h index 9d79b6279a4..fdc4ecf7765 100644 --- a/document/src/vespa/document/fieldvalue/structuredfieldvalue.h +++ b/document/src/vespa/document/fieldvalue/structuredfieldvalue.h @@ -44,7 +44,7 @@ class StructuredFieldValue : public FieldValue virtual StructuredCache * getCache() const { return nullptr; } protected: - StructuredFieldValue(const DataType &type) : FieldValue(), _type(&type) {} + StructuredFieldValue(Type type, const DataType &dataType) : FieldValue(type), _type(&dataType) {} /** Called from Document when deserializing alters type. */ virtual void setType(const DataType& type) { _type = &type; } @@ -106,8 +106,6 @@ protected: fieldvalue::ModificationStatus onIterateNested(PathRange nested, fieldvalue::IteratorHandler & handler) const override; public: - DECLARE_IDENTIFIABLE_ABSTRACT(StructuredFieldValue); - StructuredFieldValue* clone() const override = 0; const DataType *getDataType() const override { return _type; } diff --git a/document/src/vespa/document/fieldvalue/structuredfieldvalue.hpp b/document/src/vespa/document/fieldvalue/structuredfieldvalue.hpp index 4b347d7cc07..c142fd9b6eb 100644 --- a/document/src/vespa/document/fieldvalue/structuredfieldvalue.hpp +++ b/document/src/vespa/document/fieldvalue/structuredfieldvalue.hpp @@ -12,7 +12,7 @@ template <typename T> std::unique_ptr<T> StructuredFieldValue::getAs(const Field &field) const { FieldValue::UP val = getValue(field); - T *t = Identifiable::cast<T *>(val.get()); + T *t = dynamic_cast<T *>(val.get()); if (val.get() && !t) { throw vespalib::IllegalStateException("Field " + field.toString() + " has unexpected type.", VESPA_STRLOC); } diff --git a/document/src/vespa/document/fieldvalue/tensorfieldvalue.cpp b/document/src/vespa/document/fieldvalue/tensorfieldvalue.cpp index 42f4080d6b6..66cfbc42c07 100644 --- a/document/src/vespa/document/fieldvalue/tensorfieldvalue.cpp +++ b/document/src/vespa/document/fieldvalue/tensorfieldvalue.cpp @@ -36,7 +36,7 @@ TensorFieldValue::TensorFieldValue() } TensorFieldValue::TensorFieldValue(const TensorDataType &dataType) - : FieldValue(), + : FieldValue(Type::TENSOR), _dataType(dataType), _tensor(), _altered(true) @@ -44,7 +44,7 @@ TensorFieldValue::TensorFieldValue(const TensorDataType &dataType) } TensorFieldValue::TensorFieldValue(const TensorFieldValue &rhs) - : FieldValue(), + : FieldValue(Type::TENSOR), _dataType(rhs._dataType), _tensor(), _altered(true) @@ -56,7 +56,7 @@ TensorFieldValue::TensorFieldValue(const TensorFieldValue &rhs) TensorFieldValue::TensorFieldValue(TensorFieldValue &&rhs) - : FieldValue(), + : FieldValue(Type::TENSOR), _dataType(rhs._dataType), _tensor(), _altered(true) @@ -173,9 +173,8 @@ TensorFieldValue::printXml(XmlOutputStream& out) const FieldValue & TensorFieldValue::assign(const FieldValue &value) { - const TensorFieldValue *rhs = - Identifiable::cast<const TensorFieldValue *>(&value); - if (rhs != nullptr) { + if (value.isA(Type::TENSOR)) { + auto rhs = static_cast<const TensorFieldValue *>(&value); *this = *rhs; } else { return FieldValue::assign(value); @@ -232,6 +231,4 @@ TensorFieldValue::compare(const FieldValue &other) const return lhs_spec.compare(rhs_spec); } -IMPLEMENT_IDENTIFIABLE(TensorFieldValue, FieldValue); - } // document diff --git a/document/src/vespa/document/fieldvalue/tensorfieldvalue.h b/document/src/vespa/document/fieldvalue/tensorfieldvalue.h index 6cb2ff08c2e..058e2b86297 100644 --- a/document/src/vespa/document/fieldvalue/tensorfieldvalue.h +++ b/document/src/vespa/document/fieldvalue/tensorfieldvalue.h @@ -13,7 +13,7 @@ class TensorDataType; /** * Field value representing a tensor. */ -class TensorFieldValue : public FieldValue { +class TensorFieldValue final : public FieldValue { private: const TensorDataType &_dataType; std::unique_ptr<vespalib::eval::Value> _tensor; @@ -23,29 +23,26 @@ public: explicit TensorFieldValue(const TensorDataType &dataType); TensorFieldValue(const TensorFieldValue &rhs); TensorFieldValue(TensorFieldValue &&rhs); - ~TensorFieldValue(); + ~TensorFieldValue() override; TensorFieldValue &operator=(const TensorFieldValue &rhs); TensorFieldValue &operator=(std::unique_ptr<vespalib::eval::Value> rhs); void make_empty_if_not_existing(); - virtual void accept(FieldValueVisitor &visitor) override; - virtual void accept(ConstFieldValueVisitor &visitor) const override; - virtual const DataType *getDataType() const override; - virtual bool hasChanged() const override; - virtual TensorFieldValue* clone() const override; - virtual void print(std::ostream& out, bool verbose, - const std::string& indent) const override; - virtual void printXml(XmlOutputStream& out) const override; - virtual FieldValue &assign(const FieldValue &value) override; + void accept(FieldValueVisitor &visitor) override; + void accept(ConstFieldValueVisitor &visitor) const override; + const DataType *getDataType() const override; + bool hasChanged() const override; + TensorFieldValue* clone() const override; + void print(std::ostream& out, bool verbose, const std::string& indent) const override; + void printXml(XmlOutputStream& out) const override; + FieldValue &assign(const FieldValue &value) override; const vespalib::eval::Value *getAsTensorPtr() const { return _tensor.get(); } void assignDeserialized(std::unique_ptr<vespalib::eval::Value> rhs); - virtual int compare(const FieldValue& other) const override; - - DECLARE_IDENTIFIABLE(TensorFieldValue); + int compare(const FieldValue& other) const override; }; } // document diff --git a/document/src/vespa/document/fieldvalue/weightedsetfieldvalue.cpp b/document/src/vespa/document/fieldvalue/weightedsetfieldvalue.cpp index 2a3726095df..d6d092a8a99 100644 --- a/document/src/vespa/document/fieldvalue/weightedsetfieldvalue.cpp +++ b/document/src/vespa/document/fieldvalue/weightedsetfieldvalue.cpp @@ -18,8 +18,6 @@ namespace document { using namespace fieldvalue; -IMPLEMENT_IDENTIFIABLE_ABSTRACT(WeightedSetFieldValue, CollectionFieldValue); - namespace { const DataType &getKeyType(const DataType &type) { const WeightedSetDataType *wtype = dynamic_cast<const WeightedSetDataType *>(&type); @@ -32,7 +30,7 @@ const DataType &getKeyType(const DataType &type) { } // namespace WeightedSetFieldValue::WeightedSetFieldValue(const DataType &type) - : CollectionFieldValue(type), + : CollectionFieldValue(Type::WSET, type), _map_type(std::make_shared<MapDataType>(getKeyType(type), *DataType::INT)), _map(*_map_type), _altered(true) diff --git a/document/src/vespa/document/fieldvalue/weightedsetfieldvalue.h b/document/src/vespa/document/fieldvalue/weightedsetfieldvalue.h index d58819607b4..186c29d71e1 100644 --- a/document/src/vespa/document/fieldvalue/weightedsetfieldvalue.h +++ b/document/src/vespa/document/fieldvalue/weightedsetfieldvalue.h @@ -14,7 +14,7 @@ namespace document { -class WeightedSetFieldValue : public CollectionFieldValue +class WeightedSetFieldValue final : public CollectionFieldValue { public: struct FieldValuePtrOrder { @@ -46,7 +46,7 @@ public: WeightedSetFieldValue & operator = (const WeightedSetFieldValue &); WeightedSetFieldValue(WeightedSetFieldValue &&) = default; WeightedSetFieldValue & operator = (WeightedSetFieldValue &&) = default; - ~WeightedSetFieldValue(); + ~WeightedSetFieldValue() override; void accept(FieldValueVisitor &visitor) override { visitor.visit(*this); } void accept(ConstFieldValueVisitor &visitor) const override { visitor.visit(*this); } @@ -92,8 +92,6 @@ public: const_iterator find(const FieldValue& fv) const; iterator find(const FieldValue& fv); - - DECLARE_IDENTIFIABLE_ABSTRACT(WeightedSetFieldValue); }; } // document diff --git a/document/src/vespa/document/select/valuenodes.cpp b/document/src/vespa/document/select/valuenodes.cpp index 52e6b2e4223..f34b2e83b08 100644 --- a/document/src/vespa/document/select/valuenodes.cpp +++ b/document/src/vespa/document/select/valuenodes.cpp @@ -11,7 +11,6 @@ #include <vespa/vespalib/util/md5.h> #include <vespa/document/util/stringutil.h> #include <vespa/vespalib/text/lowercase.h> -#include <regex> #include <iomanip> #include <sys/time.h> @@ -272,43 +271,43 @@ IteratorHandler::onPrimitive(uint32_t fid, const Content& fv) { std::unique_ptr<Value> IteratorHandler::getInternalValue(const FieldValue& fval) const { - switch(fval.getClass().id()) { - case document::BoolFieldValue::classId: + switch(fval.type()) { + case FieldValue::Type::BOOL: { const auto& val(dynamic_cast<const BoolFieldValue&>(fval)); return std::make_unique<IntegerValue>(val.getAsInt(), false); } - case document::IntFieldValue::classId: + case FieldValue::Type::INT: { const auto& val(dynamic_cast<const IntFieldValue&>(fval)); return std::make_unique<IntegerValue>(val.getAsInt(), false); } - case document::ByteFieldValue::classId: + case FieldValue::Type::BYTE: { const auto& val(dynamic_cast<const ByteFieldValue&>(fval)); return std::make_unique<IntegerValue>(val.getAsByte(), false); } - case LongFieldValue::classId: + case FieldValue::Type::LONG: { const auto& val(dynamic_cast<const LongFieldValue&>(fval)); return std::make_unique<IntegerValue>(val.getAsLong(), false); } - case FloatFieldValue::classId: + case FieldValue::Type::FLOAT: { const auto& val(dynamic_cast<const FloatFieldValue&>(fval)); return std::make_unique<FloatValue>(val.getAsFloat()); } - case DoubleFieldValue::classId: + case FieldValue::Type::DOUBLE: { const auto& val(dynamic_cast<const DoubleFieldValue&>(fval)); return std::make_unique<FloatValue>(val.getAsDouble()); } - case StringFieldValue::classId: + case FieldValue::Type::STRING: { const auto& val(dynamic_cast<const StringFieldValue&>(fval)); return std::make_unique<StringValue>(val.getAsString()); } - case ReferenceFieldValue::classId: + case FieldValue::Type::REFERENCE: { const auto& val(dynamic_cast<const ReferenceFieldValue&>(fval)); if (val.hasValidDocumentId()) { @@ -317,7 +316,7 @@ IteratorHandler::getInternalValue(const FieldValue& fval) const return std::make_unique<InvalidValue>(); } } - case ArrayFieldValue::classId: + case FieldValue::Type::ARRAY: { const auto& val(dynamic_cast<const ArrayFieldValue&>(fval)); if (val.size() == 0) { @@ -328,7 +327,7 @@ IteratorHandler::getInternalValue(const FieldValue& fval) const return std::make_unique<ArrayValue>(values); } } - case StructFieldValue::classId: + case FieldValue::Type::STRUCT: { const auto& val(dynamic_cast<const StructFieldValue&>(fval)); if (val.empty()) { @@ -342,7 +341,7 @@ IteratorHandler::getInternalValue(const FieldValue& fval) const return std::make_unique<StructValue>(values); } } - case MapFieldValue::classId: + case FieldValue::Type::MAP: { const auto& val(static_cast<const MapFieldValue&>(fval)); if (val.isEmpty()) { @@ -353,6 +352,8 @@ IteratorHandler::getInternalValue(const FieldValue& fval) const return std::make_unique<ArrayValue>(values); } } + default: + break; } LOG(warning, "Tried to use unsupported datatype %s in field comparison", fval.getDataType()->toString().c_str()); diff --git a/document/src/vespa/document/update/addfieldpathupdate.cpp b/document/src/vespa/document/update/addfieldpathupdate.cpp index 227ac34d78b..cff38c246e4 100644 --- a/document/src/vespa/document/update/addfieldpathupdate.cpp +++ b/document/src/vespa/document/update/addfieldpathupdate.cpp @@ -7,6 +7,7 @@ #include <vespa/document/serialization/vespadocumentdeserializer.h> #include <vespa/vespalib/objects/nbostream.h> #include <vespa/vespalib/util/exceptions.h> +#include <vespa/vespalib/util/classname.h> #include <ostream> #include <cassert> @@ -31,7 +32,7 @@ AddFieldPathUpdate::AddFieldPathUpdate() : FieldPathUpdate(), _values() { } -AddFieldPathUpdate::~AddFieldPathUpdate() { } +AddFieldPathUpdate::~AddFieldPathUpdate() = default; FieldPathUpdate* AddFieldPathUpdate::clone() const { @@ -53,13 +54,13 @@ private: ModificationStatus AddIteratorHandler::doModify(FieldValue &fv) { - if (fv.inherits(CollectionFieldValue::classId)) { + if (fv.isCollection()) { CollectionFieldValue &cf = static_cast<CollectionFieldValue &>(fv); for (std::size_t i = 0; i < _values.size(); ++i) { cf.add(_values[i]); } } else { - vespalib::string err = make_string("Unable to add a value to a \"%s\" field value.", fv.getClass().name()); + vespalib::string err = make_string("Unable to add a value to a \"%s\" field value.", vespalib::getClassName(fv).c_str()); throw vespalib::IllegalArgumentException(err, VESPA_STRLOC); } return ModificationStatus::MODIFIED; diff --git a/document/src/vespa/document/update/addvalueupdate.cpp b/document/src/vespa/document/update/addvalueupdate.cpp index e12afd8fa63..6fda6ddc362 100644 --- a/document/src/vespa/document/update/addvalueupdate.cpp +++ b/document/src/vespa/document/update/addvalueupdate.cpp @@ -7,6 +7,7 @@ #include <vespa/document/util/serializableexceptions.h> #include <vespa/vespalib/objects/nbostream.h> #include <vespa/vespalib/util/xmlstream.h> +#include <vespa/vespalib/util/classname.h> #include <ostream> using vespalib::IllegalArgumentException; @@ -63,14 +64,14 @@ AddValueUpdate::print(std::ostream& out, bool, const std::string& indent) const bool AddValueUpdate::applyTo(FieldValue& value) const { - if (value.inherits(ArrayFieldValue::classId)) { + if (value.isA(FieldValue::Type::ARRAY)) { ArrayFieldValue& doc(static_cast<ArrayFieldValue&>(value)); doc.add(*_value); - } else if (value.inherits(WeightedSetFieldValue::classId)) { + } else if (value.isA(FieldValue::Type::WSET)) { WeightedSetFieldValue& doc(static_cast<WeightedSetFieldValue&>(value)); doc.add(*_value, _weight); } else { - std::string err = make_string("Unable to add a value to a \"%s\" field value.", value.getClass().name()); + vespalib::string err = make_string("Unable to add a value to a \"%s\" field value.", vespalib::getClassName(value).c_str()); throw IllegalStateException(err, VESPA_STRLOC); } return true; diff --git a/document/src/vespa/document/update/arithmeticvalueupdate.cpp b/document/src/vespa/document/update/arithmeticvalueupdate.cpp index b33312d8e65..7500e28ce07 100644 --- a/document/src/vespa/document/update/arithmeticvalueupdate.cpp +++ b/document/src/vespa/document/update/arithmeticvalueupdate.cpp @@ -2,9 +2,9 @@ #include "arithmeticvalueupdate.h" #include <vespa/document/base/field.h> #include <vespa/document/fieldvalue/fieldvalues.h> -#include <vespa/vespalib/objects/nbostream.h> #include <vespa/vespalib/util/exceptions.h> #include <vespa/vespalib/util/xmlstream.h> +#include <vespa/vespalib/util/classname.h> #include <ostream> using vespalib::IllegalArgumentException; @@ -44,25 +44,25 @@ ArithmeticValueUpdate::checkCompatibility(const Field& field) const bool ArithmeticValueUpdate::applyTo(FieldValue& value) const { - if (value.inherits(ByteFieldValue::classId)) { + if (value.isA(FieldValue::Type::BYTE)) { ByteFieldValue& bValue = static_cast<ByteFieldValue&>(value); bValue.setValue((int)applyTo(static_cast<int64_t>(bValue.getAsInt()))); - } else if (value.inherits(DoubleFieldValue::classId)) { + } else if (value.isA(FieldValue::Type::DOUBLE)) { DoubleFieldValue& dValue = static_cast<DoubleFieldValue&>(value); dValue.setValue(applyTo(dValue.getAsDouble())); - } else if (value.inherits(FloatFieldValue::classId)) { + } else if (value.isA(FieldValue::Type::FLOAT)) { FloatFieldValue& fValue = static_cast<FloatFieldValue&>(value); fValue.setValue((float)applyTo(fValue.getAsFloat())); - } else if (value.inherits(IntFieldValue::classId)) { + } else if (value.isA(FieldValue::Type::INT)) { IntFieldValue& iValue = static_cast<IntFieldValue&>(value); iValue.setValue((int)applyTo(static_cast<int64_t>(iValue.getAsInt()))); - } else if (value.inherits(LongFieldValue::classId)) { + } else if (value.isA(FieldValue::Type::LONG)) { LongFieldValue& lValue = static_cast<LongFieldValue&>(value); lValue.setValue(applyTo(lValue.getAsLong())); } else { - std::string err = vespalib::make_string( + vespalib::string err = vespalib::make_string( "Unable to perform an arithmetic update on a \"%s\" field " - "value.", value.getClass().name()); + "value.", vespalib::getClassName(value).c_str()); throw IllegalStateException(err, VESPA_STRLOC); } return true; diff --git a/document/src/vespa/document/update/assignfieldpathupdate.cpp b/document/src/vespa/document/update/assignfieldpathupdate.cpp index 9fa5f4fa441..6f2bbfd89c4 100644 --- a/document/src/vespa/document/update/assignfieldpathupdate.cpp +++ b/document/src/vespa/document/update/assignfieldpathupdate.cpp @@ -3,11 +3,11 @@ #include "assignfieldpathupdate.h" #include <vespa/document/fieldvalue/fieldvalues.h> #include <vespa/document/fieldvalue/iteratorhandler.h> -#include <vespa/document/select/parser.h> #include <vespa/document/select/variablemap.h> #include <vespa/document/serialization/vespadocumentdeserializer.h> #include <vespa/vespalib/objects/nbostream.h> #include <vespa/vespalib/util/exceptions.h> +#include <vespa/vespalib/util/classname.h> #include <boost/numeric/conversion/cast.hpp> #include <ostream> @@ -118,12 +118,12 @@ AssignValueIteratorHandler::doModify(FieldValue& fv) { if (!(*fv.getDataType() == *_newValue.getDataType())) { vespalib::string err = vespalib::make_string( "Trying to assign \"%s\" of type %s to an instance of type %s", - _newValue.toString().c_str(), _newValue.getClass().name(), - fv.getClass().name()); + _newValue.toString().c_str(), vespalib::getClassName(_newValue).c_str(), + vespalib::getClassName(fv).c_str()); throw vespalib::IllegalArgumentException(err, VESPA_STRLOC); } if (_removeIfZero - && _newValue.inherits(NumericFieldValueBase::classId) + && _newValue.isNumeric() && static_cast<const NumericFieldValueBase&>(_newValue).getAsLong() == 0) { return ModificationStatus::REMOVED; @@ -135,13 +135,13 @@ AssignValueIteratorHandler::doModify(FieldValue& fv) { ModificationStatus AssignExpressionIteratorHandler::doModify(FieldValue& fv) { LOG(spam, "fv = %s", fv.toString().c_str()); - if (fv.inherits(NumericFieldValueBase::classId)) { + if (fv.isNumeric()) { std::unique_ptr<select::VariableMap> varHolder = std::make_unique<select::VariableMap>(); select::VariableMap & vars = *varHolder; for (VariableMap::const_iterator i(getVariables().begin()), e(getVariables().end()); i != e; ++i) { - if (i->second.key.get() && i->second.key->inherits(NumericFieldValueBase::classId)) { + if (i->second.key.get() && i->second.key->isNumeric()) { vars[i->first] = i->second.key->getAsDouble(); } else { vars[i->first] = i->second.index; diff --git a/document/src/vespa/document/update/assignvalueupdate.cpp b/document/src/vespa/document/update/assignvalueupdate.cpp index d6eb0b501d3..0f355434f08 100644 --- a/document/src/vespa/document/update/assignvalueupdate.cpp +++ b/document/src/vespa/document/update/assignvalueupdate.cpp @@ -7,6 +7,7 @@ #include <vespa/vespalib/objects/nbostream.h> #include <vespa/vespalib/util/exceptions.h> #include <vespa/vespalib/util/xmlstream.h> +#include <vespa/vespalib/util/classname.h> #include <ostream> using vespalib::IllegalArgumentException; @@ -71,7 +72,7 @@ AssignValueUpdate::applyTo(FieldValue& value) const !value.getDataType()->isValueType(*_value))) { vespalib::string err = vespalib::make_string( "Unable to assign a \"%s\" value to a \"%s\" field value.", - _value->getClass().name(), value.getClass().name()); + vespalib::getClassName(*_value).c_str(), vespalib::getClassName(value).c_str()); throw IllegalStateException(err, VESPA_STRLOC); } if (_value) { diff --git a/document/src/vespa/document/update/documentupdate.h b/document/src/vespa/document/update/documentupdate.h index 69f22237c8f..c7ebe913d79 100644 --- a/document/src/vespa/document/update/documentupdate.h +++ b/document/src/vespa/document/update/documentupdate.h @@ -40,13 +40,14 @@ class VespaDocumentSerializer; * path updates was added, and a new serialization format was * introduced while keeping the old one. */ -class DocumentUpdate final : public Printable, public XmlSerializable +class DocumentUpdate final : public Printable, public vespalib::xml::XmlSerializable { public: - typedef std::unique_ptr<DocumentUpdate> UP; - typedef std::shared_ptr<DocumentUpdate> SP; - typedef std::vector<FieldUpdate> FieldUpdateV; - typedef std::vector<FieldPathUpdate::CP> FieldPathUpdateV; + using UP = std::unique_ptr<DocumentUpdate>; + using SP = std::shared_ptr<DocumentUpdate>; + using FieldUpdateV = std::vector<FieldUpdate>; + using FieldPathUpdateV = std::vector<FieldPathUpdate::CP>; + using XmlOutputStream = vespalib::xml::XmlOutputStream; /** * Create new style document update, possibly with field path updates. diff --git a/document/src/vespa/document/update/fieldpathupdate.h b/document/src/vespa/document/update/fieldpathupdate.h index 5283f0da455..28faad722d4 100644 --- a/document/src/vespa/document/update/fieldpathupdate.h +++ b/document/src/vespa/document/update/fieldpathupdate.h @@ -4,6 +4,7 @@ #include "updatevisitor.h" #include <vespa/document/base/fieldpath.h> #include <vespa/document/util/printable.h> +#include <vespa/document/util/identifiableid.h> namespace document { diff --git a/document/src/vespa/document/update/fieldupdate.h b/document/src/vespa/document/update/fieldupdate.h index 1e4137b9531..e364e5db5fd 100644 --- a/document/src/vespa/document/update/fieldupdate.h +++ b/document/src/vespa/document/update/fieldupdate.h @@ -23,7 +23,7 @@ class DocumentType; class FieldUpdate : public vespalib::Identifiable, public Printable, - public XmlSerializable + public vespalib::xml::XmlSerializable { Field _field; std::vector<ValueUpdate::CP> _updates; @@ -31,6 +31,7 @@ class FieldUpdate : public vespalib::Identifiable, public: typedef vespalib::CloneablePtr<FieldUpdate> CP; + using XmlOutputStream = vespalib::xml::XmlOutputStream; FieldUpdate(const Field& field); FieldUpdate(const FieldUpdate &); diff --git a/document/src/vespa/document/update/mapvalueupdate.cpp b/document/src/vespa/document/update/mapvalueupdate.cpp index 18f2c013b7f..684ff1fb6e4 100644 --- a/document/src/vespa/document/update/mapvalueupdate.cpp +++ b/document/src/vespa/document/update/mapvalueupdate.cpp @@ -44,7 +44,7 @@ MapValueUpdate::checkCompatibility(const Field& field) const { // Check compatibility of nested types. if (field.getDataType().isArray()) { - if (_key->getClass().id() != IntFieldValue::classId) { + if (_key->type() != FieldValue::Type::INT) { throw IllegalArgumentException(vespalib::make_string( "Key for field '%s' is of wrong type (expected '%s', was '%s').", field.getName().data(), DataType::INT->toString().c_str(), diff --git a/document/src/vespa/document/update/removevalueupdate.cpp b/document/src/vespa/document/update/removevalueupdate.cpp index d35d8db84a2..fda3b09163f 100644 --- a/document/src/vespa/document/update/removevalueupdate.cpp +++ b/document/src/vespa/document/update/removevalueupdate.cpp @@ -7,6 +7,7 @@ #include <vespa/vespalib/objects/nbostream.h> #include <vespa/document/util/serializableexceptions.h> #include <vespa/vespalib/util/xmlstream.h> +#include <vespa/vespalib/util/classname.h> #include <ostream> using vespalib::IllegalArgumentException; @@ -56,14 +57,14 @@ RemoveValueUpdate::checkCompatibility(const Field& field) const bool RemoveValueUpdate::applyTo(FieldValue& value) const { - if (value.inherits(ArrayFieldValue::classId)) { + if (value.isA(FieldValue::Type::ARRAY)) { ArrayFieldValue& doc(static_cast<ArrayFieldValue&>(value)); doc.remove(*_key); - } else if (value.inherits(WeightedSetFieldValue::classId)) { + } else if (value.isA(FieldValue::Type::WSET)) { WeightedSetFieldValue& doc(static_cast<WeightedSetFieldValue&>(value)); doc.remove(*_key); } else { - std::string err = vespalib::make_string("Unable to remove a value from a \"%s\" field value.", value.getClass().name()); + std::string err = vespalib::make_string("Unable to remove a value from a \"%s\" field value.", vespalib::getClassName(value).c_str()); throw IllegalStateException(err, VESPA_STRLOC); } return true; diff --git a/document/src/vespa/document/update/tensor_add_update.cpp b/document/src/vespa/document/update/tensor_add_update.cpp index 3b442b7b1d5..2474429f2a9 100644 --- a/document/src/vespa/document/update/tensor_add_update.cpp +++ b/document/src/vespa/document/update/tensor_add_update.cpp @@ -8,13 +8,12 @@ #include <vespa/document/fieldvalue/document.h> #include <vespa/document/fieldvalue/tensorfieldvalue.h> #include <vespa/document/serialization/vespadocumentdeserializer.h> -#include <vespa/document/util/serializableexceptions.h> #include <vespa/eval/eval/value.h> #include <vespa/eval/eval/fast_value.h> -#include <vespa/vespalib/objects/nbostream.h> #include <vespa/vespalib/stllike/asciistream.h> #include <vespa/vespalib/util/stringfmt.h> #include <vespa/vespalib/util/xmlstream.h> +#include <vespa/vespalib/util/classname.h> #include <ostream> using vespalib::IllegalArgumentException; @@ -99,7 +98,7 @@ TensorAddUpdate::apply_to(const Value &old_tensor, bool TensorAddUpdate::applyTo(FieldValue& value) const { - if (value.inherits(TensorFieldValue::classId)) { + if (value.isA(FieldValue::Type::TENSOR)) { TensorFieldValue &tensorFieldValue = static_cast<TensorFieldValue &>(value); tensorFieldValue.make_empty_if_not_existing(); auto oldTensor = tensorFieldValue.getAsTensorPtr(); @@ -110,7 +109,7 @@ TensorAddUpdate::applyTo(FieldValue& value) const } } else { vespalib::string err = make_string("Unable to perform a tensor add update on a '%s' field value", - value.getClass().name()); + vespalib::getClassName(value).c_str()); throw IllegalStateException(err, VESPA_STRLOC); } return true; @@ -136,11 +135,11 @@ void TensorAddUpdate::deserialize(const DocumentTypeRepo &repo, const DataType &type, nbostream & stream) { auto tensor = type.createFieldValue(); - if (tensor->inherits(TensorFieldValue::classId)) { + if (tensor->isA(FieldValue::Type::TENSOR)) { _tensor.reset(static_cast<TensorFieldValue *>(tensor.release())); } else { vespalib::string err = make_string("Expected tensor field value, got a '%s' field value", - tensor->getClass().name()); + vespalib::getClassName(*tensor).c_str()); throw IllegalStateException(err, VESPA_STRLOC); } VespaDocumentDeserializer deserializer(repo, stream, Document::getNewestSerializationVersion()); diff --git a/document/src/vespa/document/update/tensor_modify_update.cpp b/document/src/vespa/document/update/tensor_modify_update.cpp index 91ac6f4c754..9cfb38e70e2 100644 --- a/document/src/vespa/document/update/tensor_modify_update.cpp +++ b/document/src/vespa/document/update/tensor_modify_update.cpp @@ -15,6 +15,7 @@ #include <vespa/vespalib/stllike/asciistream.h> #include <vespa/vespalib/util/stringfmt.h> #include <vespa/vespalib/util/xmlstream.h> +#include <vespa/vespalib/util/classname.h> #include <ostream> using vespalib::IllegalArgumentException; @@ -94,7 +95,7 @@ TensorModifyUpdate::TensorModifyUpdate() TensorModifyUpdate::TensorModifyUpdate(const TensorModifyUpdate &rhs) : _operation(rhs._operation), _tensorType(std::make_unique<TensorDataType>(*rhs._tensorType)), - _tensor(Identifiable::cast<TensorFieldValue *>(_tensorType->createFieldValue().release())) + _tensor(static_cast<TensorFieldValue *>(_tensorType->createFieldValue().release())) { *_tensor = *rhs._tensor; } @@ -102,7 +103,7 @@ TensorModifyUpdate::TensorModifyUpdate(const TensorModifyUpdate &rhs) TensorModifyUpdate::TensorModifyUpdate(Operation operation, std::unique_ptr<TensorFieldValue> tensor) : _operation(operation), _tensorType(std::make_unique<TensorDataType>(dynamic_cast<const TensorDataType &>(*tensor->getDataType()))), - _tensor(Identifiable::cast<TensorFieldValue *>(_tensorType->createFieldValue().release())) + _tensor(static_cast<TensorFieldValue *>(_tensorType->createFieldValue().release())) { *_tensor = *tensor; } @@ -116,7 +117,7 @@ TensorModifyUpdate::operator=(const TensorModifyUpdate &rhs) _operation = rhs._operation; _tensor.reset(); _tensorType = std::make_unique<TensorDataType>(*rhs._tensorType); - _tensor.reset(Identifiable::cast<TensorFieldValue *>(_tensorType->createFieldValue().release())); + _tensor.reset(dynamic_cast<TensorFieldValue *>(_tensorType->createFieldValue().release())); *_tensor = *rhs._tensor; } return *this; @@ -177,7 +178,7 @@ TensorModifyUpdate::apply_to(const Value &old_tensor, bool TensorModifyUpdate::applyTo(FieldValue& value) const { - if (value.inherits(TensorFieldValue::classId)) { + if (value.isA(FieldValue::Type::TENSOR)) { TensorFieldValue &tensorFieldValue = static_cast<TensorFieldValue &>(value); auto oldTensor = tensorFieldValue.getAsTensorPtr(); if (oldTensor) { @@ -188,7 +189,7 @@ TensorModifyUpdate::applyTo(FieldValue& value) const } } else { vespalib::string err = make_string("Unable to perform a tensor modify update on a '%s' field value", - value.getClass().name()); + vespalib::getClassName(value).c_str()); throw IllegalStateException(err, VESPA_STRLOC); } return true; @@ -241,11 +242,11 @@ TensorModifyUpdate::deserialize(const DocumentTypeRepo &repo, const DataType &ty _operation = static_cast<Operation>(op); _tensorType = convertToCompatibleType(dynamic_cast<const TensorDataType &>(type)); auto tensor = _tensorType->createFieldValue(); - if (tensor->inherits(TensorFieldValue::classId)) { + if (tensor->isA(FieldValue::Type::TENSOR)) { _tensor.reset(static_cast<TensorFieldValue *>(tensor.release())); } else { vespalib::string err = make_string("Expected tensor field value, got a '%s' field value", - tensor->getClass().name()); + vespalib::getClassName(*tensor).c_str()); throw IllegalStateException(err, VESPA_STRLOC); } VespaDocumentDeserializer deserializer(repo, stream, Document::getNewestSerializationVersion()); diff --git a/document/src/vespa/document/update/tensor_remove_update.cpp b/document/src/vespa/document/update/tensor_remove_update.cpp index f4dc9490b62..f1f4becb285 100644 --- a/document/src/vespa/document/update/tensor_remove_update.cpp +++ b/document/src/vespa/document/update/tensor_remove_update.cpp @@ -10,6 +10,7 @@ #include <vespa/eval/eval/fast_value.h> #include <vespa/eval/eval/value.h> #include <vespa/vespalib/util/xmlstream.h> +#include <vespa/vespalib/util/classname.h> #include <ostream> using vespalib::IllegalArgumentException; @@ -54,7 +55,7 @@ TensorRemoveUpdate::TensorRemoveUpdate(const TensorRemoveUpdate &rhs) TensorRemoveUpdate::TensorRemoveUpdate(std::unique_ptr<TensorFieldValue> tensor) : _tensorType(std::make_unique<TensorDataType>(dynamic_cast<const TensorDataType &>(*tensor->getDataType()))), - _tensor(Identifiable::cast<TensorFieldValue *>(_tensorType->createFieldValue().release())) + _tensor(static_cast<TensorFieldValue *>(_tensorType->createFieldValue().release())) { *_tensor = *tensor; } @@ -67,7 +68,7 @@ TensorRemoveUpdate::operator=(const TensorRemoveUpdate &rhs) if (&rhs != this) { _tensor.reset(); _tensorType = std::make_unique<TensorDataType>(*rhs._tensorType); - _tensor.reset(Identifiable::cast<TensorFieldValue *>(_tensorType->createFieldValue().release())); + _tensor.reset(static_cast<TensorFieldValue *>(_tensorType->createFieldValue().release())); *_tensor = *rhs._tensor; } return *this; @@ -122,7 +123,7 @@ TensorRemoveUpdate::apply_to(const Value &old_tensor, bool TensorRemoveUpdate::applyTo(FieldValue &value) const { - if (value.inherits(TensorFieldValue::classId)) { + if (value.isA(FieldValue::Type::TENSOR)) { TensorFieldValue &tensorFieldValue = static_cast<TensorFieldValue &>(value); auto oldTensor = tensorFieldValue.getAsTensorPtr(); if (oldTensor) { @@ -133,7 +134,7 @@ TensorRemoveUpdate::applyTo(FieldValue &value) const } } else { vespalib::string err = make_string("Unable to perform a tensor remove update on a '%s' field value", - value.getClass().name()); + vespalib::getClassName(value).c_str()); throw IllegalStateException(err, VESPA_STRLOC); } return true; diff --git a/document/src/vespa/document/update/valueupdate.h b/document/src/vespa/document/update/valueupdate.h index 9a8ed4e9537..8564e81f777 100644 --- a/document/src/vespa/document/update/valueupdate.h +++ b/document/src/vespa/document/update/valueupdate.h @@ -20,9 +20,9 @@ #include "updatevisitor.h" #include <vespa/document/util/printable.h> -#include <vespa/document/util/xmlserializable.h> #include <vespa/document/util/identifiableid.h> #include <vespa/vespalib/objects/nbostream.h> +#include <vespa/vespalib/util/xmlserializable.h> namespace document { @@ -33,12 +33,13 @@ class DataType; class ValueUpdate : public vespalib::Identifiable, public Printable, - public XmlSerializable +public vespalib::xml::XmlSerializable { protected: using nbostream = vespalib::nbostream; public: using CP = vespalib::CloneablePtr<ValueUpdate>; + using XmlOutputStream = vespalib::xml::XmlOutputStream; /** * Create a value update object from the given stream. diff --git a/document/src/vespa/document/util/feed_reject_helper.cpp b/document/src/vespa/document/util/feed_reject_helper.cpp index f23524eddfb..a6829ec0c60 100644 --- a/document/src/vespa/document/util/feed_reject_helper.cpp +++ b/document/src/vespa/document/util/feed_reject_helper.cpp @@ -4,14 +4,12 @@ #include <vespa/document/update/documentupdate.h> #include <vespa/document/update/assignvalueupdate.h> #include <vespa/document/fieldvalue/boolfieldvalue.h> -#include <vespa/document/fieldvalue/numericfieldvalue.h> - namespace document { bool FeedRejectHelper::isFixedSizeSingleValue(const document::FieldValue & fv) { - return fv.inherits(BoolFieldValue::classId) || fv.inherits(NumericFieldValueBase::classId); + return fv.isFixedSizeSingleValue(); } bool diff --git a/document/src/vespa/document/util/xmlserializable.h b/document/src/vespa/document/util/xmlserializable.h deleted file mode 100644 index f4a5db0de58..00000000000 --- a/document/src/vespa/document/util/xmlserializable.h +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -#pragma once - -#include <vespa/vespalib/util/xmlserializable.h> - -namespace document { - using XmlSerializable = vespalib::xml::XmlSerializable; - using XmlOutputStream = vespalib::xml::XmlOutputStream; -} |