aboutsummaryrefslogtreecommitdiffstats
path: root/streamingvisitors/src/vespa/vsm/common/storagedocument.h
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2022-05-15 00:41:35 +0200
committerGitHub <noreply@github.com>2022-05-15 00:41:35 +0200
commit4db8dcbf3395fd92b1348155142b85df5a754289 (patch)
tree912b02e614bc9889ea3543893cbeb699971e8156 /streamingvisitors/src/vespa/vsm/common/storagedocument.h
parent287a799b270200aca440cad376272328128a5054 (diff)
Revert "Revert "Collapse vsm into streamingvisitors""
Diffstat (limited to 'streamingvisitors/src/vespa/vsm/common/storagedocument.h')
-rw-r--r--streamingvisitors/src/vespa/vsm/common/storagedocument.h59
1 files changed, 59 insertions, 0 deletions
diff --git a/streamingvisitors/src/vespa/vsm/common/storagedocument.h b/streamingvisitors/src/vespa/vsm/common/storagedocument.h
new file mode 100644
index 00000000000..a7f21cb052f
--- /dev/null
+++ b/streamingvisitors/src/vespa/vsm/common/storagedocument.h
@@ -0,0 +1,59 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+#pragma once
+
+#include "document.h"
+#include <vespa/document/fieldvalue/document.h>
+
+namespace vsm {
+
+typedef vespalib::CloneablePtr<document::FieldValue> FieldValueContainer;
+typedef document::FieldPath FieldPath; // field path to navigate a field value
+typedef std::vector<FieldPath> FieldPathMapT; // map from field id to field path
+typedef std::shared_ptr<FieldPathMapT> SharedFieldPathMap;
+
+class StorageDocument : public Document {
+public:
+ typedef std::unique_ptr<StorageDocument> UP;
+
+ class SubDocument {
+ public:
+ SubDocument() : _fieldValue(nullptr) {}
+ SubDocument(document::FieldValue *fv, document::FieldValue::PathRange nested) :
+ _fieldValue(fv),
+ _range(nested)
+ { }
+
+ const document::FieldValue *getFieldValue() const { return _fieldValue; }
+ void setFieldValue(document::FieldValue *fv) { _fieldValue = fv; }
+ const document::FieldValue::PathRange & getRange() const { return _range; }
+ void swap(SubDocument &rhs) {
+ std::swap(_fieldValue, rhs._fieldValue);
+ std::swap(_range, rhs._range);
+ }
+ private:
+ FieldPath::const_iterator begin() const;
+ FieldPath::const_iterator end() const;
+ document::FieldValue *_fieldValue;
+ document::FieldValue::PathRange _range;
+ };
+public:
+ StorageDocument(document::Document::UP doc, const SharedFieldPathMap &fim, size_t fieldNoLimit);
+ StorageDocument(const StorageDocument &) = delete;
+ StorageDocument & operator = (const StorageDocument &) = delete;
+ ~StorageDocument();
+
+ const document::Document &docDoc() const { return *_doc; }
+ bool valid() const { return _doc.get() != nullptr; }
+ const SubDocument &getComplexField(FieldIdT fId) const;
+ const document::FieldValue *getField(FieldIdT fId) const override;
+ bool setField(FieldIdT fId, document::FieldValue::UP fv) override ;
+ void saveCachedFields() const;
+private:
+ document::Document::UP _doc;
+ SharedFieldPathMap _fieldMap;
+ mutable std::vector<SubDocument> _cachedFields;
+ mutable std::vector<document::FieldValue::UP> _backedFields;
+};
+
+}
+