summaryrefslogtreecommitdiffstats
path: root/document
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2022-03-17 20:26:58 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2022-03-17 20:26:58 +0000
commit2974fb58ddc245e94f325eb6b1407c16bd6887bc (patch)
tree6c80d1d1e35151c7b460d0ecd157c91b9af09836 /document
parentf5d308f5cb8bd1f5a4d7daaac18ed1aaa8e8778e (diff)
Implement className on document::FieldValue
Diffstat (limited to 'document')
-rw-r--r--document/src/vespa/document/fieldvalue/fieldvalue.cpp44
-rw-r--r--document/src/vespa/document/fieldvalue/fieldvalue.h7
-rw-r--r--document/src/vespa/document/fieldvalue/tensorfieldvalue.cpp2
-rw-r--r--document/src/vespa/document/update/addfieldpathupdate.cpp3
-rw-r--r--document/src/vespa/document/update/addvalueupdate.cpp3
-rw-r--r--document/src/vespa/document/update/arithmeticvalueupdate.cpp3
-rw-r--r--document/src/vespa/document/update/assignfieldpathupdate.cpp4
-rw-r--r--document/src/vespa/document/update/assignvalueupdate.cpp3
-rw-r--r--document/src/vespa/document/update/mapvalueupdate.cpp4
-rw-r--r--document/src/vespa/document/update/removevalueupdate.cpp3
-rw-r--r--document/src/vespa/document/update/tensor_add_update.cpp5
-rw-r--r--document/src/vespa/document/update/tensor_modify_update.cpp5
-rw-r--r--document/src/vespa/document/update/tensor_remove_update.cpp3
-rw-r--r--document/src/vespa/document/update/valueupdate.h2
14 files changed, 65 insertions, 26 deletions
diff --git a/document/src/vespa/document/fieldvalue/fieldvalue.cpp b/document/src/vespa/document/fieldvalue/fieldvalue.cpp
index 465847c1221..be3a0dd3cb6 100644
--- a/document/src/vespa/document/fieldvalue/fieldvalue.cpp
+++ b/document/src/vespa/document/fieldvalue/fieldvalue.cpp
@@ -26,6 +26,50 @@ namespace document {
using namespace fieldvalue;
+const char *
+FieldValue::className() const noexcept {
+ switch (type()) {
+ case Type::BOOL:
+ return "BoolFieldValue";
+ case Type::BYTE:
+ return "ByteFieldValue";
+ case Type::SHORT:
+ return "ShortFieldValue";
+ case Type::INT:
+ return "IntFieldValue";
+ case Type::LONG:
+ return "LongFieldValue";
+ case Type::FLOAT:
+ return "FloatFieldValue";
+ case Type::DOUBLE:
+ return "DoubleFieldValue";
+ case Type::STRING:
+ return "StringFieldValue";
+ case Type::RAW:
+ return "RawFieldValue";
+ case Type::PREDICATE:
+ return "PredicateFieldValue";
+ case Type::TENSOR:
+ return "TensorFieldValue";
+ case Type::ANNOTATION_REFERENCE:
+ return "AnnotationReferenceFieldValue";
+ case Type::REFERENCE:
+ return "ReferenceFieldValue";
+ case Type::ARRAY:
+ return "ArrayFieldValue";
+ case Type::WSET:
+ return "WSetFieldValue";
+ case Type::MAP:
+ return "MapFieldValue";
+ case Type::STRUCT:
+ return "StructFieldValue";
+ case Type::DOCUMENT:
+ return "DocumentFieldValue";
+ case Type::NONE:
+ default:
+ return "NONE - Impossible";
+ }
+}
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 976f060f192..4f589913a4d 100644
--- a/document/src/vespa/document/fieldvalue/fieldvalue.h
+++ b/document/src/vespa/document/fieldvalue/fieldvalue.h
@@ -30,7 +30,11 @@ class DataType;
class FieldValue
{
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};
+ 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>;
@@ -180,6 +184,7 @@ public:
bool isFixedSizeSingleValue() const noexcept {
return (_type == Type::BOOL) || isNumeric();
}
+ const char * className() const noexcept;
protected:
FieldValue(Type type) noexcept : _type(type) { }
FieldValue(const FieldValue&) = default;
diff --git a/document/src/vespa/document/fieldvalue/tensorfieldvalue.cpp b/document/src/vespa/document/fieldvalue/tensorfieldvalue.cpp
index 66cfbc42c07..94f2ddc994f 100644
--- a/document/src/vespa/document/fieldvalue/tensorfieldvalue.cpp
+++ b/document/src/vespa/document/fieldvalue/tensorfieldvalue.cpp
@@ -174,7 +174,7 @@ FieldValue &
TensorFieldValue::assign(const FieldValue &value)
{
if (value.isA(Type::TENSOR)) {
- auto rhs = static_cast<const TensorFieldValue *>(&value);
+ const auto * rhs = static_cast<const TensorFieldValue *>(&value);
*this = *rhs;
} else {
return FieldValue::assign(value);
diff --git a/document/src/vespa/document/update/addfieldpathupdate.cpp b/document/src/vespa/document/update/addfieldpathupdate.cpp
index cff38c246e4..bd06451759e 100644
--- a/document/src/vespa/document/update/addfieldpathupdate.cpp
+++ b/document/src/vespa/document/update/addfieldpathupdate.cpp
@@ -7,7 +7,6 @@
#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>
@@ -60,7 +59,7 @@ AddIteratorHandler::doModify(FieldValue &fv) {
cf.add(_values[i]);
}
} else {
- vespalib::string err = make_string("Unable to add a value to a \"%s\" field value.", vespalib::getClassName(fv).c_str());
+ vespalib::string err = make_string("Unable to add a value to a \"%s\" field value.", fv.className());
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 6fda6ddc362..6f6c9a93738 100644
--- a/document/src/vespa/document/update/addvalueupdate.cpp
+++ b/document/src/vespa/document/update/addvalueupdate.cpp
@@ -7,7 +7,6 @@
#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;
@@ -71,7 +70,7 @@ AddValueUpdate::applyTo(FieldValue& value) const
WeightedSetFieldValue& doc(static_cast<WeightedSetFieldValue&>(value));
doc.add(*_value, _weight);
} else {
- vespalib::string err = make_string("Unable to add a value to a \"%s\" field value.", vespalib::getClassName(value).c_str());
+ vespalib::string err = make_string("Unable to add a value to a \"%s\" field value.", value.className());
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 7500e28ce07..e5fb5aee8af 100644
--- a/document/src/vespa/document/update/arithmeticvalueupdate.cpp
+++ b/document/src/vespa/document/update/arithmeticvalueupdate.cpp
@@ -4,7 +4,6 @@
#include <vespa/document/fieldvalue/fieldvalues.h>
#include <vespa/vespalib/util/exceptions.h>
#include <vespa/vespalib/util/xmlstream.h>
-#include <vespa/vespalib/util/classname.h>
#include <ostream>
using vespalib::IllegalArgumentException;
@@ -62,7 +61,7 @@ ArithmeticValueUpdate::applyTo(FieldValue& value) const
} else {
vespalib::string err = vespalib::make_string(
"Unable to perform an arithmetic update on a \"%s\" field "
- "value.", vespalib::getClassName(value).c_str());
+ "value.", value.className());
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 6f2bbfd89c4..d4cbff2aae9 100644
--- a/document/src/vespa/document/update/assignfieldpathupdate.cpp
+++ b/document/src/vespa/document/update/assignfieldpathupdate.cpp
@@ -7,7 +7,6 @@
#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,8 +117,7 @@ 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(), vespalib::getClassName(_newValue).c_str(),
- vespalib::getClassName(fv).c_str());
+ _newValue.toString().c_str(), _newValue.className(), fv.className());
throw vespalib::IllegalArgumentException(err, VESPA_STRLOC);
}
if (_removeIfZero
diff --git a/document/src/vespa/document/update/assignvalueupdate.cpp b/document/src/vespa/document/update/assignvalueupdate.cpp
index 0f355434f08..cf2321dbf56 100644
--- a/document/src/vespa/document/update/assignvalueupdate.cpp
+++ b/document/src/vespa/document/update/assignvalueupdate.cpp
@@ -7,7 +7,6 @@
#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;
@@ -72,7 +71,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.",
- vespalib::getClassName(*_value).c_str(), vespalib::getClassName(value).c_str());
+ _value->className(), value.className());
throw IllegalStateException(err, VESPA_STRLOC);
}
if (_value) {
diff --git a/document/src/vespa/document/update/mapvalueupdate.cpp b/document/src/vespa/document/update/mapvalueupdate.cpp
index 684ff1fb6e4..48e52a9d2cc 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->type() != FieldValue::Type::INT) {
+ if ( !_key->isA(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(),
@@ -60,7 +60,7 @@ MapValueUpdate::checkCompatibility(const Field& field) const
}
} else {
throw IllegalArgumentException("MapValueUpdate does not support "
- "datatype " + field.getDataType().toString() + ".", VESPA_STRLOC);
+ "datatype " + field.getDataType().toString() + ".", VESPA_STRLOC);
}
}
diff --git a/document/src/vespa/document/update/removevalueupdate.cpp b/document/src/vespa/document/update/removevalueupdate.cpp
index fda3b09163f..a61553da4d1 100644
--- a/document/src/vespa/document/update/removevalueupdate.cpp
+++ b/document/src/vespa/document/update/removevalueupdate.cpp
@@ -7,7 +7,6 @@
#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;
@@ -64,7 +63,7 @@ RemoveValueUpdate::applyTo(FieldValue& value) const
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.", vespalib::getClassName(value).c_str());
+ std::string err = vespalib::make_string("Unable to remove a value from a \"%s\" field value.", value.className());
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 2474429f2a9..1f8aed2d8b4 100644
--- a/document/src/vespa/document/update/tensor_add_update.cpp
+++ b/document/src/vespa/document/update/tensor_add_update.cpp
@@ -13,7 +13,6 @@
#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;
@@ -109,7 +108,7 @@ TensorAddUpdate::applyTo(FieldValue& value) const
}
} else {
vespalib::string err = make_string("Unable to perform a tensor add update on a '%s' field value",
- vespalib::getClassName(value).c_str());
+ value.className());
throw IllegalStateException(err, VESPA_STRLOC);
}
return true;
@@ -139,7 +138,7 @@ TensorAddUpdate::deserialize(const DocumentTypeRepo &repo, const DataType &type,
_tensor.reset(static_cast<TensorFieldValue *>(tensor.release()));
} else {
vespalib::string err = make_string("Expected tensor field value, got a '%s' field value",
- vespalib::getClassName(*tensor).c_str());
+ tensor->className());
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 9cfb38e70e2..49ea57f28c1 100644
--- a/document/src/vespa/document/update/tensor_modify_update.cpp
+++ b/document/src/vespa/document/update/tensor_modify_update.cpp
@@ -15,7 +15,6 @@
#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;
@@ -189,7 +188,7 @@ TensorModifyUpdate::applyTo(FieldValue& value) const
}
} else {
vespalib::string err = make_string("Unable to perform a tensor modify update on a '%s' field value",
- vespalib::getClassName(value).c_str());
+ value.className());
throw IllegalStateException(err, VESPA_STRLOC);
}
return true;
@@ -246,7 +245,7 @@ TensorModifyUpdate::deserialize(const DocumentTypeRepo &repo, const DataType &ty
_tensor.reset(static_cast<TensorFieldValue *>(tensor.release()));
} else {
vespalib::string err = make_string("Expected tensor field value, got a '%s' field value",
- vespalib::getClassName(*tensor).c_str());
+ tensor->className());
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 f1f4becb285..f2d11ef8234 100644
--- a/document/src/vespa/document/update/tensor_remove_update.cpp
+++ b/document/src/vespa/document/update/tensor_remove_update.cpp
@@ -10,7 +10,6 @@
#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;
@@ -134,7 +133,7 @@ TensorRemoveUpdate::applyTo(FieldValue &value) const
}
} else {
vespalib::string err = make_string("Unable to perform a tensor remove update on a '%s' field value",
- vespalib::getClassName(value).c_str());
+ value.className());
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 8564e81f777..ec903c1adc1 100644
--- a/document/src/vespa/document/update/valueupdate.h
+++ b/document/src/vespa/document/update/valueupdate.h
@@ -33,7 +33,7 @@ class DataType;
class ValueUpdate : public vespalib::Identifiable,
public Printable,
-public vespalib::xml::XmlSerializable
+ public vespalib::xml::XmlSerializable
{
protected:
using nbostream = vespalib::nbostream;