aboutsummaryrefslogtreecommitdiffstats
path: root/document
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@oath.com>2018-06-04 20:12:14 +0200
committerHenning Baldersheim <balder@oath.com>2018-06-05 15:46:55 +0200
commitd3ed38df6ae6dbdb0143fd20e8dd546da0c60bf3 (patch)
tree3abf23973b1d599616aee070985ce0aa64663d9d /document
parent257b508881cc74d0bbce675a4f07973b3196581f (diff)
Aggregate elementId
Diffstat (limited to 'document')
-rw-r--r--document/src/vespa/document/fieldvalue/arrayfieldvalue.cpp9
-rw-r--r--document/src/vespa/document/fieldvalue/iteratorhandler.cpp11
-rw-r--r--document/src/vespa/document/fieldvalue/iteratorhandler.h6
-rw-r--r--document/src/vespa/document/fieldvalue/mapfieldvalue.cpp10
4 files changed, 25 insertions, 11 deletions
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..97529e09578 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.resize(_arrayIndexStack.size() - 1);
}
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());
}