diff options
11 files changed, 53 insertions, 31 deletions
diff --git a/document/src/tests/fieldpathupdatetestcase.cpp b/document/src/tests/fieldpathupdatetestcase.cpp index 3d41a5bcacd..17b84ecc180 100644 --- a/document/src/tests/fieldpathupdatetestcase.cpp +++ b/document/src/tests/fieldpathupdatetestcase.cpp @@ -182,8 +182,9 @@ void testSerialize(const DocumentTypeRepo& repo, const DocumentUpdate& a) { } EXPECT_EQ(a, *b); } catch (std::exception& e) { - std::cerr << "Failed while testing document field path update:\n" - << a.toString(true) << "\n"; + std::cerr << "Failed while testing document field path update:\n"; + a.print(std::cerr, true, ""); + std::cerr << std::endl; throw; } } diff --git a/document/src/tests/testxml.cpp b/document/src/tests/testxml.cpp index 2fdcee029c8..4d26be9da9c 100644 --- a/document/src/tests/testxml.cpp +++ b/document/src/tests/testxml.cpp @@ -131,6 +131,7 @@ TEST(TestXml, testDocumentUpdate) " <remove>789</remove>\n" " </alter>\n" "</document>"; + std::ostringstream os; EXPECT_EQ(expected, up1->toXml(" ")); } diff --git a/document/src/vespa/document/update/documentupdate.cpp b/document/src/vespa/document/update/documentupdate.cpp index fde1ab70e11..2b831f951f8 100644 --- a/document/src/vespa/document/update/documentupdate.cpp +++ b/document/src/vespa/document/update/documentupdate.cpp @@ -11,7 +11,7 @@ #include <vespa/document/datatype/documenttype.h> #include <vespa/document/repo/documenttyperepo.h> #include <vespa/vespalib/util/xmlstream.h> -#include <ostream> +#include <sstream> using vespalib::IllegalArgumentException; using vespalib::IllegalStateException; @@ -336,6 +336,15 @@ DocumentUpdate::reserialize() _needHardReserialize = false; } +std::string +DocumentUpdate::toXml(const std::string& indent) const +{ + std::ostringstream ost; + XmlOutputStream xos(ost, indent); + printXml(xos); + return ost.str(); +} + std::ostream & operator<<(std::ostream &out, const DocumentUpdate &update) { diff --git a/document/src/vespa/document/update/documentupdate.h b/document/src/vespa/document/update/documentupdate.h index c7ebe913d79..976c6337747 100644 --- a/document/src/vespa/document/update/documentupdate.h +++ b/document/src/vespa/document/update/documentupdate.h @@ -40,7 +40,7 @@ class VespaDocumentSerializer; * path updates was added, and a new serialization format was * introduced while keeping the old one. */ -class DocumentUpdate final : public Printable, public vespalib::xml::XmlSerializable +class DocumentUpdate { public: using UP = std::unique_ptr<DocumentUpdate>; @@ -70,7 +70,9 @@ public: DocumentUpdate(const DocumentUpdate &) = delete; DocumentUpdate & operator = (const DocumentUpdate &) = delete; - ~DocumentUpdate() override; + DocumentUpdate(DocumentUpdate &&) = delete; + DocumentUpdate & operator = (DocumentUpdate &&) = delete; + ~DocumentUpdate(); bool operator==(const DocumentUpdate&) const; bool operator!=(const DocumentUpdate & rhs) const { return ! (*this == rhs); } @@ -98,9 +100,8 @@ public: /** @return The type of document this update is for. */ const DocumentType& getType() const; - void print(std::ostream& out, bool verbose, const std::string& indent) const override; + void serializeHEAD(vespalib::nbostream &stream) const; - void printXml(XmlOutputStream&) const override; /** * Sets whether this update should create the document it updates if that document does not exist. @@ -115,6 +116,10 @@ public: int serializeFlags(int size_) const; + // Only used for debugging + void print(std::ostream& out, bool verbose, const std::string& indent) const; + void printXml(XmlOutputStream&) const; + std::string toXml(const std::string& indent) const; private: DocumentId _documentId; // The ID of the document to update. const DataType *_type; // The type of document this update is for. diff --git a/document/src/vespa/document/update/fieldupdate.cpp b/document/src/vespa/document/update/fieldupdate.cpp index ff60c3b7994..2db4f7eba2d 100644 --- a/document/src/vespa/document/update/fieldupdate.cpp +++ b/document/src/vespa/document/update/fieldupdate.cpp @@ -12,8 +12,7 @@ namespace document { using vespalib::nbostream; FieldUpdate::FieldUpdate(const Field& field) - : Printable(), - _field(field), + : _field(field), _updates() { } @@ -29,8 +28,7 @@ int readInt(nbostream & stream) { } FieldUpdate::FieldUpdate(const DocumentTypeRepo& repo, const DataType & type, nbostream & stream) - : Printable(), - _field(type.getField(readInt(stream))), + : _field(type.getField(readInt(stream))), _updates() { int numUpdates = readInt(stream); diff --git a/document/src/vespa/document/update/fieldupdate.h b/document/src/vespa/document/update/fieldupdate.h index e364e5db5fd..20cb739ee57 100644 --- a/document/src/vespa/document/update/fieldupdate.h +++ b/document/src/vespa/document/update/fieldupdate.h @@ -21,9 +21,7 @@ namespace document { class Document; class DocumentType; -class FieldUpdate : public vespalib::Identifiable, - public Printable, - public vespalib::xml::XmlSerializable +class FieldUpdate : public vespalib::Identifiable { Field _field; std::vector<ValueUpdate::CP> _updates; @@ -73,8 +71,8 @@ public: const Field& getField() const { return _field; } void applyTo(Document& doc) const; - void print(std::ostream& out, bool verbose, const std::string& indent) const override; - void printXml(XmlOutputStream&) const override; + void print(std::ostream& out, bool verbose, const std::string& indent) const; + void printXml(XmlOutputStream&) const; /** * Deserializes the given stream into an instance of an update object. diff --git a/document/src/vespa/document/update/mapvalueupdate.cpp b/document/src/vespa/document/update/mapvalueupdate.cpp index 48e52a9d2cc..7418d35793b 100644 --- a/document/src/vespa/document/update/mapvalueupdate.cpp +++ b/document/src/vespa/document/update/mapvalueupdate.cpp @@ -122,7 +122,9 @@ MapValueUpdate::printXml(XmlOutputStream& xos) const { xos << XmlTag("map") << XmlTag("value") << *_key << XmlEndTag() - << XmlTag("update") << *_update << XmlEndTag() + << XmlTag("update"); + _update->printXml(xos); + xos << XmlEndTag() << XmlEndTag(); } diff --git a/document/src/vespa/document/update/valueupdate.cpp b/document/src/vespa/document/update/valueupdate.cpp index 8a023fb9ef2..8fc85e8858a 100644 --- a/document/src/vespa/document/update/valueupdate.cpp +++ b/document/src/vespa/document/update/valueupdate.cpp @@ -26,4 +26,10 @@ ValueUpdate::createInstance(const DocumentTypeRepo& repo, const DataType& type, } } +std::ostream& +operator<<(std::ostream& out, const ValueUpdate& p) { + p.print(out, false, ""); + return out; +} + } diff --git a/document/src/vespa/document/update/valueupdate.h b/document/src/vespa/document/update/valueupdate.h index ec903c1adc1..872f883744a 100644 --- a/document/src/vespa/document/update/valueupdate.h +++ b/document/src/vespa/document/update/valueupdate.h @@ -19,10 +19,9 @@ #pragma once #include "updatevisitor.h" -#include <vespa/document/util/printable.h> #include <vespa/document/util/identifiableid.h> #include <vespa/vespalib/objects/nbostream.h> -#include <vespa/vespalib/util/xmlserializable.h> +#include <vespa/vespalib/util/xmlstream.h> namespace document { @@ -31,9 +30,7 @@ class Field; class FieldValue; class DataType; -class ValueUpdate : public vespalib::Identifiable, - public Printable, - public vespalib::xml::XmlSerializable +class ValueUpdate : public vespalib::Identifiable { protected: using nbostream = vespalib::nbostream; @@ -62,11 +59,6 @@ public: TensorRemoveUpdate = IDENTIFIABLE_CLASSID(TensorRemoveUpdate) }; - ValueUpdate() - : Printable(), XmlSerializable() {} - - virtual ~ValueUpdate() = default; - virtual bool operator==(const ValueUpdate&) const = 0; bool operator != (const ValueUpdate & rhs) const { return ! (*this == rhs); } @@ -105,8 +97,13 @@ public: */ virtual void accept(UpdateVisitor &visitor) const = 0; + 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); }; +std::ostream& operator<<(std::ostream& out, const ValueUpdate & p); + } diff --git a/document/src/vespa/document/util/printable.cpp b/document/src/vespa/document/util/printable.cpp index 8d9135af285..c8043bfce04 100644 --- a/document/src/vespa/document/util/printable.cpp +++ b/document/src/vespa/document/util/printable.cpp @@ -23,7 +23,7 @@ void Printable::print(std::ostream& out, const std::string& indent) const { } std::ostream& operator<<(std::ostream& out, const Printable& p) { - p.print(out); + p.print(out, false, ""); return out; } diff --git a/searchcore/src/apps/vespa-transactionlog-inspect/vespa-transactionlog-inspect.cpp b/searchcore/src/apps/vespa-transactionlog-inspect/vespa-transactionlog-inspect.cpp index f00702f2785..4d7f32241f9 100644 --- a/searchcore/src/apps/vespa-transactionlog-inspect/vespa-transactionlog-inspect.cpp +++ b/searchcore/src/apps/vespa-transactionlog-inspect/vespa-transactionlog-inspect.cpp @@ -232,9 +232,14 @@ private: toPrint.printXml(out); std::cout << std::endl; } + void printXml(const document::DocumentUpdate &toPrint) { + vespalib::xml::XmlOutputStream out(std::cout); + toPrint.printXml(out); + std::cout << std::endl; + } - void printText(const document::Printable &toPrint) { - toPrint.print(std::cout, _verbose); + void printText(const document::DocumentUpdate &toPrint) { + toPrint.print(std::cout, _verbose, ""); std::cout << std::endl; } @@ -265,7 +270,7 @@ public: } void replay(const UpdateOperation &op) override { print(op); - if (op.getUpdate().get() != NULL) { + if (op.getUpdate()) { if (_printXml) { printXml(*op.getUpdate()); } else { |