diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2018-06-06 10:01:52 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-06 10:01:52 +0200 |
commit | ae20ddec12c463d1bbcc7817a8751c7aac355f38 (patch) | |
tree | 8204414e27054385d2028cd738608ab999caa08e /document | |
parent | 1e8f8c6492aea894c1f6a2bcd3cf4d5856fcb117 (diff) |
Revert "Revert "Balder/sameelement in streaming""
Diffstat (limited to 'document')
5 files changed, 36 insertions, 16 deletions
diff --git a/document/src/tests/documenttestcase.cpp b/document/src/tests/documenttestcase.cpp index 33d1a666d4a..ee49259e982 100644 --- a/document/src/tests/documenttestcase.cpp +++ b/document/src/tests/documenttestcase.cpp @@ -115,16 +115,22 @@ public: ~Handler(); const std::string & getResult() const { return _result; } private: - void onPrimitive(uint32_t, const Content&) override { _result += 'P'; } + void onPrimitive(uint32_t, const Content&) override { + std::ostringstream os; os << "P-" << getArrayIndex(); + _result += os.str(); + } void onCollectionStart(const Content&) override { _result += '['; } void onCollectionEnd(const Content&) override { _result += ']'; } - void onStructStart(const Content&) override { _result += '<'; } + void onStructStart(const Content&) override { + std::ostringstream os; os << "<" << getArrayIndex() << ":"; + _result += os.str(); + } void onStructEnd(const Content&) override { _result += '>'; } std::string _result; }; -Handler::Handler() { } -Handler::~Handler() { } +Handler::Handler() = default; +Handler::~Handler() = default; void DocumentTest::testTraversing() @@ -186,7 +192,7 @@ void DocumentTest::testTraversing() FieldPath empty; doc.iterateNested(empty.getFullRange(), fullTraverser); CPPUNIT_ASSERT_EQUAL(fullTraverser.getResult(), - std::string("<P<P<PP[PPP][<PP><PP>]>>>")); + std::string("<0:P-0<0:P-0<0:P-0P-0[P-0P-1P-2][<0:P-0P-0><1:P-1P-1>]>>>")); } class VariableIteratorHandler : public IteratorHandler { diff --git a/document/src/vespa/document/fieldvalue/arrayfieldvalue.cpp b/document/src/vespa/document/fieldvalue/arrayfieldvalue.cpp index 194c9b422da..f3239553fa9 100644 --- a/document/src/vespa/document/fieldvalue/arrayfieldvalue.cpp +++ b/document/src/vespa/document/fieldvalue/arrayfieldvalue.cpp @@ -37,9 +37,7 @@ ArrayFieldValue::ArrayFieldValue(const ArrayFieldValue& other) { } -ArrayFieldValue::~ArrayFieldValue() -{ -} +ArrayFieldValue::~ArrayFieldValue() = default; ArrayFieldValue& ArrayFieldValue::operator=(const ArrayFieldValue& other) @@ -194,6 +192,7 @@ ArrayFieldValue::iterateSubset(int startPos, int endPos, std::vector<int> indicesToRemove; for (int i = startPos; i <= endPos && i < static_cast<int>(_array->size()); ++i) { + handler.setArrayIndex(i); if (!variable.empty()) { handler.getVariables()[variable] = IndexValue(i); } @@ -212,9 +211,7 @@ ArrayFieldValue::iterateSubset(int startPos, int endPos, handler.getVariables().erase(variable); } - for (std::vector<int>::reverse_iterator i = indicesToRemove.rbegin(); - i != indicesToRemove.rend(); ++i) - { + for (auto i = indicesToRemove.rbegin(); i != indicesToRemove.rend(); ++i) { const_cast<ArrayFieldValue&>(*this).remove(*i); } diff --git a/document/src/vespa/document/fieldvalue/iteratorhandler.cpp b/document/src/vespa/document/fieldvalue/iteratorhandler.cpp index 2e9a525d9e6..8764e7908cd 100644 --- a/document/src/vespa/document/fieldvalue/iteratorhandler.cpp +++ b/document/src/vespa/document/fieldvalue/iteratorhandler.cpp @@ -5,7 +5,14 @@ namespace document::fieldvalue { -IteratorHandler::~IteratorHandler() { } +IteratorHandler::IteratorHandler() + : _weight(1), + _arrayIndexStack(1, 0), + _variables() +{ +} + +IteratorHandler::~IteratorHandler() = default; void @@ -18,11 +25,13 @@ IteratorHandler::handleComplex(const FieldValue & fv) { } void IteratorHandler::handleCollectionStart(const FieldValue & fv) { + _arrayIndexStack.push_back(0); onCollectionStart(Content(fv, getWeight())); } void IteratorHandler::handleCollectionEnd(const FieldValue & fv) { onCollectionEnd(Content(fv, getWeight())); + _arrayIndexStack.pop_back(); } void IteratorHandler::handleStructStart(const FieldValue & fv) { diff --git a/document/src/vespa/document/fieldvalue/iteratorhandler.h b/document/src/vespa/document/fieldvalue/iteratorhandler.h index 757cea54ef9..cf71504e7a1 100644 --- a/document/src/vespa/document/fieldvalue/iteratorhandler.h +++ b/document/src/vespa/document/fieldvalue/iteratorhandler.h @@ -4,6 +4,7 @@ #include "variablemap.h" #include "modificationstatus.h" +#include <vector> namespace document::fieldvalue { @@ -55,7 +56,7 @@ protected: int _weight; }; - IteratorHandler() : _weight(1) {} + IteratorHandler(); public: virtual ~IteratorHandler(); @@ -72,6 +73,8 @@ public: void handleStructStart(const FieldValue &fv); void handleStructEnd(const FieldValue &fv); void setWeight(int weight) { _weight = weight; } + uint32_t getArrayIndex() const { return _arrayIndexStack.back(); } + void setArrayIndex(uint32_t index) { _arrayIndexStack.back() = index; } ModificationStatus modify(FieldValue &fv) { return doModify(fv); } fieldvalue::VariableMap &getVariables() { return _variables; } void setVariables(const fieldvalue::VariableMap &vars) { _variables = vars; } @@ -93,6 +96,7 @@ private: int getWeight() const { return _weight; } int _weight; + std::vector<uint32_t> _arrayIndexStack; fieldvalue::VariableMap _variables; }; diff --git a/document/src/vespa/document/fieldvalue/mapfieldvalue.cpp b/document/src/vespa/document/fieldvalue/mapfieldvalue.cpp index 8e5a641ab6e..ebd51c82794 100644 --- a/document/src/vespa/document/fieldvalue/mapfieldvalue.cpp +++ b/document/src/vespa/document/fieldvalue/mapfieldvalue.cpp @@ -78,9 +78,7 @@ MapFieldValue::MapFieldValue(const DataType &mapType) { } -MapFieldValue::~MapFieldValue() -{ -} +MapFieldValue::~MapFieldValue() = default; MapFieldValue::MapFieldValue(const MapFieldValue & rhs) : FieldValue(rhs), @@ -425,6 +423,7 @@ MapFieldValue::iterateNestedImpl(PathRange nested, bool wasModified = false; const bool isWSet(complexFieldValue.inherits(WeightedSetFieldValue::classId)); + uint32_t index(0); if ( ! nested.atEnd() ) { LOG(spam, "not yet at end of field path"); const FieldPathEntry & fpe = nested.cur(); @@ -451,6 +450,7 @@ MapFieldValue::iterateNestedImpl(PathRange nested, case FieldPathEntry::MAP_ALL_KEYS: LOG(spam, "MAP_ALL_KEYS"); for (const auto & entry : *this) { + handler.setArrayIndex(index++); if (isWSet) { handler.setWeight(static_cast<const IntFieldValue &>(*entry.second).getValue()); } @@ -462,6 +462,7 @@ MapFieldValue::iterateNestedImpl(PathRange nested, case FieldPathEntry::MAP_ALL_VALUES: LOG(spam, "MAP_ALL_VALUES"); for (const auto & entry : *this) { + handler.setArrayIndex(index++); wasModified = checkAndRemove(*entry.second, entry.second->iterateNested(nested.next(), handler), wasModified, keysToRemove); @@ -482,6 +483,7 @@ MapFieldValue::iterateNestedImpl(PathRange nested, } else { PathRange next = nested.next(); for (const auto & entry : *this) { + handler.setArrayIndex(index++); LOG(spam, "key is '%s'", entry.first->toString().c_str()); handler.getVariables()[fpe.getVariableName()] = IndexValue(*entry.first); LOG(spam, "vars at this time = %s", handler.getVariables().toString().c_str()); @@ -495,6 +497,7 @@ MapFieldValue::iterateNestedImpl(PathRange nested, default: LOG(spam, "default"); for (const auto & entry : *this) { + handler.setArrayIndex(index++); if (isWSet) { handler.setWeight(static_cast<const IntFieldValue &>(*entry.second).getValue()); } @@ -522,6 +525,7 @@ MapFieldValue::iterateNestedImpl(PathRange nested, if (handler.handleComplex(complexFieldValue)) { LOG(spam, "calling handler.handleComplex for all map keys"); for (const auto & entry : *this) { + handler.setArrayIndex(index++); if (isWSet) { handler.setWeight(static_cast<const IntFieldValue &>(*entry.second).getValue()); } |