diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2019-01-09 10:20:42 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2019-01-09 13:05:01 +0000 |
commit | 5f321f1d1df8da72187a711f9cdc36481dc25cae (patch) | |
tree | 5378915b89a25ead8cea4c7678357ec66916b38d | |
parent | a9c77576da201d3da009e8f86800d23070284a41 (diff) |
Brief implementation skeleton for bool field type.
20 files changed, 218 insertions, 92 deletions
diff --git a/document/src/vespa/document/datatype/datatype.cpp b/document/src/vespa/document/datatype/datatype.cpp index 8d2721a4d9b..8c17ca4e383 100644 --- a/document/src/vespa/document/datatype/datatype.cpp +++ b/document/src/vespa/document/datatype/datatype.cpp @@ -21,6 +21,7 @@ NumericDataType INT_OBJ(DataType::T_INT); NumericDataType LONG_OBJ(DataType::T_LONG); NumericDataType FLOAT_OBJ(DataType::T_FLOAT); NumericDataType DOUBLE_OBJ(DataType::T_DOUBLE); +NumericDataType BOOL_OBJ(DataType::T_BOOL); PrimitiveDataType STRING_OBJ(DataType::T_STRING); PrimitiveDataType RAW_OBJ(DataType::T_RAW); DocumentType DOCUMENT_OBJ("document"); @@ -37,6 +38,7 @@ const DataType *const DataType::INT(&INT_OBJ); const DataType *const DataType::LONG(&LONG_OBJ); const DataType *const DataType::FLOAT(&FLOAT_OBJ); const DataType *const DataType::DOUBLE(&DOUBLE_OBJ); +const DataType *const DataType::BOOL(&BOOL_OBJ); const DataType *const DataType::STRING(&STRING_OBJ); const DataType *const DataType::RAW(&RAW_OBJ); const DocumentType *const DataType::DOCUMENT(&DOCUMENT_OBJ); @@ -71,6 +73,7 @@ DataType2FieldValueId::DataType2FieldValueId() _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; @@ -103,6 +106,7 @@ DataType::getDefaultDataTypes() types.push_back(LONG); types.push_back(FLOAT); types.push_back(DOUBLE); + types.push_back(BOOL); types.push_back(STRING); types.push_back(RAW); types.push_back(DOCUMENT); diff --git a/document/src/vespa/document/datatype/datatype.h b/document/src/vespa/document/datatype/datatype.h index 4dd5d6aae64..723e7c69ed6 100644 --- a/document/src/vespa/document/datatype/datatype.h +++ b/document/src/vespa/document/datatype/datatype.h @@ -66,6 +66,7 @@ public: T_RAW = 3, T_LONG = 4, T_DOUBLE = 5, + T_BOOL = 6, T_DOCUMENT = 8, // Type of super document type Document.0 that all documents inherit. // T_TIMESTAMP = 9, // Not used anymore, Id should probably not be reused T_URI = 10, @@ -88,6 +89,7 @@ public: static const DataType *const LONG; static const DataType *const FLOAT; static const DataType *const DOUBLE; + static const DataType *const BOOL; static const DataType *const STRING; static const DataType *const RAW; static const DocumentType *const DOCUMENT; @@ -108,7 +110,7 @@ public: * Create a field value using this datatype. */ virtual std::unique_ptr<FieldValue> createFieldValue() const = 0; - virtual DataType* clone() const override = 0; + DataType* clone() const override = 0; /** * Whether another datatype is a supertype of this one. Document types may diff --git a/document/src/vespa/document/datatype/primitivedatatype.cpp b/document/src/vespa/document/datatype/primitivedatatype.cpp index e48e4464acf..7ec47f52d9c 100644 --- a/document/src/vespa/document/datatype/primitivedatatype.cpp +++ b/document/src/vespa/document/datatype/primitivedatatype.cpp @@ -23,6 +23,7 @@ namespace { const char *Double = "Double"; const char *Uri = "Uri"; const char *Byte = "Byte"; + const char *Bool = "Bool"; const char *Predicate = "Predicate"; const char *Tensor = "Tensor"; @@ -37,6 +38,7 @@ namespace { case DataType::T_DOUBLE: return Double; case DataType::T_URI: return Uri; case DataType::T_BYTE: return Byte; + case DataType::T_BOOL: return Bool; case DataType::T_PREDICATE: return Predicate; case DataType::T_TENSOR: return Tensor; default: @@ -56,16 +58,17 @@ FieldValue::UP PrimitiveDataType::createFieldValue() const { switch (getId()) { - case T_INT: return FieldValue::UP(new IntFieldValue); - case T_SHORT: return FieldValue::UP(new ShortFieldValue); - case T_FLOAT: return FieldValue::UP(new FloatFieldValue); - case T_URI: return FieldValue::UP(new StringFieldValue); - case T_STRING: return FieldValue::UP(new StringFieldValue); - case T_RAW: return FieldValue::UP(new RawFieldValue); - case T_LONG: return FieldValue::UP(new LongFieldValue); - case T_DOUBLE: return FieldValue::UP(new DoubleFieldValue); - case T_BYTE: return FieldValue::UP(new ByteFieldValue); - case T_PREDICATE: return FieldValue::UP(new PredicateFieldValue); + case T_INT: return std::make_unique<IntFieldValue>(); + case T_SHORT: return std::make_unique<ShortFieldValue>(); + case T_FLOAT: return std::make_unique<FloatFieldValue>(); + case T_URI: return std::make_unique<StringFieldValue>(); + case T_STRING: return std::make_unique<StringFieldValue>(); + case T_RAW: return std::make_unique<RawFieldValue>(); + case T_LONG: return std::make_unique<LongFieldValue>(); + case T_DOUBLE: return std::make_unique<DoubleFieldValue>(); + case T_BOOL: return std::make_unique<BoolFieldValue>(); + case T_BYTE: return std::make_unique<ByteFieldValue>(); + case T_PREDICATE: return std::make_unique<PredicateFieldValue>(); case T_TENSOR: return std::make_unique<TensorFieldValue>(); } LOG_ABORT("getId() returned value out of range"); diff --git a/document/src/vespa/document/fieldvalue/CMakeLists.txt b/document/src/vespa/document/fieldvalue/CMakeLists.txt index 0b161cff08a..dcef1bc8305 100644 --- a/document/src/vespa/document/fieldvalue/CMakeLists.txt +++ b/document/src/vespa/document/fieldvalue/CMakeLists.txt @@ -3,6 +3,7 @@ vespa_add_library(document_fieldvalues OBJECT SOURCES annotationreferencefieldvalue.cpp arrayfieldvalue.cpp + boolfieldvalue.cpp bytefieldvalue.cpp collectionfieldvalue.cpp document.cpp diff --git a/document/src/vespa/document/fieldvalue/boolfieldvalue.cpp b/document/src/vespa/document/fieldvalue/boolfieldvalue.cpp new file mode 100644 index 00000000000..8ee2556d751 --- /dev/null +++ b/document/src/vespa/document/fieldvalue/boolfieldvalue.cpp @@ -0,0 +1,60 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include "boolfieldvalue.h" +#include <vespa/document/datatype/datatype.h> +#include <vespa/vespalib/util/xmlstream.h> +#include <ostream> + +using namespace vespalib::xml; + +namespace document { + +IMPLEMENT_IDENTIFIABLE(BoolFieldValue, FieldValue); + +BoolFieldValue::BoolFieldValue(bool value) + : _value(value), _altered(false) { +} + +BoolFieldValue::~BoolFieldValue() = default; + +FieldValue &BoolFieldValue::assign(const FieldValue &rhs) { + if (rhs.inherits(BoolFieldValue::classId)) { + operator=(static_cast<const BoolFieldValue &>(rhs)); + return *this; + } else { + _altered = true; + return FieldValue::assign(rhs); + } +} + +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 { + out << XmlContent(getAsString()); +} + +void BoolFieldValue::print(std::ostream& out, bool, const std::string&) const { + out << (_value ? "true" : "false") << "\n"; +} + +const DataType * +BoolFieldValue::getDataType() const { + return DataType::BOOL; +} + +bool +BoolFieldValue::hasChanged() const { + return _altered; +} + +FieldValue * +BoolFieldValue::clone() const { + return new BoolFieldValue(*this); +} + +} // namespace document diff --git a/document/src/vespa/document/fieldvalue/boolfieldvalue.h b/document/src/vespa/document/fieldvalue/boolfieldvalue.h new file mode 100644 index 00000000000..d81fa25848d --- /dev/null +++ b/document/src/vespa/document/fieldvalue/boolfieldvalue.h @@ -0,0 +1,37 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#pragma once + +#include "fieldvalue.h" + +namespace document { + +class BoolFieldValue : public FieldValue { + bool _value; + bool _altered; + +public: + BoolFieldValue(bool value=false); + ~BoolFieldValue() override; + + void accept(FieldValueVisitor &visitor) override { visitor.visit(*this); } + void accept(ConstFieldValueVisitor &visitor) const override { visitor.visit(*this); } + + FieldValue *clone() const override; + int compare(const FieldValue &rhs) const override; + + void printXml(XmlOutputStream &out) const override; + void print(std::ostream &out, bool verbose, const std::string &indent) const override; + + const DataType *getDataType() const override; + bool hasChanged() const override; + + bool getValue() const { return _value; } + void setValue(bool v) { _value = v; } + + FieldValue &assign(const FieldValue &rhs) override; + + DECLARE_IDENTIFIABLE(BoolFieldValue); +}; + +} diff --git a/document/src/vespa/document/fieldvalue/document.cpp b/document/src/vespa/document/fieldvalue/document.cpp index 7acc7e97be9..d915d9fd66d 100644 --- a/document/src/vespa/document/fieldvalue/document.cpp +++ b/document/src/vespa/document/fieldvalue/document.cpp @@ -10,6 +10,7 @@ #include <vespa/vespalib/objects/nbostream.h> #include <vespa/document/util/serializableexceptions.h> #include <vespa/document/base/exceptions.h> +#include <vespa/document/fieldset/fieldsets.h> #include <vespa/document/util/bytebuffer.h> #include <vespa/vespalib/util/xmlstream.h> #include <sstream> diff --git a/document/src/vespa/document/fieldvalue/fieldvalues.h b/document/src/vespa/document/fieldvalue/fieldvalues.h index 6d438bcd0d5..cc665cee95c 100644 --- a/document/src/vespa/document/fieldvalue/fieldvalues.h +++ b/document/src/vespa/document/fieldvalue/fieldvalues.h @@ -2,18 +2,19 @@ #pragma once -#include <vespa/document/fieldvalue/arrayfieldvalue.h> -#include <vespa/document/fieldvalue/bytefieldvalue.h> -#include <vespa/document/fieldvalue/document.h> -#include <vespa/document/fieldvalue/doublefieldvalue.h> -#include <vespa/document/fieldvalue/floatfieldvalue.h> -#include <vespa/document/fieldvalue/intfieldvalue.h> -#include <vespa/document/fieldvalue/longfieldvalue.h> -#include <vespa/document/fieldvalue/mapfieldvalue.h> -#include <vespa/document/fieldvalue/predicatefieldvalue.h> -#include <vespa/document/fieldvalue/rawfieldvalue.h> -#include <vespa/document/fieldvalue/shortfieldvalue.h> -#include <vespa/document/fieldvalue/stringfieldvalue.h> -#include <vespa/document/fieldvalue/weightedsetfieldvalue.h> -#include <vespa/document/fieldvalue/tensorfieldvalue.h> +#include "arrayfieldvalue.h" +#include "boolfieldvalue.h" +#include "bytefieldvalue.h" +#include "document.h" +#include "doublefieldvalue.h" +#include "floatfieldvalue.h" +#include "intfieldvalue.h" +#include "longfieldvalue.h" +#include "mapfieldvalue.h" +#include "predicatefieldvalue.h" +#include "rawfieldvalue.h" +#include "shortfieldvalue.h" +#include "stringfieldvalue.h" +#include "weightedsetfieldvalue.h" +#include "tensorfieldvalue.h" diff --git a/document/src/vespa/document/fieldvalue/fieldvaluevisitor.h b/document/src/vespa/document/fieldvalue/fieldvaluevisitor.h index ef07dd25212..778b1c77023 100644 --- a/document/src/vespa/document/fieldvalue/fieldvaluevisitor.h +++ b/document/src/vespa/document/fieldvalue/fieldvaluevisitor.h @@ -5,6 +5,7 @@ namespace document { class AnnotationReferenceFieldValue; class ArrayFieldValue; +class BoolFieldValue; class ByteFieldValue; class Document; class DoubleFieldValue; @@ -26,6 +27,7 @@ struct FieldValueVisitor { virtual void visit(AnnotationReferenceFieldValue &value) = 0; virtual void visit(ArrayFieldValue &value) = 0; + virtual void visit(BoolFieldValue &value) = 0; virtual void visit(ByteFieldValue &value) = 0; virtual void visit(Document &value) = 0; virtual void visit(DoubleFieldValue &value) = 0; @@ -48,6 +50,7 @@ struct ConstFieldValueVisitor { virtual void visit(const AnnotationReferenceFieldValue &value) = 0; virtual void visit(const ArrayFieldValue &value) = 0; + virtual void visit(const BoolFieldValue &value) = 0; virtual void visit(const ByteFieldValue &value) = 0; virtual void visit(const Document &value) = 0; virtual void visit(const DoubleFieldValue &value) = 0; diff --git a/document/src/vespa/document/fieldvalue/numericfieldvalue.hpp b/document/src/vespa/document/fieldvalue/numericfieldvalue.hpp index 90c93e7a944..91873f021d1 100644 --- a/document/src/vespa/document/fieldvalue/numericfieldvalue.hpp +++ b/document/src/vespa/document/fieldvalue/numericfieldvalue.hpp @@ -27,8 +27,7 @@ NumericFieldValue<Number>::assign(const FieldValue& value) _value = static_cast<Number>(value.getAsLong()); } else if (value.getClass().id() == IDENTIFIABLE_CLASSID(FloatFieldValue)) { _value = static_cast<Number>(value.getAsFloat()); - } else if (value.getClass().id() == IDENTIFIABLE_CLASSID(DoubleFieldValue)) - { + } else if (value.getClass().id() == IDENTIFIABLE_CLASSID(DoubleFieldValue)) { _value = static_cast<Number>(value.getAsDouble()); } else { return FieldValue::assign(value); diff --git a/document/src/vespa/document/fieldvalue/predicatefieldvalue.h b/document/src/vespa/document/fieldvalue/predicatefieldvalue.h index d5c58e862f5..e0df3a38353 100644 --- a/document/src/vespa/document/fieldvalue/predicatefieldvalue.h +++ b/document/src/vespa/document/fieldvalue/predicatefieldvalue.h @@ -40,5 +40,4 @@ public: DECLARE_IDENTIFIABLE(PredicateFieldValue); }; -} // namespace document - +} diff --git a/document/src/vespa/document/serialization/vespadocumentdeserializer.cpp b/document/src/vespa/document/serialization/vespadocumentdeserializer.cpp index 4f30851ac4c..89172b0bc46 100644 --- a/document/src/vespa/document/serialization/vespadocumentdeserializer.cpp +++ b/document/src/vespa/document/serialization/vespadocumentdeserializer.cpp @@ -5,6 +5,7 @@ #include <vespa/document/annotation/spantree.h> #include <vespa/document/fieldvalue/annotationreferencefieldvalue.h> #include <vespa/document/fieldvalue/arrayfieldvalue.h> +#include <vespa/document/fieldvalue/boolfieldvalue.h> #include <vespa/document/fieldvalue/bytefieldvalue.h> #include <vespa/document/fieldvalue/document.h> #include <vespa/document/fieldvalue/doublefieldvalue.h> @@ -190,12 +191,12 @@ void VespaDocumentDeserializer::read(MapFieldValue &value) { } namespace { -template <typename T> struct ValueType { typedef typename T::Number Type; }; -template <> struct ValueType<ShortFieldValue> { typedef uint16_t Type; }; -template <> struct ValueType<IntFieldValue> { typedef uint32_t Type; }; -template <> struct ValueType<LongFieldValue> { typedef uint64_t Type; }; -template <> -struct ValueType<RawFieldValue> { typedef vespalib::string Type; }; +template <typename T> struct ValueType { using Type = typename T::Number; }; +template <> struct ValueType<BoolFieldValue> { using Type = bool; }; +template <> struct ValueType<ShortFieldValue> { using Type = uint16_t; }; +template <> struct ValueType<IntFieldValue> { using Type = uint32_t; }; +template <> struct ValueType<LongFieldValue> { using Type = uint64_t; }; +template <> struct ValueType<RawFieldValue> { using Type = vespalib::string; }; template <typename T> void readFieldValue(nbostream &input, T &value) { @@ -214,6 +215,10 @@ stringref readAttributeString(Input &input) { } } // namespace +void VespaDocumentDeserializer::read(BoolFieldValue &value) { + readFieldValue(_stream, value); +} + void VespaDocumentDeserializer::read(ByteFieldValue &value) { readFieldValue(_stream, value); } diff --git a/document/src/vespa/document/serialization/vespadocumentdeserializer.h b/document/src/vespa/document/serialization/vespadocumentdeserializer.h index 64346428cdd..e6b490e1075 100644 --- a/document/src/vespa/document/serialization/vespadocumentdeserializer.h +++ b/document/src/vespa/document/serialization/vespadocumentdeserializer.h @@ -21,6 +21,7 @@ class VespaDocumentDeserializer : private FieldValueVisitor { void visit(AnnotationReferenceFieldValue &value) override { read(value); } void visit(ArrayFieldValue &value) override { read(value); } + void visit(BoolFieldValue &value) override { read(value); } void visit(ByteFieldValue &value) override { read(value); } void visit(Document &value) override { read(value); } void visit(DoubleFieldValue &value) override { read(value); } @@ -63,6 +64,7 @@ public: void read(AnnotationReferenceFieldValue &value); void read(ArrayFieldValue &value); void read(MapFieldValue &value); + void read(BoolFieldValue &value); void read(ByteFieldValue &value); void read(DoubleFieldValue &value); void read(FloatFieldValue &value); diff --git a/document/src/vespa/document/serialization/vespadocumentserializer.cpp b/document/src/vespa/document/serialization/vespadocumentserializer.cpp index ae03bcc0d3c..3519f38baab 100644 --- a/document/src/vespa/document/serialization/vespadocumentserializer.cpp +++ b/document/src/vespa/document/serialization/vespadocumentserializer.cpp @@ -6,6 +6,7 @@ #include "util.h" #include <vespa/document/fieldvalue/annotationreferencefieldvalue.h> #include <vespa/document/fieldvalue/arrayfieldvalue.h> +#include <vespa/document/fieldvalue/boolfieldvalue.h> #include <vespa/document/fieldvalue/bytefieldvalue.h> #include <vespa/document/fieldvalue/document.h> #include <vespa/document/fieldvalue/doublefieldvalue.h> @@ -24,6 +25,7 @@ #include <vespa/document/update/updates.h> #include <vespa/document/update/fieldpathupdates.h> #include <vespa/document/util/bytebuffer.h> +#include <vespa/document/fieldset/fieldsets.h> #include <vespa/vespalib/data/slime/binary_format.h> #include <vespa/vespalib/objects/nbostream.h> #include <vespa/vespalib/data/databuffer.h> @@ -185,6 +187,10 @@ void VespaDocumentSerializer::write(const MapFieldValue &value) { } } +void VespaDocumentSerializer::write(const BoolFieldValue &value) { + _stream << value.getValue(); +} + void VespaDocumentSerializer::write(const ByteFieldValue &value) { _stream << value.getValue(); } diff --git a/document/src/vespa/document/serialization/vespadocumentserializer.h b/document/src/vespa/document/serialization/vespadocumentserializer.h index 818759d35b5..fde073c13b3 100644 --- a/document/src/vespa/document/serialization/vespadocumentserializer.h +++ b/document/src/vespa/document/serialization/vespadocumentserializer.h @@ -4,12 +4,10 @@ #include <vespa/document/fieldvalue/fieldvaluevisitor.h> #include <vespa/document/fieldvalue/fieldvaluewriter.h> -#include <vespa/document/fieldset/fieldsets.h> +#include <vespa/document/fieldset/fieldset.h> #include <vespa/document/update/updatevisitor.h> -namespace vespalib { - class nbostream; -} +namespace vespalib { class nbostream; } namespace document { @@ -40,6 +38,7 @@ public: void write(const AnnotationReferenceFieldValue &value); void write(const ArrayFieldValue &value); void write(const MapFieldValue &map); + void write(const BoolFieldValue &value); void write(const ByteFieldValue &value); void write(const DoubleFieldValue &val); void write(const FloatFieldValue &value); @@ -90,6 +89,7 @@ private: void visit(const AnnotationReferenceFieldValue &value) override { write(value); } void visit(const ArrayFieldValue &value) override { write(value); } + void visit(const BoolFieldValue &value) override { write(value); } void visit(const ByteFieldValue &value) override { write(value); } void visit(const Document &value) override { write(value, COMPLETE); } void visit(const DoubleFieldValue &value) override { write(value); } diff --git a/document/src/vespa/document/util/identifiableid.h b/document/src/vespa/document/util/identifiableid.h index c52888e8491..84cfc506bcc 100644 --- a/document/src/vespa/document/util/identifiableid.h +++ b/document/src/vespa/document/util/identifiableid.h @@ -19,7 +19,7 @@ #define CID_StringFieldValue DOCUMENT_CID(15) #define CID_RawFieldValue DOCUMENT_CID(16) //Gone with vespa 6 #define CID_ContentFieldValue DOCUMENT_CID(17) -//Long gone #define CID_ContentMetaFieldValue DOCUMENT_CID(18) +#define CID_BoolFieldValue DOCUMENT_CID(18) #define CID_ArrayFieldValue DOCUMENT_CID(19) #define CID_WeightedSetFieldValue DOCUMENT_CID(20) #define CID_FieldMapValue DOCUMENT_CID(21) diff --git a/searchcore/src/vespa/searchcore/proton/attribute/document_field_extractor.cpp b/searchcore/src/vespa/searchcore/proton/attribute/document_field_extractor.cpp index 64c3455be84..bbd2221f631 100644 --- a/searchcore/src/vespa/searchcore/proton/attribute/document_field_extractor.cpp +++ b/searchcore/src/vespa/searchcore/proton/attribute/document_field_extractor.cpp @@ -3,6 +3,7 @@ #include "document_field_extractor.h" #include <vespa/document/datatype/arraydatatype.h> #include <vespa/document/fieldvalue/arrayfieldvalue.h> +#include <vespa/document/fieldvalue/boolfieldvalue.h> #include <vespa/document/fieldvalue/bytefieldvalue.h> #include <vespa/document/fieldvalue/document.h> #include <vespa/document/fieldvalue/doublefieldvalue.h> @@ -17,6 +18,7 @@ #include <vespa/vespalib/util/exceptions.h> using document::FieldValue; +using document::BoolFieldValue; using document::ByteFieldValue; using document::ShortFieldValue; using document::IntFieldValue; @@ -45,6 +47,7 @@ class SetUndefinedValueVisitor : public FieldValueVisitor { void visit(document::AnnotationReferenceFieldValue &) override { } void visit(ArrayFieldValue &) override { } + void visit(BoolFieldValue &) override { } void visit(ByteFieldValue &value) override { value = getUndefined<int8_t>(); } void visit(Document &) override { } void visit(DoubleFieldValue &value) override { value = getUndefined<double>(); } @@ -65,6 +68,7 @@ class SetUndefinedValueVisitor : public FieldValueVisitor SetUndefinedValueVisitor setUndefinedValueVisitor; const ArrayDataType arrayTypeByte(*DataType::BYTE); +const ArrayDataType arrayTypeBool(*DataType::BOOL); const ArrayDataType arrayTypeShort(*DataType::SHORT); const ArrayDataType arrayTypeInt(*DataType::INT); const ArrayDataType arrayTypeLong(*DataType::LONG); @@ -78,6 +82,8 @@ getArrayType(const DataType &fieldType) switch (fieldType.getId()) { case DataType::Type::T_BYTE: return &arrayTypeByte; + case DataType::Type::T_BOOL: + return &arrayTypeByte; case DataType::Type::T_SHORT: return &arrayTypeShort; case DataType::Type::T_INT: diff --git a/searchsummary/src/vespa/searchsummary/docsummary/summaryfieldconverter.cpp b/searchsummary/src/vespa/searchsummary/docsummary/summaryfieldconverter.cpp index 290cc45648a..91a7fd45061 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/summaryfieldconverter.cpp +++ b/searchsummary/src/vespa/searchsummary/docsummary/summaryfieldconverter.cpp @@ -9,6 +9,7 @@ #include <vespa/document/annotation/spantreevisitor.h> #include <vespa/document/datatype/documenttype.h> #include <vespa/document/fieldvalue/arrayfieldvalue.h> +#include <vespa/document/fieldvalue/boolfieldvalue.h> #include <vespa/document/fieldvalue/bytefieldvalue.h> #include <vespa/document/fieldvalue/document.h> #include <vespa/document/fieldvalue/doublefieldvalue.h> @@ -42,6 +43,7 @@ using document::Annotation; using document::AnnotationReferenceFieldValue; using document::ArrayDataType; using document::ArrayFieldValue; +using document::BoolFieldValue; using document::ByteFieldValue; using document::DataType; using document::Document; @@ -229,7 +231,7 @@ class SummaryFieldValueConverter : protected ConstFieldValueVisitor FieldValue::UP _field_value; FieldValueConverter &_structuredFieldConverter; - virtual void visit(const ArrayFieldValue &value) override { + void visit(const ArrayFieldValue &value) override { _field_value = _structuredFieldConverter.convert(value); } @@ -237,17 +239,18 @@ class SummaryFieldValueConverter : protected ConstFieldValueVisitor void visitPrimitive(const T &t) { _field_value.reset(t.clone()); } - virtual void visit(const IntFieldValue &value) override { visitPrimitive(value); } - virtual void visit(const LongFieldValue &value) override { visitPrimitive(value); } - virtual void visit(const ShortFieldValue &value) override { visitPrimitive(value); } - virtual void visit(const ByteFieldValue &value) override { + void visit(const IntFieldValue &value) override { visitPrimitive(value); } + void visit(const LongFieldValue &value) override { visitPrimitive(value); } + void visit(const ShortFieldValue &value) override { visitPrimitive(value); } + void visit(const BoolFieldValue &value) override { visitPrimitive(value); } + void visit(const ByteFieldValue &value) override { int8_t signedValue = value.getAsByte(); _field_value.reset(new ShortFieldValue(signedValue)); } - virtual void visit(const DoubleFieldValue &value) override { visitPrimitive(value); } - virtual void visit(const FloatFieldValue &value) override { visitPrimitive(value); } + void visit(const DoubleFieldValue &value) override { visitPrimitive(value); } + void visit(const FloatFieldValue &value) override { visitPrimitive(value); } - virtual void visit(const StringFieldValue &value) override { + void visit(const StringFieldValue &value) override { if (_tokenize) { SummaryHandler handler(value.getValue(), _str); handleIndexingTerms(handler, value); @@ -256,33 +259,29 @@ class SummaryFieldValueConverter : protected ConstFieldValueVisitor } } - virtual void visit(const AnnotationReferenceFieldValue & v ) override { + void visit(const AnnotationReferenceFieldValue & v ) override { _field_value = _structuredFieldConverter.convert(v); } - virtual void visit(const Document & v) override { + void visit(const Document & v) override { _field_value = _structuredFieldConverter.convert(v); } - virtual void - visit(const PredicateFieldValue &value) override - { + void visit(const PredicateFieldValue &value) override { _str << value.toString(); } - virtual void - visit(const RawFieldValue &value) override - { + void visit(const RawFieldValue &value) override { visitPrimitive(value); } - virtual void visit(const MapFieldValue & v) override { + void visit(const MapFieldValue & v) override { _field_value = _structuredFieldConverter.convert(v); } - virtual void visit(const StructFieldValue &value) override { + void visit(const StructFieldValue &value) override { if (*value.getDataType() == *SearchDataType::URI) { FieldValue::UP uriAllValue = value.getValue("all"); - if (uriAllValue.get() != NULL && + if (uriAllValue && uriAllValue->inherits(IDENTIFIABLE_CLASSID(StringFieldValue))) { uriAllValue->accept(*this); @@ -292,11 +291,11 @@ class SummaryFieldValueConverter : protected ConstFieldValueVisitor _field_value = _structuredFieldConverter.convert(value); } - virtual void visit(const WeightedSetFieldValue &value) override { + void visit(const WeightedSetFieldValue &value) override { _field_value = _structuredFieldConverter.convert(value); } - virtual void visit(const TensorFieldValue &value) override { + void visit(const TensorFieldValue &value) override { visitPrimitive(value); } @@ -315,7 +314,7 @@ public: if (_field_value.get()) { return std::move(_field_value); } - return FieldValue::UP(new StringFieldValue(_str.str())); + return std::make_unique<StringFieldValue>(_str.str()); } }; @@ -323,7 +322,7 @@ SummaryFieldValueConverter::SummaryFieldValueConverter(bool tokenize, FieldValue : _str(), _tokenize(tokenize), _structuredFieldConverter(subConverter) {} -SummaryFieldValueConverter::~SummaryFieldValueConverter() {} +SummaryFieldValueConverter::~SummaryFieldValueConverter() = default; using namespace vespalib::slime::convenience; @@ -331,14 +330,14 @@ class SlimeFiller : public ConstFieldValueVisitor { Inserter &_inserter; bool _tokenize; - virtual void visit(const AnnotationReferenceFieldValue & v ) override { + void visit(const AnnotationReferenceFieldValue & v ) override { (void)v; Cursor &c = _inserter.insertObject(); Memory key("error"); Memory val("cannot convert from annotation reference field"); c.setString(key, val); } - virtual void visit(const Document & v) override { + void visit(const Document & v) override { (void)v; Cursor &c = _inserter.insertObject(); Memory key("error"); @@ -346,7 +345,7 @@ class SlimeFiller : public ConstFieldValueVisitor { c.setString(key, val); } - virtual void visit(const MapFieldValue & v) override { + void visit(const MapFieldValue & v) override { Cursor &a = _inserter.insertArray(); Symbol keysym = a.resolve("key"); Symbol valsym = a.resolve("value"); @@ -364,7 +363,7 @@ class SlimeFiller : public ConstFieldValueVisitor { } } - virtual void visit(const ArrayFieldValue &value) override { + void visit(const ArrayFieldValue &value) override { Cursor &a = _inserter.insertArray(); if (value.size() > 0) { ArrayInserter ai(a); @@ -375,7 +374,7 @@ class SlimeFiller : public ConstFieldValueVisitor { } } - virtual void visit(const StringFieldValue &value) override { + void visit(const StringFieldValue &value) override { if (_tokenize) { asciistream tmp; SummaryHandler handler(value.getValue(), tmp); @@ -386,48 +385,48 @@ class SlimeFiller : public ConstFieldValueVisitor { } } - virtual void visit(const IntFieldValue &value) override { + void visit(const IntFieldValue &value) override { int32_t v = value.getValue(); _inserter.insertLong(v); } - virtual void visit(const LongFieldValue &value) override { + void visit(const LongFieldValue &value) override { int64_t v = value.getValue(); _inserter.insertLong(v); } - virtual void visit(const ShortFieldValue &value) override { + void visit(const ShortFieldValue &value) override { int16_t v = value.getValue(); _inserter.insertLong(v); } - virtual void visit(const ByteFieldValue &value) override { + void visit(const ByteFieldValue &value) override { int8_t v = value.getAsByte(); _inserter.insertLong(v); } - virtual void visit(const DoubleFieldValue &value) override { + void visit(const BoolFieldValue &value) override { + bool v = value.getValue(); + _inserter.insertBool(v); + } + void visit(const DoubleFieldValue &value) override { double v = value.getValue(); _inserter.insertDouble(v); } - virtual void visit(const FloatFieldValue &value) override { + void visit(const FloatFieldValue &value) override { float v = value.getValue(); _inserter.insertDouble(v); } - virtual void - visit(const PredicateFieldValue &value) override - { + void visit(const PredicateFieldValue &value) override { vespalib::slime::inject(value.getSlime().get(), _inserter); } - virtual void - visit(const RawFieldValue &value) override - { + void visit(const RawFieldValue &value) override { std::pair<const char *, size_t> buf = value.getAsRaw(); _inserter.insertData(Memory(buf.first, buf.second)); } - virtual void visit(const StructFieldValue &value) override { + void visit(const StructFieldValue &value) override { if (*value.getDataType() == *SearchDataType::URI) { FieldValue::UP uriAllValue = value.getValue("all"); - if (uriAllValue.get() != NULL && + if (uriAllValue && uriAllValue->inherits(IDENTIFIABLE_CLASSID(StringFieldValue))) { uriAllValue->accept(*this); @@ -444,7 +443,7 @@ class SlimeFiller : public ConstFieldValueVisitor { } } - virtual void visit(const WeightedSetFieldValue &value) override { + void visit(const WeightedSetFieldValue &value) override { Cursor &a = _inserter.insertArray(); if (value.size() > 0) { Symbol isym = a.resolve("item"); @@ -460,7 +459,7 @@ class SlimeFiller : public ConstFieldValueVisitor { } } - virtual void visit(const TensorFieldValue &value) override { + void visit(const TensorFieldValue &value) override { const auto &tensor = value.getAsTensorPtr(); vespalib::nbostream s; if (tensor) { @@ -495,7 +494,7 @@ public: search::RawBuf rbuf(4096); search::SlimeOutputRawBufAdapter adapter(rbuf); vespalib::slime::BinaryFormat::encode(slime, adapter); - return FieldValue::UP(new RawFieldValue(rbuf.GetDrainPos(), rbuf.GetUsedLen())); + return std::make_unique<RawFieldValue>(rbuf.GetDrainPos(), rbuf.GetUsedLen()); } }; diff --git a/staging_vespalib/src/vespa/vespalib/util/xmlserializable.cpp b/staging_vespalib/src/vespa/vespalib/util/xmlserializable.cpp index 9272f7b0f94..35110be87ca 100644 --- a/staging_vespalib/src/vespa/vespalib/util/xmlserializable.cpp +++ b/staging_vespalib/src/vespa/vespalib/util/xmlserializable.cpp @@ -4,8 +4,7 @@ #include "xmlstream.h" #include <sstream> -namespace vespalib { -namespace xml { +namespace vespalib::xml { std::string XmlSerializable::toXml(const std::string& indent) const @@ -16,5 +15,4 @@ XmlSerializable::toXml(const std::string& indent) const return ost.str(); } -} // xml -} // vespalib +} diff --git a/staging_vespalib/src/vespa/vespalib/util/xmlserializable.h b/staging_vespalib/src/vespa/vespalib/util/xmlserializable.h index c0d41910479..4c00a734b2b 100644 --- a/staging_vespalib/src/vespa/vespalib/util/xmlserializable.h +++ b/staging_vespalib/src/vespa/vespalib/util/xmlserializable.h @@ -4,8 +4,7 @@ #include <string> -namespace vespalib { -namespace xml { +namespace vespalib::xml { class XmlOutputStream; @@ -26,8 +25,9 @@ public: virtual std::string toXml(const std::string& indent = "") const; }; -} // xml +} +namespace vespalib { // The XmlSerializable and XmlOutputStream is often used in header files // and is thus available in the vespalib namespace. To not pollute the // vespalib namespace with all the other classes, use |