diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2022-03-28 09:57:50 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2022-03-28 14:49:19 +0000 |
commit | 8976efd142145482d61d83755db2fab0a8b626a6 (patch) | |
tree | 928f5320c8a9ad5298c2e016ee924936af1ff6c8 | |
parent | 0ad0999caf32c04110390fef838b01d14474cd3c (diff) |
Avoid Identifiable for ValueUpdate. It complicates without bringing much useful.
25 files changed, 165 insertions, 122 deletions
diff --git a/document/src/tests/documentupdatetestcase.cpp b/document/src/tests/documentupdatetestcase.cpp index beb94959e73..93ab1c370c5 100644 --- a/document/src/tests/documentupdatetestcase.cpp +++ b/document/src/tests/documentupdatetestcase.cpp @@ -498,7 +498,7 @@ TEST(DocumentUpdateTest, testReadSerializedFile) serValue = &serField2[0]; EXPECT_EQ(serValue->getType(), ValueUpdate::Clear); - EXPECT_TRUE(serValue->inherits(ClearValueUpdate::classId)); + EXPECT_EQ(ValueUpdate::Clear, serValue->getType()); // Verify add value update. const FieldUpdate & serField3 = upd.getUpdates()[0]; diff --git a/document/src/vespa/document/serialization/vespadocumentserializer.cpp b/document/src/vespa/document/serialization/vespadocumentserializer.cpp index b6a7dabd87d..c156594f1f0 100644 --- a/document/src/vespa/document/serialization/vespadocumentserializer.cpp +++ b/document/src/vespa/document/serialization/vespadocumentserializer.cpp @@ -377,7 +377,7 @@ VespaDocumentSerializer::write(const FieldUpdate &value) void VespaDocumentSerializer::write(const RemoveValueUpdate &value) { - _stream << RemoveValueUpdate::classId; + _stream << ValueUpdate::Remove; write(value.getKey()); } @@ -385,7 +385,7 @@ VespaDocumentSerializer::write(const RemoveValueUpdate &value) void VespaDocumentSerializer::write(const AddValueUpdate &value) { - _stream << AddValueUpdate::classId; + _stream << ValueUpdate::Add; write(value.getValue()); _stream << static_cast<int32_t>(value.getWeight()); } @@ -393,7 +393,7 @@ VespaDocumentSerializer::write(const AddValueUpdate &value) void VespaDocumentSerializer::write(const ArithmeticValueUpdate &value) { - _stream << ArithmeticValueUpdate::classId; + _stream << ValueUpdate::Arithmetic; _stream << static_cast<uint32_t>(value.getOperator()); _stream << static_cast<double>(value.getOperand()); } @@ -401,7 +401,7 @@ VespaDocumentSerializer::write(const ArithmeticValueUpdate &value) void VespaDocumentSerializer::write(const AssignValueUpdate &value) { - _stream << AssignValueUpdate::classId; + _stream << ValueUpdate::Assign; if (value.hasValue()) { _stream << static_cast<uint8_t>(CONTENT_HASVALUE); write(value.getValue()); @@ -414,12 +414,12 @@ void VespaDocumentSerializer::write(const ClearValueUpdate &value) { (void) value; - _stream << ClearValueUpdate::classId; + _stream << ValueUpdate::Clear; } void VespaDocumentSerializer::write(const MapValueUpdate &value) { - _stream << MapValueUpdate::classId; + _stream << ValueUpdate::Map; write(value.getKey()); write(value.getUpdate()); } @@ -479,7 +479,7 @@ VespaDocumentSerializer::write(const RemoveFieldPathUpdate &value) void VespaDocumentSerializer::write(const TensorModifyUpdate &value) { - _stream << TensorModifyUpdate::classId; + _stream << ValueUpdate::TensorModify; _stream << static_cast<uint8_t>(value.getOperation()); write(value.getTensor()); } @@ -493,7 +493,7 @@ VespaDocumentSerializer::visit(const TensorModifyUpdate &value) void VespaDocumentSerializer::write(const TensorAddUpdate &value) { - _stream << TensorAddUpdate::classId; + _stream << ValueUpdate::TensorAdd; write(value.getTensor()); } @@ -506,7 +506,7 @@ VespaDocumentSerializer::visit(const TensorAddUpdate &value) void VespaDocumentSerializer::write(const TensorRemoveUpdate &value) { - _stream << TensorRemoveUpdate::classId; + _stream << ValueUpdate::TensorRemove; write(value.getTensor()); } diff --git a/document/src/vespa/document/update/addvalueupdate.cpp b/document/src/vespa/document/update/addvalueupdate.cpp index 6f6c9a93738..3b593d3e9b2 100644 --- a/document/src/vespa/document/update/addvalueupdate.cpp +++ b/document/src/vespa/document/update/addvalueupdate.cpp @@ -17,19 +17,19 @@ using namespace vespalib::xml; namespace document { -IMPLEMENT_IDENTIFIABLE(AddValueUpdate, ValueUpdate); AddValueUpdate:: AddValueUpdate(const FieldValue& value, int weight) - : ValueUpdate(), + : ValueUpdate(Add), _value(value.clone()), _weight(weight) {} AddValueUpdate::~AddValueUpdate() = default; + bool AddValueUpdate::operator==(const ValueUpdate& other) const { - if (other.getClass().id() != AddValueUpdate::classId) return false; + if (other.getType() != Add) return false; const AddValueUpdate& o(static_cast<const AddValueUpdate&>(other)); if (*_value != *o._value) return false; if (_weight != o._weight) return false; diff --git a/document/src/vespa/document/update/addvalueupdate.h b/document/src/vespa/document/update/addvalueupdate.h index ee7f6fbcdf2..2ab7a98e842 100644 --- a/document/src/vespa/document/update/addvalueupdate.h +++ b/document/src/vespa/document/update/addvalueupdate.h @@ -12,14 +12,14 @@ namespace document { -class AddValueUpdate : public ValueUpdate { +class AddValueUpdate final : public ValueUpdate { FieldValue::CP _value; // The field value to add by this update. int _weight; // The weight to assign to the contained value. // Used by ValueUpdate's static factory function // Private because it generates an invalid object. friend class ValueUpdate; - AddValueUpdate() : ValueUpdate(), _value(0), _weight(1) {} + AddValueUpdate() : ValueUpdate(Add), _value(0), _weight(1) {} ACCEPT_UPDATE_VISITOR; public: typedef std::unique_ptr<AddValueUpdate> UP; @@ -67,8 +67,6 @@ public: void printXml(XmlOutputStream& xos) const override; void print(std::ostream& out, bool verbose, const std::string& indent) const override; void deserialize(const DocumentTypeRepo& repo, const DataType& type, nbostream & buffer) override; - - DECLARE_IDENTIFIABLE(AddValueUpdate); }; } // document diff --git a/document/src/vespa/document/update/arithmeticvalueupdate.cpp b/document/src/vespa/document/update/arithmeticvalueupdate.cpp index e5fb5aee8af..06f90d59d85 100644 --- a/document/src/vespa/document/update/arithmeticvalueupdate.cpp +++ b/document/src/vespa/document/update/arithmeticvalueupdate.cpp @@ -12,8 +12,6 @@ using namespace vespalib::xml; namespace document { -IMPLEMENT_IDENTIFIABLE(ArithmeticValueUpdate, ValueUpdate); - // Declare string representations for operator names. static const char * operatorName[] = { "add", "div", "mul", "sub" }; static const char * operatorNameC[] = { "Add", "Div", "Mul", "Sub" }; @@ -21,7 +19,7 @@ static const char * operatorNameC[] = { "Add", "Div", "Mul", "Sub" }; bool ArithmeticValueUpdate::operator==(const ValueUpdate& other) const { - if (other.getClass().id() != ArithmeticValueUpdate::classId) return false; + if (other.getType() != Arithmetic) return false; const ArithmeticValueUpdate& o(static_cast<const ArithmeticValueUpdate&>(other)); if (_operator != o._operator) return false; if (_operand != o._operand) return false; diff --git a/document/src/vespa/document/update/arithmeticvalueupdate.h b/document/src/vespa/document/update/arithmeticvalueupdate.h index cb86528fce5..c82a5b4c338 100644 --- a/document/src/vespa/document/update/arithmeticvalueupdate.h +++ b/document/src/vespa/document/update/arithmeticvalueupdate.h @@ -12,7 +12,7 @@ namespace document { -class ArithmeticValueUpdate : public ValueUpdate { +class ArithmeticValueUpdate final : public ValueUpdate { public: /** Declare all types of arithmetic value updates. */ enum Operator { @@ -31,7 +31,7 @@ private: // Private because it generates an invalid object. friend class ValueUpdate; ArithmeticValueUpdate() - : ValueUpdate(), + : ValueUpdate(Arithmetic), _operator(MAX_NUM_OPERATORS), _operand(0.0) {} @@ -46,7 +46,7 @@ public: * @param opn The operand for the operation. */ ArithmeticValueUpdate(Operator opt, double opn) - : ValueUpdate(), + : ValueUpdate(Arithmetic), _operator(opt), _operand(opn) {} @@ -91,8 +91,6 @@ public: void printXml(XmlOutputStream& xos) const override; void print(std::ostream& out, bool verbose, const std::string& indent) const override; void deserialize(const DocumentTypeRepo& repo, const DataType& type, nbostream & buffer) override; - - DECLARE_IDENTIFIABLE(ArithmeticValueUpdate); }; } // document diff --git a/document/src/vespa/document/update/assignvalueupdate.cpp b/document/src/vespa/document/update/assignvalueupdate.cpp index cf2321dbf56..363eff92bf0 100644 --- a/document/src/vespa/document/update/assignvalueupdate.cpp +++ b/document/src/vespa/document/update/assignvalueupdate.cpp @@ -16,12 +16,13 @@ using namespace vespalib::xml; namespace document { -IMPLEMENT_IDENTIFIABLE(AssignValueUpdate, ValueUpdate); - -AssignValueUpdate::AssignValueUpdate() = default; +AssignValueUpdate::AssignValueUpdate() + : ValueUpdate(Assign), + _value() +{} AssignValueUpdate::AssignValueUpdate(const FieldValue& value) - : ValueUpdate(), + : ValueUpdate(Assign), _value(value.clone()) { } @@ -33,7 +34,7 @@ static const unsigned char CONTENT_HASVALUE = 0x01; bool AssignValueUpdate::operator==(const ValueUpdate& other) const { - if (other.getClass().id() != AssignValueUpdate::classId) return false; + if (other.getType() != Assign) return false; const AssignValueUpdate& o(static_cast<const AssignValueUpdate&>(other)); return _value == o._value; } diff --git a/document/src/vespa/document/update/assignvalueupdate.h b/document/src/vespa/document/update/assignvalueupdate.h index e829e80da45..9df2084ef97 100644 --- a/document/src/vespa/document/update/assignvalueupdate.h +++ b/document/src/vespa/document/update/assignvalueupdate.h @@ -16,15 +16,13 @@ namespace document { -class AssignValueUpdate : public ValueUpdate { +class AssignValueUpdate final : public ValueUpdate { FieldValue::CP _value; ACCEPT_UPDATE_VISITOR; public: typedef std::unique_ptr<AssignValueUpdate> UP; - AssignValueUpdate(); - AssignValueUpdate(const FieldValue& value); ~AssignValueUpdate() override; @@ -43,8 +41,6 @@ public: void printXml(XmlOutputStream& xos) const override; void print(std::ostream& out, bool verbose, const std::string& indent) const override; void deserialize(const DocumentTypeRepo& repo, const DataType& type, nbostream & buffer) override; - - DECLARE_IDENTIFIABLE(AssignValueUpdate); }; } diff --git a/document/src/vespa/document/update/clearvalueupdate.cpp b/document/src/vespa/document/update/clearvalueupdate.cpp index 17d7660219b..357ca8162c6 100644 --- a/document/src/vespa/document/update/clearvalueupdate.cpp +++ b/document/src/vespa/document/update/clearvalueupdate.cpp @@ -8,12 +8,10 @@ using namespace vespalib::xml; namespace document { -IMPLEMENT_IDENTIFIABLE(ClearValueUpdate, ValueUpdate); - bool ClearValueUpdate::operator==(const ValueUpdate& other) const { - return (other.getClass().id() == ClearValueUpdate::classId); + return (other.getType() == Clear); } // Ensure that this update is compatible with given field. diff --git a/document/src/vespa/document/update/clearvalueupdate.h b/document/src/vespa/document/update/clearvalueupdate.h index 6e0d800dd73..2a68814f8b0 100644 --- a/document/src/vespa/document/update/clearvalueupdate.h +++ b/document/src/vespa/document/update/clearvalueupdate.h @@ -11,12 +11,12 @@ namespace document { -class ClearValueUpdate : public ValueUpdate { +class ClearValueUpdate final : public ValueUpdate { ACCEPT_UPDATE_VISITOR; public: typedef std::unique_ptr<ClearValueUpdate> UP; - ClearValueUpdate() : ValueUpdate() {} - ClearValueUpdate(const ClearValueUpdate& update) : ValueUpdate(update) {} + ClearValueUpdate(const ClearValueUpdate& update) = default; + ClearValueUpdate() : ValueUpdate(Clear) {} ClearValueUpdate &operator=(const ClearValueUpdate &rhs) = default; bool operator==(const ValueUpdate& other) const override; @@ -25,8 +25,6 @@ public: void printXml(XmlOutputStream& xos) const override; void print(std::ostream& out, bool verbose, const std::string& indent) const override; void deserialize(const DocumentTypeRepo& repo, const DataType& type, nbostream& buffer) override; - - DECLARE_IDENTIFIABLE(ClearValueUpdate); }; } diff --git a/document/src/vespa/document/update/mapvalueupdate.cpp b/document/src/vespa/document/update/mapvalueupdate.cpp index c3d9cff571b..93f2029b92f 100644 --- a/document/src/vespa/document/update/mapvalueupdate.cpp +++ b/document/src/vespa/document/update/mapvalueupdate.cpp @@ -16,16 +16,14 @@ using namespace vespalib::xml; namespace document { -IMPLEMENT_IDENTIFIABLE(MapValueUpdate, ValueUpdate); - MapValueUpdate::MapValueUpdate(const FieldValue& key, std::unique_ptr<ValueUpdate> update) - : ValueUpdate(), + : ValueUpdate(Map), _key(key.clone()), _update(std::move(update)) {} MapValueUpdate::MapValueUpdate(const MapValueUpdate &) - : ValueUpdate(), + : ValueUpdate(Map), _key(), _update() { @@ -41,7 +39,7 @@ MapValueUpdate::~MapValueUpdate() = default; bool MapValueUpdate::operator==(const ValueUpdate& other) const { - if (other.getClass().id() != MapValueUpdate::classId) return false; + if (other.getType() != Map) return false; const MapValueUpdate& o(static_cast<const MapValueUpdate&>(other)); if (*_key != *o._key) return false; if (*_update != *o._update) return false; diff --git a/document/src/vespa/document/update/mapvalueupdate.h b/document/src/vespa/document/update/mapvalueupdate.h index 722255dd8d6..93d6c844899 100644 --- a/document/src/vespa/document/update/mapvalueupdate.h +++ b/document/src/vespa/document/update/mapvalueupdate.h @@ -16,7 +16,7 @@ namespace document { -class MapValueUpdate : public ValueUpdate { +class MapValueUpdate final : public ValueUpdate { public: /** @@ -59,7 +59,6 @@ public: void print(std::ostream& out, bool verbose, const std::string& indent) const override; void deserialize(const DocumentTypeRepo& repo, const DataType& type, nbostream& buffer) override; - DECLARE_IDENTIFIABLE(MapValueUpdate); private: std::unique_ptr<FieldValue> _key; // The field value this update is mapping to. std::unique_ptr<ValueUpdate> _update; //The update to apply to the value member of this. @@ -67,7 +66,7 @@ private: // Used by ValueUpdate's static factory function // Private because it generates an invalid object. friend class ValueUpdate; - MapValueUpdate() : ValueUpdate(), _key(), _update() {} + MapValueUpdate() : ValueUpdate(Map), _key(), _update() {} ACCEPT_UPDATE_VISITOR; }; diff --git a/document/src/vespa/document/update/removevalueupdate.cpp b/document/src/vespa/document/update/removevalueupdate.cpp index a61553da4d1..4789df8d7ab 100644 --- a/document/src/vespa/document/update/removevalueupdate.cpp +++ b/document/src/vespa/document/update/removevalueupdate.cpp @@ -16,10 +16,8 @@ using namespace vespalib::xml; namespace document { -IMPLEMENT_IDENTIFIABLE(RemoveValueUpdate, ValueUpdate); - RemoveValueUpdate::RemoveValueUpdate(const FieldValue& key) - : ValueUpdate(), + : ValueUpdate(Remove), _key(key.clone()) {} @@ -28,7 +26,7 @@ RemoveValueUpdate::~RemoveValueUpdate() = default; bool RemoveValueUpdate::operator==(const ValueUpdate& other) const { - if (other.getClass().id() != RemoveValueUpdate::classId) return false; + if (other.getType() != Remove) return false; const RemoveValueUpdate& o(static_cast<const RemoveValueUpdate&>(other)); if (*_key != *o._key) return false; return true; diff --git a/document/src/vespa/document/update/removevalueupdate.h b/document/src/vespa/document/update/removevalueupdate.h index 0eea8f69da7..0c57817ce33 100644 --- a/document/src/vespa/document/update/removevalueupdate.h +++ b/document/src/vespa/document/update/removevalueupdate.h @@ -10,12 +10,12 @@ namespace document { -class RemoveValueUpdate : public ValueUpdate { +class RemoveValueUpdate final : public ValueUpdate { FieldValue::CP _key; // The field value to remove by this update. - RemoveValueUpdate() : ValueUpdate(), _key() {} ACCEPT_UPDATE_VISITOR; - + friend ValueUpdate; + RemoveValueUpdate() : ValueUpdate(Remove), _key() {} public: typedef std::unique_ptr<RemoveValueUpdate> UP; @@ -40,9 +40,6 @@ public: void printXml(XmlOutputStream& xos) const override; void print(std::ostream& out, bool verbose, const std::string& indent) const override; void deserialize(const DocumentTypeRepo& repo, const DataType& type, nbostream& buffer) override; - - DECLARE_IDENTIFIABLE(RemoveValueUpdate); - }; } diff --git a/document/src/vespa/document/update/tensor_add_update.cpp b/document/src/vespa/document/update/tensor_add_update.cpp index 2d6b6e1d658..49c73722147 100644 --- a/document/src/vespa/document/update/tensor_add_update.cpp +++ b/document/src/vespa/document/update/tensor_add_update.cpp @@ -22,20 +22,24 @@ using vespalib::eval::FastValueBuilderFactory; namespace document { -IMPLEMENT_IDENTIFIABLE(TensorAddUpdate, ValueUpdate); - TensorAddUpdate::TensorAddUpdate() - : _tensor() + : ValueUpdate(TensorAdd), + TensorUpdate(), + _tensor() { } TensorAddUpdate::TensorAddUpdate(const TensorAddUpdate &rhs) - : _tensor(rhs._tensor->clone()) + : ValueUpdate(rhs), + TensorUpdate(rhs), + _tensor(rhs._tensor->clone()) { } TensorAddUpdate::TensorAddUpdate(std::unique_ptr<TensorFieldValue> &&tensor) - : _tensor(std::move(tensor)) + : ValueUpdate(TensorAdd), + TensorUpdate(), + _tensor(std::move(tensor)) { } @@ -58,7 +62,7 @@ TensorAddUpdate::operator=(TensorAddUpdate &&rhs) bool TensorAddUpdate::operator==(const ValueUpdate &other) const { - if (other.getClass().id() != TensorAddUpdate::classId) { + if (other.getType() != TensorAdd) { return false; } const TensorAddUpdate& o(static_cast<const TensorAddUpdate&>(other)); diff --git a/document/src/vespa/document/update/tensor_add_update.h b/document/src/vespa/document/update/tensor_add_update.h index 7f2228bff41..7e62f2db71a 100644 --- a/document/src/vespa/document/update/tensor_add_update.h +++ b/document/src/vespa/document/update/tensor_add_update.h @@ -14,9 +14,10 @@ class TensorFieldValue; * * The cells to add are contained in a tensor of the same type. */ -class TensorAddUpdate : public ValueUpdate, public TensorUpdate { +class TensorAddUpdate final : public ValueUpdate, public TensorUpdate { std::unique_ptr<TensorFieldValue> _tensor; + friend ValueUpdate; TensorAddUpdate(); TensorAddUpdate(const TensorAddUpdate &rhs); ACCEPT_UPDATE_VISITOR; @@ -35,8 +36,6 @@ public: void printXml(XmlOutputStream &xos) const override; void print(std::ostream &out, bool verbose, const std::string &indent) const override; void deserialize(const DocumentTypeRepo &repo, const DataType &type, nbostream &stream) override; - - DECLARE_IDENTIFIABLE(TensorAddUpdate); }; } diff --git a/document/src/vespa/document/update/tensor_modify_update.cpp b/document/src/vespa/document/update/tensor_modify_update.cpp index 77fd5059b0c..6abed60af17 100644 --- a/document/src/vespa/document/update/tensor_modify_update.cpp +++ b/document/src/vespa/document/update/tensor_modify_update.cpp @@ -82,17 +82,19 @@ convertToCompatibleType(const TensorDataType &tensorType) } -IMPLEMENT_IDENTIFIABLE(TensorModifyUpdate, ValueUpdate); - TensorModifyUpdate::TensorModifyUpdate() - : _operation(Operation::MAX_NUM_OPERATIONS), + : ValueUpdate(TensorModify), + TensorUpdate(), + _operation(Operation::MAX_NUM_OPERATIONS), _tensorType(), _tensor() { } TensorModifyUpdate::TensorModifyUpdate(const TensorModifyUpdate &rhs) - : _operation(rhs._operation), + : ValueUpdate(rhs), + TensorUpdate(), + _operation(rhs._operation), _tensorType(std::make_unique<TensorDataType>(*rhs._tensorType)), _tensor(static_cast<TensorFieldValue *>(_tensorType->createFieldValue().release())) { @@ -100,7 +102,9 @@ TensorModifyUpdate::TensorModifyUpdate(const TensorModifyUpdate &rhs) } TensorModifyUpdate::TensorModifyUpdate(Operation operation, std::unique_ptr<TensorFieldValue> tensor) - : _operation(operation), + : ValueUpdate(TensorModify), + TensorUpdate(), + _operation(operation), _tensorType(std::make_unique<TensorDataType>(dynamic_cast<const TensorDataType &>(*tensor->getDataType()))), _tensor(static_cast<TensorFieldValue *>(_tensorType->createFieldValue().release())) { @@ -134,7 +138,7 @@ TensorModifyUpdate::operator=(TensorModifyUpdate &&rhs) bool TensorModifyUpdate::operator==(const ValueUpdate &other) const { - if (other.getClass().id() != TensorModifyUpdate::classId) { + if (other.getType() != TensorModify) { return false; } const TensorModifyUpdate& o(static_cast<const TensorModifyUpdate&>(other)); diff --git a/document/src/vespa/document/update/tensor_modify_update.h b/document/src/vespa/document/update/tensor_modify_update.h index b6d339a36cf..9fb69ec5a13 100644 --- a/document/src/vespa/document/update/tensor_modify_update.h +++ b/document/src/vespa/document/update/tensor_modify_update.h @@ -16,7 +16,7 @@ class TensorFieldValue; * The operand is represented as a tensor field value containing a * mapped (aka sparse) tensor. */ -class TensorModifyUpdate : public ValueUpdate, public TensorUpdate { +class TensorModifyUpdate final : public ValueUpdate, public TensorUpdate { public: /** Declare all types of tensor modify updates. */ enum class Operation { // Operation to be applied to matching tensor cells @@ -30,6 +30,7 @@ private: std::unique_ptr<const TensorDataType> _tensorType; std::unique_ptr<TensorFieldValue> _tensor; + friend ValueUpdate; TensorModifyUpdate(); TensorModifyUpdate(const TensorModifyUpdate &rhs); ACCEPT_UPDATE_VISITOR; @@ -49,8 +50,6 @@ public: void printXml(XmlOutputStream &xos) const override; void print(std::ostream &out, bool verbose, const std::string &indent) const override; void deserialize(const DocumentTypeRepo &repo, const DataType &type, nbostream &stream) override; - - DECLARE_IDENTIFIABLE(TensorModifyUpdate); }; } diff --git a/document/src/vespa/document/update/tensor_remove_update.cpp b/document/src/vespa/document/update/tensor_remove_update.cpp index 69b8b898ec5..4bfb6bc6b18 100644 --- a/document/src/vespa/document/update/tensor_remove_update.cpp +++ b/document/src/vespa/document/update/tensor_remove_update.cpp @@ -38,22 +38,26 @@ convertToCompatibleType(const TensorDataType &tensorType) } -IMPLEMENT_IDENTIFIABLE(TensorRemoveUpdate, ValueUpdate); - TensorRemoveUpdate::TensorRemoveUpdate() - : _tensorType(), + : ValueUpdate(TensorRemove), + TensorUpdate(), + _tensorType(), _tensor() { } TensorRemoveUpdate::TensorRemoveUpdate(const TensorRemoveUpdate &rhs) - : _tensorType(std::make_unique<TensorDataType>(*rhs._tensorType)), + : ValueUpdate(rhs), + TensorUpdate(rhs), + _tensorType(std::make_unique<TensorDataType>(*rhs._tensorType)), _tensor(rhs._tensor->clone()) { } TensorRemoveUpdate::TensorRemoveUpdate(std::unique_ptr<TensorFieldValue> tensor) - : _tensorType(std::make_unique<TensorDataType>(dynamic_cast<const TensorDataType &>(*tensor->getDataType()))), + : ValueUpdate(TensorRemove), + TensorUpdate(), + _tensorType(std::make_unique<TensorDataType>(dynamic_cast<const TensorDataType &>(*tensor->getDataType()))), _tensor(static_cast<TensorFieldValue *>(_tensorType->createFieldValue().release())) { *_tensor = *tensor; @@ -84,7 +88,7 @@ TensorRemoveUpdate::operator=(TensorRemoveUpdate &&rhs) bool TensorRemoveUpdate::operator==(const ValueUpdate &other) const { - if (other.getClass().id() != TensorRemoveUpdate::classId) { + if (other.getType() != TensorRemove) { return false; } const TensorRemoveUpdate& o(static_cast<const TensorRemoveUpdate&>(other)); diff --git a/document/src/vespa/document/update/tensor_remove_update.h b/document/src/vespa/document/update/tensor_remove_update.h index 9b4ea17c4d9..00c886fa41f 100644 --- a/document/src/vespa/document/update/tensor_remove_update.h +++ b/document/src/vespa/document/update/tensor_remove_update.h @@ -16,11 +16,12 @@ class TensorFieldValue; * The cells to remove are contained in a sparse tensor (with all mapped dimensions) where cell values are set to 1.0. * When used on a mixed tensor the entire dense sub-space (pointed to by a cell in the sparse tensor) is removed. */ -class TensorRemoveUpdate : public ValueUpdate, public TensorUpdate { +class TensorRemoveUpdate final : public ValueUpdate, public TensorUpdate { private: std::unique_ptr<const TensorDataType> _tensorType; std::unique_ptr<TensorFieldValue> _tensor; + friend ValueUpdate; TensorRemoveUpdate(); TensorRemoveUpdate(const TensorRemoveUpdate &rhs); ACCEPT_UPDATE_VISITOR; @@ -40,8 +41,6 @@ public: void printXml(XmlOutputStream &xos) const override; void print(std::ostream &out, bool verbose, const std::string &indent) const override; void deserialize(const DocumentTypeRepo &repo, const DataType &type, nbostream &stream) override; - - DECLARE_IDENTIFIABLE(TensorRemoveUpdate); }; } diff --git a/document/src/vespa/document/update/valueupdate.cpp b/document/src/vespa/document/update/valueupdate.cpp index 8fc85e8858a..4af61178a79 100644 --- a/document/src/vespa/document/update/valueupdate.cpp +++ b/document/src/vespa/document/update/valueupdate.cpp @@ -1,12 +1,69 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "valueupdate.h" +#include "addvalueupdate.h" +#include "assignvalueupdate.h" +#include "arithmeticvalueupdate.h" +#include "clearvalueupdate.h" +#include "removevalueupdate.h" +#include "mapvalueupdate.h" +#include "tensor_add_update.h" +#include "tensor_modify_update.h" +#include "tensor_remove_update.h" #include <vespa/vespalib/util/stringfmt.h> #include <stdexcept> namespace document { -IMPLEMENT_IDENTIFIABLE_ABSTRACT(ValueUpdate, Identifiable); +const char * +ValueUpdate::className() const noexcept { + switch (getType()) { + case Add: + return "AddValueUpdate"; + case Assign: + return "AssignValueUpdate"; + case Arithmetic: + return "ArithmeticValueUpdate"; + case Clear: + return "ClearValueUpdate"; + case Remove: + return "RemoveValueUpdate"; + case Map: + return "MapValueUpdate"; + case TensorAdd: + return "TensorAddUpdate"; + case TensorModify: + return "TensorModifyUpdate"; + case TensorRemove: + return "TensorRemoveUpdate"; + } + abort(); +} + +std::unique_ptr<ValueUpdate> +ValueUpdate::create(ValueUpdateType type) { + switch (type) { + case Add: + return std::unique_ptr<AddValueUpdate>(new AddValueUpdate()); + case Assign: + return std::make_unique<AssignValueUpdate>(); + case Arithmetic: + return std::unique_ptr<ArithmeticValueUpdate>(new ArithmeticValueUpdate()); + case Clear: + return std::make_unique<ClearValueUpdate>(); + case Remove: + return std::unique_ptr<RemoveValueUpdate>(new RemoveValueUpdate()); + case Map: + return std::unique_ptr<MapValueUpdate>( new MapValueUpdate()); + case TensorAdd: + return std::unique_ptr<TensorAddUpdate>( new TensorAddUpdate()); + case TensorModify: + return std::unique_ptr<TensorModifyUpdate>( new TensorModifyUpdate()); + case TensorRemove: + return std::unique_ptr<TensorRemoveUpdate>( new TensorRemoveUpdate()); + } + throw std::runtime_error(vespalib::make_string("Could not find a class for classId %d(%x)", type, type)); +} std::unique_ptr<ValueUpdate> ValueUpdate::createInstance(const DocumentTypeRepo& repo, const DataType& type, nbostream & stream) @@ -14,16 +71,12 @@ ValueUpdate::createInstance(const DocumentTypeRepo& repo, const DataType& type, int32_t classId = 0; stream >> classId; - const Identifiable::RuntimeClass * rtc(Identifiable::classFromId(classId)); - if (rtc != nullptr) { - std::unique_ptr<ValueUpdate> update(static_cast<ValueUpdate*>(rtc->create())); - /// \todo TODO (was warning): Updates are not versioned in serialization format. Will not work without altering it. - /// Should also use the serializer, not this deserialize into self. - update->deserialize(repo, type, stream); - return update; - } else { - throw std::runtime_error(vespalib::make_string("Could not find a class for classId %d(%x)", classId, classId)); - } + std::unique_ptr<ValueUpdate> update = create(static_cast<ValueUpdateType>(classId)); + + /// \todo TODO (was warning): Updates are not versioned in serialization format. Will not work without altering it. + /// Should also use the serializer, not this deserialize into self. + update->deserialize(repo, type, stream); + return update; } std::ostream& diff --git a/document/src/vespa/document/update/valueupdate.h b/document/src/vespa/document/update/valueupdate.h index 0b52fe46ac9..c97de4d54e1 100644 --- a/document/src/vespa/document/update/valueupdate.h +++ b/document/src/vespa/document/update/valueupdate.h @@ -30,7 +30,7 @@ class Field; class FieldValue; class DataType; -class ValueUpdate : public vespalib::Identifiable +class ValueUpdate { protected: using nbostream = vespalib::nbostream; @@ -53,11 +53,12 @@ public: Clear = IDENTIFIABLE_CLASSID(ClearValueUpdate), Map = IDENTIFIABLE_CLASSID(MapValueUpdate), Remove = IDENTIFIABLE_CLASSID(RemoveValueUpdate), - TensorModifyUpdate = IDENTIFIABLE_CLASSID(TensorModifyUpdate), - TensorAddUpdate = IDENTIFIABLE_CLASSID(TensorAddUpdate), - TensorRemoveUpdate = IDENTIFIABLE_CLASSID(TensorRemoveUpdate) + TensorModify = IDENTIFIABLE_CLASSID(TensorModifyUpdate), + TensorAdd = IDENTIFIABLE_CLASSID(TensorAddUpdate), + TensorRemove = IDENTIFIABLE_CLASSID(TensorRemoveUpdate) }; + virtual ~ValueUpdate() = default; virtual bool operator==(const ValueUpdate&) const = 0; bool operator != (const ValueUpdate & rhs) const { return ! (*this == rhs); } @@ -85,10 +86,8 @@ public: virtual void deserialize(const DocumentTypeRepo& repo, const DataType& type, nbostream & stream) = 0; /** @return The operation type. */ - ValueUpdateType getType() const { - return static_cast<ValueUpdateType>(getClass().id()); - } - + ValueUpdateType getType() const noexcept { return _type; } + const char * className() const noexcept; /** * Visit this fieldvalue for double dispatch. */ @@ -96,8 +95,11 @@ public: virtual void print(std::ostream& out, bool verbose, const std::string& indent) const = 0; virtual void printXml(XmlOutputStream& out) const = 0; - - DECLARE_IDENTIFIABLE_ABSTRACT(ValueUpdate); +protected: + ValueUpdate(ValueUpdateType type) : _type(type) { } +private: + static std::unique_ptr<ValueUpdate> create(ValueUpdateType type); + ValueUpdateType _type; }; std::ostream& operator<<(std::ostream& out, const ValueUpdate & p); diff --git a/document/src/vespa/document/util/feed_reject_helper.cpp b/document/src/vespa/document/util/feed_reject_helper.cpp index a6829ec0c60..3dec889661b 100644 --- a/document/src/vespa/document/util/feed_reject_helper.cpp +++ b/document/src/vespa/document/util/feed_reject_helper.cpp @@ -17,8 +17,8 @@ FeedRejectHelper::mustReject(const document::ValueUpdate & valueUpdate) { using namespace document; switch (valueUpdate.getType()) { case ValueUpdate::Add: - case ValueUpdate::TensorAddUpdate: - case ValueUpdate::TensorModifyUpdate: + case ValueUpdate::TensorAdd: + case ValueUpdate::TensorModify: case ValueUpdate::Map: return true; case ValueUpdate::Assign: { diff --git a/searchcore/src/vespa/searchcore/proton/common/attribute_updater.cpp b/searchcore/src/vespa/searchcore/proton/common/attribute_updater.cpp index 5b134c65e84..fe29a11639b 100644 --- a/searchcore/src/vespa/searchcore/proton/common/attribute_updater.cpp +++ b/searchcore/src/vespa/searchcore/proton/common/attribute_updater.cpp @@ -157,12 +157,12 @@ AttributeUpdater::handleUpdateT(V & vec, Accessor, uint32_t lid, const ValueUpda const MapValueUpdate & map(static_cast<const MapValueUpdate &>(upd)); if (!vec.AttributeVector::apply(lid, map)) { throw UpdateException(make_string("attribute map(%s, %s) failed: %s[%u]", - map.getKey().className(), map.getUpdate().getClass().name(), + map.getKey().className(), map.getUpdate().className(), vec.getName().c_str(), lid)); } } else { LOG(warning, "Unsupported value update operation %s on multivalue vector %s", - upd.getClass().name(), vec.getName().c_str()); + upd.className(), vec.getName().c_str()); } } else { if (op == ValueUpdate::Assign) { @@ -178,7 +178,7 @@ AttributeUpdater::handleUpdateT(V & vec, Accessor, uint32_t lid, const ValueUpda } else if (op == ValueUpdate::Clear) { vec.clearDoc(lid); } else { - LOG(warning, "Unsupported value update operation %s on singlevalue vector %s", upd.getClass().name(), vec.getName().c_str()); + LOG(warning, "Unsupported value update operation %s on singlevalue vector %s", upd.className(), vec.getName().c_str()); } } } @@ -200,7 +200,7 @@ AttributeUpdater::handleUpdate(PredicateAttribute &vec, uint32_t lid, const Valu vec.clearDoc(lid); } else { LOG(warning, "Unsupported value update operation %s on singlevalue vector %s", - upd.getClass().name(), vec.getName().c_str()); + upd.className(), vec.getName().c_str()); } } @@ -217,17 +217,17 @@ AttributeUpdater::handleUpdate(TensorAttribute &vec, uint32_t lid, const ValueUp vec.clearDoc(lid); updateValue(vec, lid, assign.getValue()); } - } else if (op == ValueUpdate::TensorModifyUpdate) { + } else if (op == ValueUpdate::TensorModify) { vec.update_tensor(lid, static_cast<const TensorModifyUpdate &>(upd), false); - } else if (op == ValueUpdate::TensorAddUpdate) { + } else if (op == ValueUpdate::TensorAdd) { vec.update_tensor(lid, static_cast<const TensorAddUpdate &>(upd), true); - } else if (op == ValueUpdate::TensorRemoveUpdate) { + } else if (op == ValueUpdate::TensorRemove) { vec.update_tensor(lid, static_cast<const TensorRemoveUpdate &>(upd), false); } else if (op == ValueUpdate::Clear) { vec.clearDoc(lid); } else { LOG(warning, "Unsupported value update operation %s on singlevalue tensor attribute %s", - upd.getClass().name(), vec.getName().c_str()); + upd.className(), vec.getName().c_str()); } } @@ -247,7 +247,7 @@ AttributeUpdater::handleUpdate(ReferenceAttribute &vec, uint32_t lid, const Valu vec.clearDoc(lid); } else { LOG(warning, "Unsupported value update operation %s on singlevalue reference attribute %s", - upd.getClass().name(), vec.getName().c_str()); + upd.className(), vec.getName().c_str()); } } diff --git a/searchlib/src/vespa/searchlib/attribute/attributevector.cpp b/searchlib/src/vespa/searchlib/attribute/attributevector.cpp index ea2379eef58..07563ad369d 100644 --- a/searchlib/src/vespa/searchlib/attribute/attributevector.cpp +++ b/searchlib/src/vespa/searchlib/attribute/attributevector.cpp @@ -493,10 +493,10 @@ AttributeVector::apply(DocId doc, const MapValueUpdate &map) { bool retval(doc < getNumDocs()); if (retval) { const ValueUpdate & vu(map.getUpdate()); - if (vu.inherits(ArithmeticValueUpdate::classId)) { + if (vu.getType() == ValueUpdate::Arithmetic) { const ArithmeticValueUpdate &au(static_cast<const ArithmeticValueUpdate &>(vu)); retval = applyWeight(doc, map.getKey(), au); - } else if (vu.inherits(AssignValueUpdate::classId)) { + } else if (vu.getType() == ValueUpdate::Assign) { const AssignValueUpdate &au(static_cast<const AssignValueUpdate &>(vu)); retval = applyWeight(doc, map.getKey(), au); } else { |